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!

Comments

  1. Kentico 13 xperience developers I would like to say that this blog really convinced me to do it! Thanks, very good post.

    ReplyDelete
  2. The 20 best casino games in Oklahoma City - OKHOMA
    The 20 아시안부키 best casino games in Oklahoma City bet 뜻 · Thunder Thunder · Thunder Valley's 승부사온라인환전 Legends · 10 뱃 Thunder Thunder League of Legends · Thunder 꽁머니 지급 Storm King · Thunder Warrior · Thunder

    ReplyDelete

Post a Comment

Popular posts from this blog

Attaching a file on WFFM Send email action

Solr with Sitecore Checklist

Set Workflow using Item Buckets Search Operations