Is there a way in azure search, to bring data orderby
value to top and remaining below. Bringing the hotel's in user's location country to top and then other results
For example: See the sample data below
HotelName | City | Country | RoomType | rating |
---|---|---|---|---|
XYZ | City1 | India | abc | 4 |
UVW | City2 | Australia | def | 5 |
KWHK | City3 | India | 6 | |
KHUK | City4 | China | 2 |
I want to get all the data, but country India
should be at top result and remaining should be below. (which includes pagination).
I am doing lucene query POST search for same , and below is my query json body for same .
Query: { search: *, queryType: 'full', count: true, skip: 0, top: 10, scoringStatistics: 'global', searchMode: 'any', }
CodePudding user response:
I believe if you include the country in your search should work, for example:
search=term OR (term and Country eq 'India')
a Similar question was answered by a MSFT product manager with more information:
https://stackoverflow.com/a/44766731/1384539
CodePudding user response:
You should consider using the geo.distance function in Search, basically when querying, you need to pass the current user's location as a edm.GeographyPoint in the Function, then when ordering the results, you can order them by closest to fartest location from the user. Documentation on this, there you will also see some examples https://docs.microsoft.com/en-us/azure/search/search-query-odata-geo-spatial-functions
POST /indexes/hotels/docs/search?api-version=2020-06-30
{
"search": "*",
"orderby": "geo.distance(Location, geography'POINT(-122.12315 47.88121)')"
}