I have implemented a site search feature on a website built on Umbraco CMS. For site search we are using Lucene.net which easily integrates with Umbraco.
The search works perfectly if I use a search string with a single keyword. For example there is page (in website) which has a header named "Domestic use video licence". Now if I use a search string "domestic" or "video" it works. But if I use "domestic video" or "domestic licence", no results are returned.
I want to build a query that would not only return the matches for the whole "domestic video" but also the pages with texts "domestic whatever video", "domestic" and "video" in them. Out of all the results returned, pages with a full match should have a higher score so that they take prominent positions on the search result.
Does anyone have any suggestions? My current code is below:
var criteria = ExamineManager.Instance
.SearchProviderCollection["WebSearcher"]
.CreateSearchCriteria(IndexTypes.Content);
var filter =
criteria.GroupedOr(
new[]
{
"nodeName", "heading", "content", "metaKeywords", "title", "umbracoNaviHide", "umbracoUrlName",
"umbracoUrlAlias", "metaCategory", "metaDescription", "metaTags", "heading", "subHeading",
"quote", "author", "socialCopy", "socialTitle", "socialTitle2", "thumbTitle", "thumbTitle2",
"thumbCopy", "thumbQuote", "url", "location", "question", "answer"
}, query)
.Compile();
var searchResults =
ExamineManager.Instance.SearchProviderCollection["WebSearcher"].Search(filter)
.OrderByDescending(x => x.Score).ThenByDescending(d => d.Fields["createDate"]);