Difference Between Search Result Web Part and Content by Search Web Part I: AvailableSortsJson Property

Hi again.

For a long time I was thinking to write and have finally begun. Since this article may get very long I thought to divide it into a number of articles. So this is the first article.

Today the first difference I am sharing is regarding the “AvailableSortsJson” property.

Scenario / Background

You might be wondering why I am specifying the difference for this property. Because I have spent at least 30-60 minutes to resolve the issue regarding this property.

We have one Content By Search (CBS) web part provisioned for news articles and we are sorting on our custom managed property news article date (NewsArticleDate) and everything seems to be fine. We have the "DataProviderJSON" property in the web part that looks as follows, I have shortened it for understanding. Also please have a look at the sorting done on NewsArticleDate shown in bold.

  1. <property name="DataProviderJSON" type="string">{"QueryGroupName":"Default","QueryPropertiesTemplateUrl":"sitesearch://webroot","IgnoreQueryPropertiesTemplateUrl":false,"SourceID":"8413cd39-2156-4e00-b54d-11efd9abdb89","SourceName":"Local SharePoint Results","SourceLevel":"Ssa","CollapseSpecification":"","QueryTemplate" ContentTypeId:0x010100 6B0DE1C0F3B84A5E8E60-607433E01D8A*", "FallbackSort":[{"p":"NewsArticleDate","d":1}],"FallbackSortJson":"[{\"p\":\"NewsarticleDate\",\"d\":1}]","RankRules":null,"RankRulesJson":"null","AsynchronousResultRetrieval":false,"SendContentBeforeQuery":true,"BatchClientQuery":true}  
  2. </property>  
Also please notice the “AvailableSortsJson” property that is null as in the following:
  1. <property name="AvailableSortsJson" type="string">null</property>  
This web part is working perfectly fine, showing the sorted result based on our custom managed property NewsArticleDate.

Then we have the requirement to search the news on the news listing page and we are using the Search Result webpart for it. We need to do the sorting here, also on our custom managed property NewsArticleDate. So we did the same thing as for the preceding CBS web part.
  1. <property name="DataProviderJSON" type="string">{"QueryGroupName":"66bc0bb9-5b82-4b5e-a065-dbae1738ae20","QueryPropertiesTemplateUrl":"sitesearch://webroot","IgnoreQueryPropertiesTemplateUrl":false,"SourceID":"8b16ca39-1e06-494f-a0a4-a86b0aa89daf","SourceName":"Local SharePoint Results","SourceLevel":"Ssa","CollapseSpecification":"","QueryTemplate":"{SearchBoxQuery} ContentTypeId: 0x010100 6B0DE1C0F3B84A5E8E60-607433E01D8A* ","FallbackSort":[{"p":" NewsArticleDate ","d":1}],"FallbackSortJson":"[{\"p\":\" NewsArticleDate \",\"d\":1}]""RankRules":null,"RankRulesJson":"null""AsynchronousResultRetrieval":false,"SendContentBeforeQuery":true,"BatchClientQuery":true}  
  2. </property>  
Here also please notice the “AvailableSortsJson” property as in the following:
  1. <property name="AvailableSortsJson" type="string">[{"name":"Relevance","sorts":[]},{"name":"Date(Newest)","sorts":[{"p":"Write","d":1}]},{"name":"Date(Oldest)","sorts":[{"p":"Write","d":0}]},{"name":"Lifetime Views","sorts":[{"p":"ViewsLifeTime","d":1}]},{"name":"Recent Views","sorts":[{"p":"ViewsRecent","d":1}]}]  
  2. </property>  
But unfortunately this doesn't seem to be working. The Search Result is not being sorted on NewsArticleDate.

Then I took the help of my best friend ILSpy, trying to dig into the very complex architecture of Content by search and Search Result web part. Then I noticed that the SearchResult web part considers the AvailableSortJson property. This means that we also need to update the AvailableSortJson property of the Search Result web part for doing the sorting on our custom managed property so I changed the AvailableSortJson as follows.
  1. <property name="AvailableSortsJson" type="string">[{"name":"Date(Newest)","sorts":[{"p":" NewsArticleDate","d":1}]}]</property>  
And wonder happens? Now the result is sorted in the Search Result web part on my custom managed property.

Difference
  • The Search Result web part gives the default options for sorting but the CBS does not as in the following:
    1. SearchResult: <property name="AvailableSortsJson" type="string">[{"name":"Relevance","sorts":[]},{"name":"Date(Newest)","sorts":[{"p":"Write","d":1}]},{"name":"Date(Oldest)","sorts":[{"p":"Write","d":0}]},{"name":"Lifetime Views","sorts":[{"p":"ViewsLifeTime","d":1}]},{"name":"Recent Views","sorts":[{"p":"ViewsRecent","d":1}]}]  
    2. </property>  
    CBS
    1. <property name="AvailableSortsJson" type="string">null</property>  
  • To have sorting on our custom managed property in a Search Result web part, we need to update to make it available first for sorting using “AvailableSortsJson”. This change is not required for CBS web parts. 
That's all here for now, I'll try to keep writing such interesting differences.

Thanks!

Feel free to provide ideas, comments and feedback, if any, or if you have any query.

Similar Articles