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.
- <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}
- </property>
- <property name="AvailableSortsJson" type="string">null</property>
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.
- <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}
- </property>
- <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}]}]
- </property>
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.
- <property name="AvailableSortsJson" type="string">[{"name":"Date(Newest)","sorts":[{"p":" NewsArticleDate","d":1}]}]</property>
Difference
- The Search Result web part gives the default options for sorting but the CBS does not as in the following:
CBS:- 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}]}]
- </property>
- <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.
Thanks!
Feel free to provide ideas, comments and feedback, if any, or if you have any query.

Gowtham RajamanickamPosted Mar 11, 2015, 7:05 AM
good one..
Rahul Kumar SaxenaPosted Mar 11, 2015, 3:08 AM
good one Prasham Sabadra...
Ramesh BabuPosted Mar 10, 2015, 8:03 AM
Thanks
Prasham SabadraPosted Mar 10, 2015, 7:35 AM
Thanks!
Tom MohanPosted Mar 10, 2015, 4:54 AM
Good one.