1

Is there documentation on how to create groups for search results, preferably using managed properties? All that I was able to find on it is using query rules, result blocks, or this great tutorial: http://www.eliostruyf.com/grouping-search-results-with-display-templates-for-the-cswp/, but it uses completely custom templates while I'm using modified versions of the default control, item, and group display templates and I really want to retain many of their features and just add what I need instead.

I want to organize the results by site title. I'm hoping to use each item's ParentLink managed property to get the Parent URL or Parent Web and from there, get the title. The search is collecting different items from all the site collections in the farm so that's why I want to organize it this way. How can I at least make groups? Where would this be placed within the control, item, and group templates?

  • If you want to group your search results you'll have to write some code to do this. Which is explained in the article you referenced. You could maybe go for another approach, but this will always involve additional code in your display templates because this functionality is not out-of-the-box available. The explained approach can also be used in your templates. The provided templates can be used as a reference. – Elio Struyf Mar 10 '16 at 8:59
  • I am the same person that replied on your blog through that link. I refreshed the page on there yesterday twice and seems like both my comments are gone. I apologize if they do show up later though. I'm using the Item_Default, Control_SearchResults, and Group_Default display templates provided by SharePoint. My problem in the beginning was that I thought I HAD to use the Group since that was directly rendering the items. My last two comments explained my initial problem. Since then, I've left the Group alone and have placed your code in Control and Item respectively. – LaLaLottie Mar 11 '16 at 19:47
  • The groups work! But how I'm defining my content doesn't. The items are appearing before the groups and the groups also list all the (correct) items, but they're really stripped down (down to objects not actual content) and I'm having trouble defining content so it displays everything exactly how it's supposed to. Would it be okay if I show you part of my item template? – LaLaLottie Mar 11 '16 at 19:50
  • You're working with the templates for a search result web part. In the CSWP the group template does not output any HTML. This is only done by the item and control templates, but for the search result web part it is different. The group template has HTML, so to solve your problem, it would be best to move the grouping code from the control template to the group template. – Elio Struyf Mar 14 '16 at 8:18
  • Yes, I am. I know your guide was for the CSWP (which I originally used and figured I could translate it over to the SRWP), but I used it for SRWP. Anyway, I got everything figured out, thank you! When it came to content, I basically pushed all the parts that were HTML in the item display template to it using a super long String.format which probably needs condensing. I essentially stripped a lot of the fancy OOTB animations that came along with those templates just to display the needed text. – LaLaLottie Mar 14 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.