Creating Custom Sitecore Search Filters (Search Types)
When Sitecore houses more than 80,000 items, browsing for an item in the style of Windows Explorer is less than optimal. Our latest client produced content at a rapid clip, and the content types were typically articles with rich text containing plenty of Sitecore dynamic links. Browsing all these content items using the content tree was pretty cumbersome. But wait! Sitecore 7 introduced a new search interface in the Content Editor that utilizes the sitecore_master_index (with either the SOLR or Lucene indexing provider.) This new interface provides a fast, robust capability to search and select items, and you can perform bulk actions on those results to boot – more on that in a later post.
The Need for Custom Search Filters
When it came to finding the needle in that haystack of 80,000 items, our client needed more search filters than what comes out of the box1, i.e. the existing filters include things like template, language, site, tag, etc. While these were certainly useful, the client needed to be able to find article items with certain values selected in two custom multilist fields on the article template, Authors and Taxonomies. For example, an article may contain the line, “back in 2007, our very own Francis Fiedler proposed to end the practice.” Now, assuming that Francis is an internal author, we can do some nifty things with custom search filters2 to find this piece of content.
We proposed adding two custom filters to the Sitecore search interface: “Article Author” and “Article Taxonomy”. Using the combination of time filters (start and end) with the template filter and the new custom “Article Author” filter, it was easy to find a specific Article content item like in the example above and link to it. Multiply this practice by 30 times per week, and compare it to how long it would take to manually find each item when they are six to eight levels deep in the tree, and you can see the time savings pretty easily.
Implementation
For this example, we will look at the Article Taxonomy search filter. To implement custom Search Type items, follow two simple steps:
- Create items in Sitecore to represent the new search types.
- If using a selection control, such as Auto Suggest List (auto-complete), add a web service class to populate it.
Create the custom Search Type item in Sitecore under System/Settings/Buckets/Search Types/User Defined. Even though these custom filters live under the Buckets settings, Sitecore will also search content items that are not in Item Buckets. Define the name of the filter, the field name to be searched in the index, the control type, and the web service class file/method.
Add the web service class under Website/sitecore/shell/Applications/Buckets, and any necessary web methods for retrieving items that populate selection controls, such as the Auto Suggest List control. For brevity in the code sample below, only the GetTaxonomies method is shown since GetAuthors is very similar, and item paths and guids that I would typically store in a global item reference class are hard-coded:
Results
Here is an example of a search that I ran in the Content Editor using the new “Article Taxonomy” Search Type combined with a template filter and a text filter to narrow the results. This same search interface is also present in the “Insert Sitecore Link” modal of rich text fields.
Further References
- https://sdn.sitecore.net/upload/sitecore7/75/developer's_guide_to_item_buckets_and%20search_sc75-a4.pdf
- https://doc.sitecore.net/sitecore_experience_platform/developing/developing_with_sitecore/search_and_item_buckets/add_new_search_filters_and_alias_filters
- https://doc.sitecore.net/sitecore_experience_platform/content_authoring/searching/searching