Building Sitecore Content Search Queryable using Rules engine

Recently i have built a custom search module which uses Sitecore Content Search API that would let you define the search criteria directly from content editor, where you would be able to select which index, start locations, Templates that you want the results to filter on from the content tree



i also wanted to add fields filter, like filter on checkbox, date, Single-line Text fields etc. I had an idea to build this Fields filter using Sitecore Rule Engine since it seemed like a good fit here! Imagine you would be able to build a filter like:
  • Where [Field Name] is equal [String Value]
That would be nice, right?
So i started digging into rules conditions and see how can i make this possible, And came to my surprise that Sitecore have built a predefined set of conditions to do just the job!

Using this Query builder rule [/sitecore/system/Settings/Rules/Search Query Builder] you will be able to see the set of conditions for Search query where you can build your filter, and also assign boosting value on the filter! So i added a new field on my Search setting template of type Rules and set the source to be [rulespath=/sitecore/system/Settings/Rules/Search Query Builder] , Now if i go to the search setting item and open the Edit Rule editor for the new field, i see the following window:


So now i can build query like these directly from content editor:



Now to the code part, i wanted to executed the query built using the rules editor and return the filter results back, I was able to use the following code snippet (stripped of other code areas that my search module has) to return IQueryable object after applying the filter on it :



And Voila! it worked like a charm, i can build field filters directly from Content editor!

Hope this was a helpful post for you!

Popular posts from this blog

Integrating Lucene.Net.Contrib.Spatial with Sitecore Search API (Geo-Spatial Search)

Sitecore Spatial/Geo Location Search Module

Caching Rendering HTML when conditional rules are applied