Tuesday, 19 February 2019

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:

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)

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.
https://docs.microsoft.com/en-us/rest/api/searchservice/search-documents#orderbystring-optional

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.


Share it:

Radosław Kozłowski - Senior Sitecore Developer Radoslaw Kozlowski

Author & Editor

Sitecore MVP, passionate Sitecore & .NET developer and architect. Sitecore Community evangelist.

11 comments:

  1. pmp certification hyderabad
    https://360digitmg.com/pmp-training-in-hyderabad
    PMP® certification is de facto project management standard practices. PMP® certification training course at 360digiTMG takes you through a vast project management learning experience that is truly unmatched. Our industry-expert trainers will lead the way as you explore the foundational concept of project management.

    ReplyDelete
  2. You might comment on the order system of the blog. You should chat it's splendid. Your blog audit would swell up your visitors. I was very pleased to find this site.I wanted to thank you for this great read!!

    360DigiTMG PMP Certification
    360DigiTMG PMP Certification in Malaysia
    360DigiTMG PMP Course
    360DigiTMG PMP Course in Malaysia

    ReplyDelete
  3. This website and I conceive this internet site is really informative ! Keep on putting up!
    data science course

    ReplyDelete
  4. I am impressed by the information that you have on this blog. It shows how well you understand this subject.
    data analytics course
    big data analytics malaysia
    big data course

    ReplyDelete
  5. Set aside my effort to peruse all the remarks, however I truly delighted in the article. It's consistently pleasant when you can not exclusively be educated, yet in addition, engaged!

    https://360digitmg.com/course/project-management-professional-pmp

    ReplyDelete
  6. This is a great motivational article. In fact, I am happy with your good work. They publish very supportive data, really. Continue. Continue blogging. Hope you explore your next post
    hrdf claimable courses

    ReplyDelete
  7. You re in motivation behind fact an on-target site administrator. The site stacking speed is amazing. It kind of feels that you're doing a specific trick. What's more, The substance is a masterpiece. you have done a marvelous development concerning this issue!
    360DigiTMG Data Analytics Course

    ReplyDelete
  8. Especially superb!!! Exactly when I search for this I found this webpage at the top of every single online diary in web crawler.
    data science course in malaysia

    ReplyDelete
  9. an extremely wonderful post this is. Genuinely, perhaps the best post I've at any point seen to find in as long as I can remember. Goodness, simply keep it up.
    what is hrdf claimable

    ReplyDelete
  10. This is a great motivational article. In fact, I am happy with your good work. They publish very supportive data, really. Continue. Continue blogging. Hope you explore your next post
    HRDF training

    ReplyDelete
  11. Two full endorsement for this magnificent article of yours. I've genuinely refreshing scrutinizing this article today and I figure this might be uncommon contrasted with other articles that I've examined now. On the off chance that it's not all that much difficulty prop this work up on in a comparable quality.
    data science course in delhi

    ReplyDelete