Question

How do I modify search to be able hit my searchString?

I have variables with following values:

fieldName: nodeName
searchString: des

I want to be able to find a nodeName by any contiguous characters in it: e.g. find Esa selects Ariane 6 basic design by entering design.

My current search is constructed as:

 var searchCriteria = SearchProvider.CreateSearchCriteria(BooleanOperation.Or);

 var luceneString = string.Format("{0}:", fieldName);
 luceneString += "(+" + searchString.Replace(" ", " +") + ")^10 ";
 luceneString += string.Format("{0}:{1}", fieldName, searchString);
 var rawQuery = searchCriteria.RawQuery(luceneString).Field(fieldName, searchString.Fuzzy(0.8f));

My Examine definition:

<add name="AutoCompleteLookupIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
           supportUnpublished="true"
           supportProtected="true"
          analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" />

Was it helpful?

Solution

You probably need to start much simpler than this. You need to build the following queries as the user types into the field:

nodeName:d*

nodeName:de*

nodeName:des*

nodeName:desi*

and so on.

If you want to search over more than one field, build the following queries:

nodeName:d* bodyText:d*

nodeName:de* bodyText:de*

nodeName:des* bodyText:des*

nodeName:desi* bodyText:desi*

This will perform an OR search, search both as optional fields. Adding a + to the front of nodeName will make that matching nodeName mandatory but bodyText optional, e.g:

+nodeName:d* bodyText:d*

If the user specifies more than one term, use regex to sanitize the input (remove all the non letter number characters), split string based upon spaces and build the following:

nodeName:graphic* nodeName:desi* bodyText:graphic* bodyText:desi*

Or making nodeName mandatory:

+(nodeName:graphic* nodeName:desi*) bodyText:graphic* bodyText:desi*

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top