Thursday, 6 March 2014

Difference between Search Result web part and Content by Search web –part II: TrimDuplicates property


Hi Again,
Today, second difference I am sharing is regarding the “TrimDuplicates” property.

Scenario / Background:

 We have SearchResult (ResultScriptWebPart) web part on one page and we are showing some pages based on Title and Path managed properties. We are come up with one weird issue, we couldn’t see all the results, very few results are shown.

In QueryBuilder, in Search Result Preview pane we could see all the result properly. But when page is Saved/Published we couldn’t see all the result. Results are very less but expecting all the result. Really wondering why this is happening.

Then we thought to verify the same query in Content By Search (CBS) web part and CBS was showing all the expected result.  So we have exported both the web parts and verify the difference in their DataProviderJSON properties and along with other differences, this difference which catch our attention is TrimDuplicates property.

DataProviderJSON property for (I have shorten it for understandingJ)


1.    Search Result web part:

<property name="DataProviderJSON" type="string">{"QueryGroupName":"705a414d-64de-4918-b907-cfa448e7642c","QueryPropertiesTemplateUrl":"sitesearch://webroot","IgnoreQueryPropertiesTemplateUrl":false,"SourceName":"Local SharePoint Results","SourceLevel":"Ssa","CollapseSpecification":"","QueryTemplate":"{searchboxquery} Path:{SiteCollection.URL} Title:Home","TrimDuplicates":true, "ClientType":"","UpdateAjaxNavigate":true}</property>
 
2.    Content By Search web part:
        <property name="DataProviderJSON" type="string">{"QueryGroupName":"ffb1a85d-
          f511-4e73-9612-ba5e7d5dfd07", "QueryPropertiesTemplateUrl":" sitesearch://webroot",
          "IgnoreQueryPropertiesTemplateUrl":false,"SourceName":"LocalSharePoint 
          Results","SourceLevel":"Ssa","CollapseSpecification":"","QueryTemplate":"Path:
         {SiteCollection.URL}  Title:Home","TrimDuplicates":false,
         "ClientType":"ContentSearchRegular","UpdateAjaxNavigate":true}</property>

Please note that first bold statement in a query ("Path:{SiteCollection.URL}  Title:Home") which is similar for both the web parts and second bold and italic statement (TrimDuplicates) is regarding TrimDuplicates property.

By default TrimDuplicates property is True in Search Result web part. So we changed value TrimDuplicates of property to False and uploaded the web part, added it on page and web part is showing all the result as expected. Here note that even though our content is not duplicated, but any how it was not showing before this change.

But still I was wondering since Content By Search web part is derived from Search Result web part (ResultScriptWebPart) and from UI we don’t have to option to change the TrimDuplicates property. So again my best friend ILSpy came to rescue, I found that ResultScriptWebPart class have an instance of DataProviderScriptWebPart, and this class has a TrimDuplicates property and default value set to True as shown in following figure1 and figure2:

 
 
Fig. 1 and 2 DataProviderScript web part and TrimDuplicates property
 
Now I was wondering how CBS web part has this property to False so I digging the CBS web part in ILSpy and found that this property is set to False as shown in following figure:


Fig. 3 : ContentBySearch web part and TrimDuplicates property

Difference:
 
TrimDuplicates property is True by default in Search result web part. But False in Content By Search web part. 
 
Important Points:
1.    There is no way available to change the value of this property from UI except export, change and upload it again.
2.    To show all the results in Search Result web part we need to manually change the value of this property from True to False
That’s all here for now; I’ll try to keep posting such interesting differences.
Thanks!       
 
Enjoy reading J
Feel free to ideas / comment / feedback if any or if you have any query J



Tuesday, 4 March 2014

Difference between Search Result web part and Content by Search web –part I: AvailableSortsJson property

Hi Again,

Since long time I was thinking to write this post and finally started. Since this post may get very long J I thought to divide in to number of posts. So this is first post.
Today 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 spend at least 30-60 minutes to resolve the issue regarding this property. We have one CBS (Content By Search) web part provisioned for news articles and we are doing sorting on our custom managed property news article date(NewsArticleDate) and seems to be everything is fine. We have "DataProviderJSON" property in web part looks like as follows, I have shorten it for understanding and also please have a look for sorting made 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>
Also please notice the “AvailableSortsJson” property which is null as shown follows.

<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 requirement of searching news on news listing page and we are using the Search Result webpart for it. We have to do the sorting here also on our custom managed property NewsArticleDate. So we did the same thing as did for above 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>
Here also please notice the “AvailableSortsJson” property which is shown follows.

<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>

But unfortunately this doesn’t seem to be working. Search result is not getting sorted on NewsArticleDate.

Then I took the help of my best friend ILSpy, trying to dig the very complex architecture of Content by search and Search Result web part. Then I noticed that SearchResult web part considers the AvailableSortJson property. This means that we also need to update the AvailableSortJson property of Search Result web part for doing 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>

And wonder happens now result is sorted in Search Result web part on my custom managed property.
Difference:

1. Search result web part gives the default options for sorting but CBS not as

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>

CBS: <property name="AvailableSortsJson" type="string">null</property>

2. To have sorting on our custom managed property in Search Result web part, we need to update the make it available first for sorting using AvailableSortsJson”. This change is not required for CBS web part.
That’s all here for now, I’ll try to keep posting such interesting differences.

Thanks!          
Enjoy reading J
 
Feel free to ideas / comment / feedback if any or if you have any query