SearchResultSuggester

When you click an object field in the content edit form, the content picker appears with a list of search results applicable to the object type. For example, if an Article contains fields for Author and Image, clicking either of those fields invokes the Content Picker with a list of Author or Image search results. Obviously you want to select a result appropriate to the context of the containing article.

To assist the user in selecting a search result that’s most appropriate to the containing object type, you can implement suggestions to appear in the Content Picker search results. Say that you have an Article subclass for environmental content, which contains an Image field. To guide writers to set applicable images for the content type, you can implement filtering of search results and display suggestions for environmentally-themed images. In the following screenshot, Brightspot suggests images that are related to the environment.

../../../_images/suggestions.png

How Suggestions Work

As search results are rendered in the Content Picker, the search renderer calls the page servlet SearchResultSuggestions. This servlet passes control to a SearchResultSuggester implementation with the highest priority. Based on the object on which the Content Picker was invoked (such as Article), and on the search results returned (such as Images), the SearchResultSuggester implementation determines if there are suggestions to offer. If so, the implementation passes the suggestions to the search renderer.

Brightspot includes a default SearchResultSuggester implementation, SolrSearchResultSuggester. This implementation uses Solr database scoring to check for suggestions.

Implementing SearchResultSuggester

Override the following methods:

  • getPriority returns a numerical priority level that SearchResultSuggestions needs to determine which SearchResultSuggester implementation to use. The default priority level set in the SearchResultSuggester interface is zero. To use a SearchResultSuggester implementation other than the default SolrSearchResultSuggester, return a value greater than zero. To no longer use a SearchResultSuggester implementation, return a value less than zero.
  • writeHtml contains the logic for determining suggestions. To continue with the above example, this method would evaluate the context of the Article object and the Image search results and pass suggestions, if any, to the search renderer.