Difference Between Search Result Web Part and Content by Search Web Part II: TrimDuplicates Property

Hi Again.

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

Scenario / Background

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

In QueryBuilder, in the Search Result Preview pane we could see all the results properly. But when the page is Saved/Published we couldn't see all the results. The were a few results but we were expecting all the results. We were really wondering why this was happening.

Then we thought to verify the same query in a Content By Search (CBS) web part and CBS was showing all the expected results. So we exported both of the web parts and verified the difference in their DataProviderJSON properties and along with other differences, the difference that caught our attention was the TrimDuplicates property.

DataProviderJSON property for (I have shortened it for understanding)

Search Result web part:

  1. <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>  
Content By Search web part:
  1. <property name="DataProviderJSON" type="string">{"QueryGroupName":"ffb1a85d-f511-4e73-9612-ba5e7d5dfd07","QueryPropertiesTemplateUrl":"sitesearch://webroot","IgnoreQueryPropertiesTemplateUrl":false,"SourceName":"Local SharePoint Results","SourceLevel":"Ssa","CollapseSpecification":"","QueryTemplate":"Path:{SiteCollection.URL} Title:Home","TrimDuplicates":false"ClientType":"ContentSearchRegular","UpdateAjaxNavigate":true}</property>  
Please note that first the bold statement in a query ("Path:{SiteCollection.URL} Title:Home") is similar for both of the web parts and the second bold and italic statement (TrimDuplicates) is regarding the TrimDuplicates property.

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

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



                         Figure 1



                           Figure 2

Figure 1 and 2: DataProviderScript web part and TrimDuplicates property

Now I was wondering how the CBS web part has this property set to False so I was researching the CBS web part in ILSpy and found that this property is set to False as shown in the following figure:


                             Figure 3

Figure 3: ContentBySearch web part and TrimDuplicates property.

Difference
  1. The TrimDuplicates property is True by default in a Search result web part but False in a Content By Search web part.
Important Points
  1. There is no way available to change the value of this property from the UI except to export, change and upload it again
  2. To show all the results in a 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!

Feel free to ideas / comment / feedback if any or if you have any query.