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

November 22, 2012

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


%d bloggers like this: