Every web application that is being built these days has some sort of search functionality. I have seen different implementations. Some of them are simple and easy to maintain, some not so much so. I would like to share with you, readers of my blog, how I have implemented such functionality. I am not saying only my implementation is correct, but served me well in last three applications I have worked on.
To be able to produce search results based on category, all articles, news and press release page items as well as any other content needs to be "tagged" to this category.
To accomplish that I have implemented a base template with tree list "Category" field. The source of this category needs to point to a location in the Sitecore tree that represents the list of categories. All templates that can be tagged to category should inherit this template. So now, if an articles is tagged to a category or categories, it would show up in search results when you specify selected category value. Nothing remarkable so far.
The next part is landing pages. Lets say I would like to have three modules on my Category One landing page: news, articles, and press releases. Each of these modules should only display the content that is tagged to the Category One. There are two options - either implement a rendering data source that would have the category selection specified or have the same base template with Category field inherited by the landing page. When a value is selected in Category field on Category One landing page, it can be used to produce search results for all modules.
This approach might not be perfect, but seems to be pretty simple for editors to understand and for developers to implement. It allows tagging content to multiple categories/tags, reusing the same template for tagging and producing consistent results.
Assumptions
- Lets assume you have content that might belong to one or more categories
- Second assumption is that you have category landing pages that have listing modules that display content that is tagged to this category.
- You might have listing/search results modules on other pages of your website.
Key Concepts
To accomplish that I have implemented a base template with tree list "Category" field. The source of this category needs to point to a location in the Sitecore tree that represents the list of categories. All templates that can be tagged to category should inherit this template. So now, if an articles is tagged to a category or categories, it would show up in search results when you specify selected category value. Nothing remarkable so far.
The next part is landing pages. Lets say I would like to have three modules on my Category One landing page: news, articles, and press releases. Each of these modules should only display the content that is tagged to the Category One. There are two options - either implement a rendering data source that would have the category selection specified or have the same base template with Category field inherited by the landing page. When a value is selected in Category field on Category One landing page, it can be used to produce search results for all modules.
This approach might not be perfect, but seems to be pretty simple for editors to understand and for developers to implement. It allows tagging content to multiple categories/tags, reusing the same template for tagging and producing consistent results.