I'm trying to implement a fuzzy search which takes a string like "Samsung Galaxy S7 tablet" and searches across multiple fields (Category, Brand, Model), but I'm unable to set the sensitivity of the fuzzy query.
The following code
var line = "Samsung Galaxy S7 tablet";
Analyzer analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);
string[] searchfields = new string[] { "Category", "Brand", "Model" };
var query = new BooleanQuery();
var parser = new MultiFieldQueryParser(LuceneVersion.LUCENE_48, searchfields, analyzer);
string[] terms = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
foreach (string term in terms)
{
var q = parser.Parse(term.Replace("~", "") + "~0.8");
query.Add(q, Occur.MUST);
}
always produces a query like
+(Category:samsung~2 Brand:samsung~2 Model:samsung~2) +(Category:galaxy~2 Brand:galaxy~2 Model:galaxy~2) +(Category:s7~2 Brand:s7~2 Model:s7~2) +(Category:tablet~2 Brand:tablet~2 Model:tablet~2)
Any idea how can I set the sensitivity of the fuzzy query. Is there a better way to perform this type of search using Lucene?
Thank you!