The blog post about how to dynamically change the result sources in a search center was based on a solution that I created to show the duplicated results in a search center with JavaScript.
A standard Search Center in SharePoint 2013 doesn’t show the duplicated results by default. You have two options to view the duplicates:
- Is to turn on the Show view duplicates link in the search result web part settings;
- Or you could change the web part property TrimDuplicates in the webparts file, and set this value to false. The first result only shows a duplicates link when items have corresponding duplicates:
When you click on the link, you retrieve the set of results with the duplicate items:
The second approach is most properly the way you want the result set to behave, because you retrieve all the results including the duplicates. The downside of this approach is that you have less flexibility. Or it’s on, or it’s off, you can’t easily switch (or you need to create an additional page).
JavaScript Solution
What I wanted to achieve is that you could quickly set if you want to show or hide the duplicate results. The code for this is really simple. All you need to do is override the Srch.U.fillKeywordQuery function by your own custom function and set if you want to show or hide the duplicates for your search query.
The code for this looks like this:
|
|
This code can be added in a Script Editor web part. I placed this above my Search Box:
Result
The result looks like this:
Note: if you always want to show the duplicates, you only need to keep the dp.set_trimDuplicates(false) line and the originalFillKeywordQuery(query, dp) call to the original function.
|
|
PS: as this will be my last blog post of the year, I wish you all a merry Christmas & happy new year.