Saturday, July 13, 2013

SharePoint 2013 Search: Instant Refinement of Multi-Value Properties - No Need to Apply

Overview
When you configure a refinement as multi-value, the user is presented with the list of available filters with checkboxes:

The user must select one or more checkboxes and then click on the Apply link. After they click on the Apply link, the results are refined by the selected filters but only the selected filters are presented:

With my Instant Refinement solution, all filters are displayed all of the time and when the user clicks on a checkbox, the results are instantly refined without the need to click on an Apply link.
This post describes a high level overview of the steps necessary for the instant refinement functionality. You may find the code and more detailed steps in my new Enhancing the Search Experience in SharePoint 2013 guide book.
 
 
Modification Steps
 

Step 1: Modify or Copy the Multi Value Display Template


Using SharePoint Designer 2013, navigate to the Filters display templates. Copy or modify the Filter_MultiValue.html file. Edit the file in advanced mode.

Step 2: Store the Original Filters

At the bottom of the display template add code to store the original set of refiners in a property of the RefinementControl object.

<!--[endif]-->

Step 3: Retrieve the Original Refiners

At the top of the display template you need to create a new array to store the original filters. Along with this you need to add logic to retrieve the previous refiners if they exist.

Step 4: Remove Condition from theRefiners Collection Creation

Scroll down the !hasNoListData condition block and remove the !hasAnyFilterTokens && check from the condition inside.

Step 5: Change Filter Tokens Logic

Scroll down to the hasAnyFilterTokens condition block and replace the refiners.push statement with code that just sets the IsSelected property to true if the refiner has been checked by the user.


Step 6: Save the Template Changes


 

Step 7: Modify the Controls in the Body Template


Modify or copy the Filter_MultiValue_Body.html file. Edit the file in advanced mode. Scroll to the bottom and find the submit link. Copy the onclick property. Paste the onclick into the checkbox inputs. Remove the Other and Submit divs sections from the bottom. Save the changes to the body file.

Step 8: Test the Changes

Navigate to your search page that contains the multi value refinements and review the experience:


 




You may click on each checkbox and watch the results instantly refine while always displaying all possible filters!!!

I improved this even further by creating a cascading solution for when you have multiple multi-value refinements!

GET ALL OF THE CODE AND DETAILED STEPS IN MY NEW SEARCH EXPERIENCE GUIDE:

 

SPECIAL LOW KINDLE PRICE!!!

22 comments:

  1. Thanks and your book also has some other cool stuff!
    But when I implemented the instant refiners (like described in your book) and I select another refiner the counts of the instant refiner are not adjusted accordingly...
    If I find it I will let you know.
    Jan

    ReplyDelete
    Replies
    1. I believe that is why I built the cascading refinenent solution on top of the instant version. The cascading solution adds logic to handle the updates of any other refiners. The first refiner section clicked becomes the "controller" and causes the other refiner sections to update their counts.

      Delete
  2. Sorry my fault, I saw it myself when I continued reading your book...
    Anyway thanks for the reply and the code
    Jan

    ReplyDelete
  3. Hi again,

    I have a strange experience after implementing the instant and cascading refinement solution.
    If one selects an instant refiner value (in my case e.g. "htlm" from File Type instant refiner) and after that I select a search result. Everything is fine but when I go back to the search results all the other refinement values seem to be disappeared (only the selected refiner is still presented, in the above example html and the orther ones like pdf, doc, ... have gone)

    adTHANKSvance,
    Jan

    ReplyDelete
    Replies
    1. When you go back, the refinement selection is in the URL so it doesn't go grab all the refiners again. I don't have a good answer for this yet.

      Delete
    2. Hi Steve,
      This thread is old so I'm not sure if you'll see this. I've also encountered the issue described above: the URL stores refinement selection, so upon returning to search results (or refreshing the page, as in my case), only the selected refiners appear, and the others vanish. Do you have a solution for this problem yet?

      Thanks for your help,
      Sam

      Delete
    3. Send me an email Steve at stevethemanmann.com

      Delete
  4. Hi Steve,

    Thanks for your reaction! I'll look for a solution too, but I'll follow this page also (in case you are faster ;-)
    Jan

    ReplyDelete
  5. Hi Steve,

    Recently got your book and tried to implement this but is facing a challenging task. I need to use the AND boolean operator instead of default OR would you know how to change that? Basically, I don't want my query to expand when I am selecting more tags

    ReplyDelete
    Replies
    1. I am trying to look into this. I have someone else looking at it too. Hopefully we'll come up with an answer.

      Delete
    2. Here is the answer: http://stevemannspath.blogspot.com/2013/10/sharepoint-2013-search-changing.html

      Delete
    3. Hi Steve,

      Thanks for the notes on changing to AND operator, really appreciate it. Was not able to try last time due to other priorities, will try again once I have time :)

      Delete
  6. Hi Steve,
    Got your book. But facing issue on assigning listData = prevRefiners;
    Error: type error.unable to get property length
    Not able to assign prevRefiners to listData. please help on this

    ReplyDelete
  7. Hi Steve,
    Got your book. Facing one issue.
    In Step 3: Retrieve the Original Refiners.At the top of the display template, RefinementControl object is always getting as undefined. So not able to assign prevRfiners to listData.
    Please help

    ReplyDelete
    Replies
    1. Send me an email: steve at stevethemanmann.com I have updated templates that work better.

      Delete
  8. Mr. Mann,

    I realize that this is an old post, and you may not be monitoring it...

    I am not a Site Collection administrator in my situation... is this still possible to do for just one site or even just a page within my own team site? If so, how do I find the "Filters display templates"?

    Your help will be greatly appreciated.

    ReplyDelete
    Replies
    1. If you can get to the Site Settings and then the Master Page gallery, you can do it through the UI. I don't know the permission levels off-hand. At the very least you would need Full Control of the site.

      Delete
  9. Is there a way to obtain the templates? It is (at least for me) kinda tricky to recconstruct those based on your book. I blame a combination of lack of experience on my side and bad formatting within the book. :-)

    Thanks
    Simon

    ReplyDelete
    Replies
    1. send me an email. Steve at stevethemanmann.com

      Delete
  10. Hi Steve,

    Could you please help me with the modified display template I tried doing it by this blog but I am facing some issue. Tried emailing my query to you but received failure message.

    -Thanks
    Neha

    ReplyDelete

Matched Content