Azure Search provider - Results ordering issue
I was implementing Azure Search lately into my last project and I found some strange issue in the provider (we're using Sitecore 9.0.2 rev. 180604). When I wanted to order my search results using Linq like this:
it was translated to:
So it looks like it's taking argument of ThenBy as first and OrderBy as the second. Inverting parameters:
gave me desired query:
And search result as well were sorted like I wanted.
Azure Search documentation states nothing unusual, but I had to confirm this:
I have raised an issue on Sitecore Helpdesk and guys from support checked and reported the issue. It has a reference number 309333. Current resolution is to invert parameters like I did.
searchQuery.OrderBy(x => x.JobRole).ThenBy(x => x.LastName)
it was translated to:
$orderby=last_name_s,job_role_i
So it looks like it's taking argument of ThenBy as first and OrderBy as the second. Inverting parameters:
searchQuery.OrderBy(x => x.LastName).ThenBy(x => x.JobRole)
gave me desired query:
$orderby=job_role_i,last_name_s
And search result as well were sorted like I wanted.
Azure Search documentation states nothing unusual, but I had to confirm this:
$orderby=[string] (optional)https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents#orderbystring-optional
A list of comma-separated expressions to sort the results by. When calling via POST, this parameter is named orderby instead of $orderby. Each expression can be either a field name or a call to the geo.distance() function. Each expression can be followed by asc to indicate ascending, and desc to indicate descending. The default is ascending order. Ties will be broken by the match scores of documents. If no $orderby is specified, the default sort order is descending by document match score. There is a limit of 32 clauses for $orderby.
I have raised an issue on Sitecore Helpdesk and guys from support checked and reported the issue. It has a reference number 309333. Current resolution is to invert parameters like I did.