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



1 comment:

Anonymous said...

Nice comparison, thanks for sharing!
- Keval