Preset Searches in the Sitecore UI

You may have noticed that whenever you create a bucket, a new Insert Option Saved Search is added to your item. Its purpose is to create items that allow editors to run preset searches.

As an example, let's say I have a bucket with news items which have a field Region. Certain editors find themselves having to search for all the items which relate to the region London.
Normally they would have to:

  1. Click on the bucket item
  2. Type the name of the field and the search term: region:London
  3. Press Enter or the search button

You can make their life easier by creating a Saved Search. Then this process is reduced to simply:

  1. Click on the London news Saved Search item.

Saved search item example How does this work?

Default bucket query and Persistent bucket filter

There are two standard fields defined in the Item Buckets section that actually have nothing to do with Buckets. They relate to the Search UI instead. When opening a search tab on an item, Sitecore will pre-populate the search field with the search query defined in the Default bucket query and Persistent bucket filter fields. The difference between both is that the terms set on the Default bucket query can be removed by the user, whereas the Persistent field defines terms that can't be changed or removed.
show default bucket query and persistent bucket filter fields

The search specified in those fields must follow a peculiar syntax. Fortunately you don't need to learn it. You can instead use the Build query option. This opens up a pop-up window with a standard Search UI where you can construct the query. By default it is set up to search only for items below the curren titem.
Build Search Query popup

The Persistent Bucket Filter can be very useful whenever you need users not to be able to find certain search results. One could argue it would be better not to include those items in the index altogether. This is for example why bucket folders don't show up when performing searches, they are simply not indexed by default. However there could be situations where you actually want the items in the index, yet you don't want editors to find them.

The Saved Search item simply makes use of those two fields. In order to get the search tab open by default it also defines it as an editor in its Standard Values (see in the Configure tab, Editors option).

Creating the Saved Search item

In order to set up the London news Saved Search item, shown in the example above, you would:

  1. Click on the bucket and create a new Saved Search item and name it London news
  2. Show the Standard Fields pressing Ctrl+Alt+Shift+T
  3. Find the Persistent bucket filter field and click on Build query
  4. Remove the existing Location filter (otherwise you won't see any results as it is searching below the Saved search item, not below the bucket).
  5. Set a new location for the search. Type Location:News (or the name or ID of your bucket item)
  6. Add the other search terms, in this case type Region:London
  7. Change the Region search term to be compulsory. Click twice on the icon of the term. The first time it will negate it, the second it will add a + sign; this indicates it must satisfy this criteria.
    filled criteria
  8. Press OK to close the popup
  9. Save changes (Ctrl+S)
  10. Hide Standard Fields (Ctrl+Shift+Alt+T)
  11. Switch to the Search tab.

You can create this type of items anywhere, not just under buckets. Their functionality has nothing to do with buckets, except they get added as an insert option to buckets. Since they are regular items, you can also set security on them, so you could provide a varying set of predefined searches according to the user/role logged in.