SharePoint 2013 search results web part ignores sort order entered via Query Builder

I have been working with SharePoint 2013 since it was released a few weeks ago and even before that when it was still in Beta and if I’m honest I have been slightly disappointed. There are some great new features which have been added to the product but I have found there are certain elements which just don’t work as I would expect and this blog post is about one of these issues.

I am currently working on a project for a public facing website which is built on SharePoint 2013 and one of the components is to display the latest news. The news content is stored in a list and I decided to use the ResultScriptWebPart rather than writing some custom code or using the ContentBySearchWebPart or ContentByQueryWebPart to display the news items.

I added the search results web part to the news page and opened the ‘Change ‘Query’ popup in the web part properties, see figure 1.

SearchResultsChangeQueryButton

Figure 1

I then configured my search criteria using the advanced mode settings, see figure 2.

SearchResultsAdvancedSettings

Figure 2

Next I clicked on the ‘Sorting’ tab and entered the sort criteria I wanted the results to use, see figure 3.

SearchResultsSorting

Figure 3

Once I was happy with the query and the sorting options I tested my query by clicking on the test tab and checking the results I expected were return and they were in the correct order, see figure 4 for screen without any results for privacy reasons

SearchResultsTesting

Figure 4

At this point the query and sort order had been set and it was returning the correct results in the preview. When I saved the settings and returned to the page I noticed that while there were results they weren’t in the order I specified.

I spent ages checking settings and looking around but nothing I changed seemed to make a difference. Eventually just for testing I enabled the sort dropdown and noticed when this was on the page I was able to select different options from the drop down and this altered the sorting. From looking at the options in the drop down, see figure 5, it looked like these options were being pulled from the ‘Available sort orders (JSON)’ web part property under settings.

SearchResultsFilterDDLOptions

Figure 5

As soon as I looked at the options in the ‘Available sort orders (JSON)’ web part property it occurred to me that for some reason the web part ignores whatever you set in the actual query builder and only sorts based on the values in this property. I changed this to sort on the fields I wanted, see figure 6, and the results came back in the correct order.

SearchResultsJSONSort

Figure 6

There may be some setting I am missing but to me this seems backwards in that you can set the sort order in the ‘Change Query’ settings and they have a nice UI for it and it even uses these settings in the preview but as soon as you save the settings it sorts on the ‘Available sort orders (JSON)’ web part property. If anyone has any experience of this and there is another way around it please let me know

Advertisements

5 Responses to SharePoint 2013 search results web part ignores sort order entered via Query Builder

  1. We had the same issue and made a workaround using the information in your post! Thank you for sharing the information.

  2. Hi. I have also had the problem of results not being sorted properly, and I thank you for your post.

    The sorting is only part of a bigger problem however. I don’t know if this is a bug, or just the way the Search Results WebPart (SRWP) works, but unless I check in the box “Show ranked results” in the checkbox under settings in the WebPart toolbox, it won’t show any results at all. And if I select to show ranked results, I am not guaranteed to get all results. It is as it only shows items which has several views, or followers or something.

    The only way I get results without using ranked results, is by adding the search box webpart and manually entering a query.

    I wouldn’t find this behaviour strange really, since the SRWP is used to display search results. But I have found a couple of blogs (including this one) where the authors seem to be able to use it similarly to the Content Query WebPart, showing the correct results on page load. I am confused as to if something is wrong with my environment (and the 2 other environments I have tried this on), or if you are not aware that perhaps showing ranked results don’t guarantee you the results your query should collect.

    For me, a query that return perhaps 5 results when I test it in the query builder, will return only 2 ranked results. If I choose not to show ranked results, it will always return 0 results, even though it will tell me that it has found 5 results (if I check the “Show results count” in the webpart settings).

    Of course I get no errors in the logs. 😦

    I cannot tell if this is normal behavior or a bug. Do you have any idea?

  3. Jacinto B says:

    Thank you! Been at it for a couple of hours trying to figure out why it wouldn’t sort. Cheers from YYC

  4. Actually, since I posted my previous comment, me and a colleague of mine found a solution to get all results shown in the SRWP. In the query builder dialog, simply group the search results by something, anything, and make sure “Show ranked results” is selected. Since this is a solution that lacks logic at all, I assume that the SRWP is bugged, or has serious design flaws. But without SharePoint Enterprise, it’s the closest we can come to the Content Query WebPart.

    Together with the sorting option you posted here, we can now use the SRWP to present any kind of search results we want, using it as a site map, news feed, announcement list, or whatever.

    /J

    • raymondlittle1000 says:

      Hi,

      Thanks for the feedback I will give this a try and see if it works.

      Sometimes you wonder why SharePoint stuff doesn’t just work as expected 🙂

      Cheers,

      Ray

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: