Azure / Office 365 / SharePoint Development / Search

View Duplicate Results in the SharePoint 2013 Search Center via JavaScript

on Dec 19, 2013 by Elio Struyf with 7 comments

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:

  1. Is to turn on the Show view duplicates link in the search result web part settings;
  2. 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:

Default View Duplicates

Default View Duplicates

When you click on the link, you retrieve the set of results with the duplicate items:

Duplicates Result Set

Duplicates Result Set

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:

Script Editor

Script Editor

Result

The result looks like this:

Result set without duplicates

Result set without duplicates

Result set with duplicates

Result set with duplicates

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.

 

Article comments

  • This is great, just what I needed. Thanks! I really didn’t want to have to export every search web part I had on my site to set the TrimDuplicates property and the Show Duplicates link is too hidden in 2013 for people to actually find.

    • kyle,

      Thank you for the feedback.

      Regards,
      Elio

  • Syl’

    Great BUT it is only working on Chrome. Neither IE, nor firefox seem to support it.

    • Syl,

      Are you receiving any error messages via JavaScript? Which version of the browsers?
      I only use Firefox and IE as my main browsers, so it is tested in these two browsers.

      Regards,
      Elio

  • Brian G

    Thank you so much for sharing this, it came in very handy today and helped me add a nice piece to a series of search improvements for a client!

  • Nicknack

    Thank you, great think !!!