If you are about to implement an auto-compelte text box for your search page, then you are in the right place. This article will show you how to display search suggestions using Sitecore 7 and Solr Search Provider. Solr is a very powerful search platform which provides many indexing and query time analyzers. The NGram analyzer is used here to implement search auto-complete feature. Before I go through the details, please don’t do the following:
Don’t use String.Contains()
var context = index.CreateSearchContext(); var results = context.GetQueryable().Where(i=> i.Title.Contains(searchText)); ...
Please don’t ever do this, your client will come back complaining that, when their customers search for “pen” they get irrelevant suggestions such as “Dispenser”, “Open” and “Sharpener”.
Don’t use String.StartsWith()
var context = index.CreateSearchContext(); var results = context.GetQueryable().Where(i=> i.Title.StartsWith(searchText)); ...
This won’t work as well because it will fail to return results such as “blue pen” where the title doesn’t start with the word “pen”.
The proper way (Using NGram)
These are the steps to properly implement this feature:
Read More Sitecore 7 & Solr search auto-complete using NGram