0

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"]);
TejSoft
  • 3,213
  • 6
  • 34
  • 58

1 Answers1

0

I think you need to use the GroupedOr method of the search criteria to generate your query.

The GroupedOr method expects two lists, one of field names, and one of search keywords. e.g.

var query = provider.CreateSearchCriteria(BooleanOperation.And)
    .GroupedOr(siteSearchFields,
    searchTerms).Compile();

There's a full example in this Gist: https://gist.github.com/tarnacious/1399392

Tim
  • 4,217
  • 1
  • 15
  • 21
  • By doing that I am hitting the "maxClauseCount is set to 1024" error. How to increase value of max clause count? Couldn't find a config value or any parameter in Examine. – TejSoft Feb 23 '16 at 00:33
  • You could us the Examine indexing events to concatenate all of the fields you want to search into a single field, that way you only have to search one field, instead of lots? – Tim Mar 04 '16 at 10:18