I have to do a multi-sort search in the Dailymotion API, since I am not getting good results with the following queries:
https://api.dailymotion.com/videos?fields=id,title&search=test&sort=relevance
https://api.dailymotion.com/videos?fields=id,title&search=test&sort=visited
I want to combine both the queries...
I have tried using:
sort=visited,relevance
but it gives the following error:
{
"error":{
"code":400,
"message":"Unrecognized value (visited,relevance), allowed values are (
recent, visited, visited-hour, visited-today, visited-week,
visited-month, commented, commented-hour, commented-today,
commented-week, commented-month, rated, rated-hour, rated-today,
rated-week, rated-month, relevance, random, ranking, trending, old,
live-audience
) for `sort' parameter",
"type":"invalid_parameter"
}
}
Please point me in the correct direction!
The Daily Motion REST API doesn't appear to permit multi-field sorting (at least not as of the time of this answer.)
https://developer.dailymotion.com/api#video-sort-filter
Related
I have a django project which uses elasticsearch 6.5.3 to index products in a store with locations as GeoPoints. I am trying to query this index and also calculate distance between an arbitrary point, say user's location to each oh these results.
I am using elasticsearch_dsl and my code looks something like this:
search_query = search_query.script_fields(distance={
'script':{
'inline':"doc['location'].arcDistance(params.lat, params.lon)",
'params': {
'lat':user_loc.lat,
'lon':user_loc.lon
}
}
})
for result in search_query.execute():
print(result.distance)
Which gives me values that looks like:
[123456.456879123]
But I'm not sure about its units.
By using and online distance calculator in https://www.nhc.noaa.gov/gccalc.shtml,
which gives me the distance as ~123km,
It looks like value is in meters.
So:
1. Where can I find some definitive answers about its units?
Please point me to the relevant documentation for these methods.
I am also interested to know if there is a way to specify the units expected for the results in the method call.
2. Is there a better way to do this in python?
The units are those returned by the arcDistance method providing the value in your script.
The arc distance (in meters) of this geo point field from the provided lat/lon
The painless docs leave a lot to be desired (there appears to be no docs on this method in 6.5). The quote above was obtained from here: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/modules-scripting.html
Additionally, they mention arcDistance caluclates meters here: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/breaking_50_scripting.html
I'm not sure about the exact python API, but elasticsearch have Geo Distance Query:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
In: https://github.com/elastic/elasticsearch-dsl-py/issues/398 there's an example of python usage of ES API:
MyDocType.search().filter(
'geo_distance', distance='1000m', location={"lat": "40", "lon": "-74"}
)
The 'geo_distance' query is the easiest way to get a distance between two geo points indexed to elasticsearch. I thinking that you don't need to use scripting in order to achieve that.
Regarding the distance unit, as you suspected the default is meters. from:
https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#distance-units
Wherever distances need to be specified, such as the distance parameter in the Geo Distance Query), the default unit if none is specified is the meter.
I've been playing a little bit with the Wikidata SPARQL page (here), and I was wondering if we can shuffle the order of the results set randomly.
I tried the following example, and I left the random part as a comment cause I couldn't find the correct syntax for it:
SELECT ?partyLabel ?countryLabel ?count
WHERE{
?party wdt:P31 wd:Q7278.
?party wdt:P17 ?country.
?party wdt:P2124 ?count
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}
}
order by #random
limit 15
Did anyone try the random ordering option? and does it exist?
Possible candidates are:
RAND()
BNODE()
UUID()
STRUUID()
However, neither ORDER BY RAND() nor ORDER BY BNODE() works on Wikidata even with hint:Query hint:optimizer "None" (that's why).
As for UUID() and STRUUID(), it seems that there is no significant performance difference, so you can use any of them.
Please note that both browser and server cache results, hence, add a few spaces or commented current time to every query.
Update
With a single triple pattern, one can use the sample service.
I found that nearby search returns inconsistent results.
I ran this query one day (go client lib). It returned me 4 results. Given
keyword=Resorts+World+Sentosa+Equarius+8+Sentosa+Gateway&location=1.2564%2C103.8189&rankby=distance&type=lodging
https://gist.github.com/haibin/20e01d38c10d4da9275439c549a2db91
I ran this query another day (go client lib). It returned me 5 results. Given
keyword=Resorts+World+Sentosa+Equarius+8+Sentosa+Gateway&language=en&location=1.2564%2C103.8189&rankby=distance&type=lodging
https://gist.github.com/haibin/b40e4952b7fddace78d6c37a19542a40
I ran this query today (curl). It returned me 1 result. Given
keyword=Resorts%20World%20Sentosa%20Equarius%208%20Sentosa%20Gateway&language=en&location=1.2564%2C103.8189&rankby=distance&type=lodging
https://gist.github.com/haibin/a65a6d03ace05898913e306840307bdb
Any idea why?
Possibly there was a bug in google places API when using rankby=distance parameter it skips some result or search in "limited radius"
As when I ran curl with these params
https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=MY_KEY&keyword=Resorts+World+Sentosa+Equarius+8+Sentosa+Gateway&location=1.2564%2C103.8189&rankby=distance&type=lodging
it returned only one result as u said.
But when i ran with radius param it returns more results as accepted
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=1.2564,103.8189&type=lodging&keyword=Resorts+World+Sentosa+Equarius+8+Sentosa+Gateway&key=MY_KEY&radius=300
You are getting more results through go lib because probably they fixed it in that or something like that
For more info you can go through these issues:
Google Places API nearby search rankby distance skipping some nearest places
http://www.itgo.me/a/3468386017980994007/google-places-api-nearby-search-rankby-distance-skipping-some-nearest-places
Hope this will help you.
I am using the google-search gem for Ruby found here.
And I'm trying to make my search within a custom date range.
results = Google::Search::Web.new(query: "SearchTerm daterange:2455197-2455562")
That doesn't seem to work and just ignores the daterange which is how you would do the search normally with Google. So it gives me the results for the term with no date range.
Does anyone have any experience with this? Or maybe there is a better solution.
NOTE: I have no experience with 'google-search' gem, following
solutions are NOT tested!
According to google docs, the api expects something like:
https://www.google.com/cse?cx=12345:example&q=lebanese+restaurant&sort=review-date:r:20090301:20090430
To make google-search populate this request for us, you could try two things:
Use order_by option (which is not documented but i imagine it will do sorting)
results = Google::Search::Web.new(query: "SearchTerm", order: "review_date:r:2455197-2455562")
2.According to gem ReadMe:
Arbitrary Query String Support
Arbitrary key / value pairs may be passed to Google::Search.new, all
options passed that are not assigned (deleted) will pass on to be part
of the query string.
So, theoretically we could do:
results = Google::Search::Web.new(query: "SearchTerm", sort: "review_date:r:2455197-2455562")
Give it a try!
I am using the Place Searches from the Google Places API and wanted to know how the JSON results are returned/ordered.
E.g. are the list of places returned in a random order within the results array; or are they returned in order of nearest distance to the specified location i.e. with the first result in the results array being the nearest place to the specified location?
This is determined by the rankby parameter, which lets you choose either prominence (best search result match) or distance.
More info: https://developers.google.com/maps/documentation/places/#PlaceSearchRequests
This has been added to the API, please use the 'rankby=distance' instead of 'radius' in your Place Search Request as described in the documentation here: https://developers.google.com/maps/documentation/places/#PlaceSearchRequests