I was playing around with the Knowledge Graph API recently, but can't really get it to return anything useful.
My scenario is this: I query the API for maxim gorki theater, and it rightly returns the entry for the theater in Berlin. Now, on the web, I can click Kommende Veranstaltungen [Upcoming events] and it gives me the next plays for that theater. This is still part of the knowledge graph, the displayed search term is maxim gorki theater kommende veranstaltungen. Yet if I try to pass that query to the API to get a JSON of the next plays I am simply returned an empty result.
My query is this: https://kgsearch.googleapis.com/v1/entities:search?query=QUERY&key=API_KEY&limit=1&indent=True
Am I doing this wrong or is this a general limitation of the API? If so, what is the point of this API?
I'm using the code from https://developers.google.com/knowledge-graph/, It works well
service_url = 'https://kgsearch.googleapis.com/v1/entities:search'
params = {
'query': query,
'limit': 10,
'indent': True,
'key': api_key,
}
url = service_url + '?' + urllib.urlencode(params)
response = json.loads(urllib2.urlopen(url).read())
Related
i'm using Apollo Client do request a very structured dataset from my server. Something like
-Show
id
title
...
-Seasons
number
-Episodes
id
number
airdate
Thanks to normalization my episodes are stored individually but i cannot query them. For exemple i would like to query all the episodes to then sort them by date to display coming next.
the only way i see is to either 'reduce' my show list to an array of episode and then do the filtering. Or to do a new query to the server.
But it will be so much faster if I could get a list of all Episodes in cache.
Unfortunately with readFragment you can only query One object by its id.
Question:
Is there a way to query the cache for all object of a defined type?
The answer is late, but could have helped someone else, currently apollo does not support it. This is the issue here from github, and also a work around.
https://github.com/apollographql/apollo-client/issues/4724#issuecomment-487373566
Here is the copied workaround by #superandrew213
const serializedState = client.cache.extract()
const typeNameItems = Object.values(serializedState)
.filter(item => item.__typename === 'TypeName')
.map(item => client.readFragment({
fragmentName: 'FragmentName',
fragment: Fragment,
id: item.id,
}))
Please take note that this method is slow, especially if you have a large normalized data.
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)
"The SoundCloud API will be dropping support for offset-based pagination on March 2, 2015, in favor of linked partitioning.
To page through a JSON response, pass the linked_partitioning=1 parameter along with your request and it will return a collection, along with a next_href property if there are additional results. To fetch the next page of results, simply follow that URI. If the response does not contain a next_href property, you have reached the end of the results."
I'm trying to do this in ruby with the soundcloud api. I know max results are 200, but if I search through 500 I will literally see "next_href" in the response. Is it possible to continue the search? How do I do it if its possible?
When I try calling it, I end up getting a syntax error ":undefined method `title'" or just not the requested amount of results.
When you request a collection of resources (eg: search results, stream tracks), if you don't get the full collection back again, in the response is a field called next_href. This is a url pointing to the next page of the same collection. Each subsequent page will give you a next_href until you reach the end and none will exist. As an example:
/users/2/tracks.json?limit=10
{
"collection": [ { id: 123, title: ... }, { id: 456 ... }, ... ],
"next_href": "https://api.soundcloud.com/users/2/tracks.json?limit=10&offset=10"
}
I don't quite know what you mean here:
When I try calling it, I end up getting a syntax error ":undefined method `title'" or just not the requested amount of results.
That sounds like a bug in your ruby code.
I am integrating FOSElasticaBundle in my Symfony 2.3 project and I need to sort the results by their price property.
Here is my code:
$finder = $this->container->get('fos_elastica.finder.website.product');
$fieldTerms = new \Elastica\Query\Terms();
$fieldTerms->setTerms('taxon_ids', $taxon_ids_array);
$boolQuery->addMust($fieldTerms);
$resultSet = $finder->find($boolQuery);
How I can do this?
Thanks
Try create a \Elastica\Query object which also contains the sorting information, then send this to the finder:
$finder = $this->container->get('fos_elastica.finder.website.product');
$fieldTerms = new \Elastica\Query\Terms();
$fieldTerms->setTerms('taxon_ids', $taxon_ids_array);
$boolQuery->addMust($fieldTerms);
$finalQuery = new \Elastica\Query($boolQuery);
$finalQuery->setSort(array('price' => array('order' => 'asc')));
$resultSet = $finder->find($finalQuery);
Have a look at the elasticsearch docs on the sort parameter to see how to use it properly.
NOTE: \Elastica\Query is quite different to \Elastica\Query\AbstractQuery, the first encapsulates everything you could send to the _search API endpoint (facets, sorting, explain, etc...) The AbstractQuery represents a base type for each of the individual query types (range, fuzzy, terms, etc...).
Is there a way to use a LINQ expression to request a Count query from the Netflix oData service in Silverlight 4?
The Netflix documentation shows that you can return counts by appending $count to a request for a collection, but a URL like this:
http://netflix.cloudapp.net/Catalog/Genres/$count
Is not generated from an expression like this:
var count = (from g in catalog.Genres select g).Count();
The above code returns an error saying that the Count method is not supported. Is there a way to do this in LINQ, or do I just need to make WebClient request to get the value?
Count and LongCount are not supported in Silverligth because they require a synchornous execution of the query. Since Silverlight requires all network operations to by asynchronous this is not possible.
You can either issue the HTTP query in question programatically not using DataServiceContext (or related classes), since the $count returns a text representation of the number, parsing the response is not that hard.
Or you can use a bit of a trick. You can use IncludeTotalCount() to add $inlinecount=allpages query option to the query which will include the count in the response. Then to not download all the entities from server, you can use Take(0) which will add $top=0 and thus return empty result set. But the inline count will still contain the right number.
You can access the inline count on the QueryOperationResponse.TotalCount property.
Something like this:
NetflixCatalog ctx = new NetflixCatalog(new Uri("http://netflix.cloudapp.net/Catalog"));
var q = (DataServiceQuery<Genre>)ctx.Genres.IncludeTotalCount().Take(0);
q.BeginExecute((ar) =>
{
QueryOperationResponse<Genre> r = (QueryOperationResponse<Genre>)q.EndExecute(ar);
r.TotalCount.ToString(); // Use the count in whatever way you need
}, null);
It works in LinqPad 4 using C# 4.0
var count = (from g in Genres select g).Count();
count.Dump();
Result: 518
In LinqPad 2 using C# 3.0 the error appears.