Google custom search json api refinement labels - google-api

I am building out a site search using the google custom json/rest api, but I am not sure how to get the 'facet/ refinement labels' to filter down the results.
They are being returned in the json, but I haven't seen anything in the documentation that explains how to filter with it.

To filter with facet, value of q parameter should be like this:
text_to_search more:facet_name

After you have added refinement labels to your custom search, you have to add the facet name into your search query to "activate" the filter. Your facet name will be named the same as you named your refinement label. If you named your refinement label "race bicycles", you need to add more:race_bicycles to your query. You can also find your facet name in the response meta data of your request in label_with_op. Just copy and past your label_with_op in your query.
For using the api in python, the request looks something like this:
params = {
"q" : "bicycles more:race_bicycles",
"cx": cx,
"key": key,
}
page = requests.request("GET", url = "https://www.googleapis.com/customsearch/v1" , params=params)
results = json.loads(page.text)

Related

Filtering a list of values by a field value in GraphQL

So I'm doing some tests with GraphQL, and I'm failing in doing something that I believe is fairly simple.
When going to the GraphQL demo site (https://graphql.org/swapi-graphql) I'm presented with a default query which goes like this:
{
allFilms {
films {
title,
director,
releaseDate
}
}
}
This works as expected and returns a list of films.
Now - I would like to modify this query to return only the films where the director is George Lucas, and for the life of me - I can't figure out how to do that.
I've tried using the where and filter expressions, and also change the second line to films: (director: "George Lucas") but keep getting error messages.
What's the correct syntax for doing that?
Thanks!
If you check the docs of the provided GraphQL schema, you'll see that this is not possible. Following is the definition of the allFilms field:
allFilms(
after: String
first: Int
before: String
last: Int
): FilmsConnection
As per the doc, it has 4 input arguments, which are after, first, before, and last. There is no way to filter this out using the director's name.
GraphQL is not SQL. You cannot use expressions like WHERE or FILTER in GraphQL. The schema is already defined and the filters are pre-defined too. If the schema does not allow you to filter values using a certain field, you just can't do it.
You can to see the graphql schema here https://github.com/graphql/swapi-graphql/blob/master/schema.graphql
The allFilms query does not contain a filter for the field director. Also i can't find other query with this filter.
Most likely you need to write a filter on the result of the query.

Using $filter on List<String> Outlook calendar

I have been looking up OData protocol for $filter and trying to look up the syntax for filtering response from ms-graph based on categories eq 'FlexUser'.
in the response I get:
...,
"categories": [
"FlexUser"
],
...
While trying to expand categories before using filter I get an error says that categories can't be expanded. Can anyone explain how to filter on List param?
I create the category when creating the event so that category does not exist in my outlook calendar
If I understand you right, you are fetching a list of events with e.g.
/v1.0/me/calendar/events
and want to filter all events which contain a specific category.
In this case you have to use the any operator in your filter:
$filter=categories/any(c:c eq '#break')
So your request could look like this:
/v1.0/me/calendar/events?$filter=categories/any(c:c eq 'FlexUser')

Django rest framework field descriptions blank

In the Django rest framework, I'm creating a documentation page using the AutoSchema class. For selected API endpoints, I'm using manual_fields to add doc entries for various fields. These entries appear on the doc page as expected, in pretty tables, but the "Description" columns are blank, even though I'm including the description arg in the coreapi.Field() constructor. How do I get the descriptions to appear in the tables?
Here is an example field definition:
class FooList(APIView):
''' List the Foos
'''
schema = AutoSchema(
manual_fields=[
coreapi.Field(
name='format',
location='query',
description='The format in which to return results. One of: api, json',
required=False),
]
)
def get(request, format=None):
...
use coreschema module to describe field that api-shcema/ or api-docs/ will display correctly. example:
schema=coreschema.String(title='Format', description='The format in which to return results. One of: api, json'),
schema = AutoSchema(
manual_fields=[
coreapi.Field(
name='format',
location='query',
schema=coreschema.String(description='The format in which to return results. One of: api, json'),
required=False),
]
)

CloudSearch or CloudQuery to search by 'contains' in CloudBoost

I need to filter data by substring, I mean, if I have got this data:
'John','Markus','james'
And i want to look by all elements which contains 'm' it should return:
'Markus','james'
Or if I filter by 'hn', the results should be:
'John'
How can I do it using CloudSearch or CloudQuery?
EDIT: I have seen wildcard method which seems to fit with my requirements, except for only is allowed a column (string) param. I would need to filter also by columns (array). As in searchOn method.
This should work I think. did you try it with this :
var query = new CB.CloudQuery('TableName');
//then you can:
query.substring('ColName','Text');
//or
query.substring(['ColName1','ColName2'],'Text');
//or
query.substring('ColName',['Text1', 'Text2']);
//or
query.substring(['ColName1','ColName2'],['Text1', 'Text2']);
query.find(callback);

Translate odata uri to expression

I'd like to use an action filter to translate an Odata uri to a Linq expression. I'm doing this because i'm using the resulting expression to query nonSQL line of business systems. In the WCF web api this was trivial because the translated query was appended as a property of the the request object, as such:
var query = (EnumerableQuery)request.Properties["queryToCompose"];
That seems to have disappeared. Are there any public api's i can use to accomplish this?
I've been trying something similiar.. While not perfect, you can grab the OData expressions directly from the query string and build the LINQ expression manually:
var queryParams = HttpUtility.ParseQueryString( ControllerContext.Request.RequestUri.Query );
var top = queryParams.Get( "$top" );
var skip = queryParams.Get( "$skip" );
var orderby = queryParams.Get( "$orderby" );
And the apply that directly to your IQueryable or whatever you're using for the filtering. Not nearly as useful, but its a start.
So as it turns out the query has changed keys in the request property collection. It also seems that the internal filter that parses the query runs after the custom filters and thus doesn't add the query value. To get the translated query, call the following inside the controller action.
(EnumerableQuery<T>)this.Request.Properties["MS_QueryKey"];
Check out Linq2Rest. It solves this problem.

Resources