5

we have creating lucene.net index and search based on this URL http://sonyblogpost.blogspot.in/. but we want the output like follow.

example: if i search "featured" i want to show related terms like "featured","featuring","feature".

Anyone can help me. thanks.

user2773170
  • 161
  • 3
  • 10

2 Answers2

7

To perform a Fuzzy search you'll create a MultiFieldQueryParser Below is an example on how to do this:

var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, new[] { "field1", "field2" }, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));

Your version of Lucene.Net may vary.

Next you will get a Fuzzy query from the parser like this:

var query = parser.GetFuzzyQuery("fieldName", "featured", 0.7f);

The float value of 0.7f is the minimum similarity. You can tweak this number until you get the desired results. The number cannot be more than 1.0f. Executing this query using an Lucene Searcher will give you the results you expect.

jvanrhyn
  • 2,804
  • 19
  • 14
  • i have already added the MultiFueldQueryParser... but where should i add the "var query = parser.GetFuzzyQuery("fieldName", "featured", 0.7f);". the followings are the my search and query..... public BooleanQuery QueryMaker(string searchString, string[] searchfields) { var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, searchfields, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)); var finalQuery = new BooleanQuery(); string searchText; searchText = searchString.Replace("+", ""); – user2773170 Sep 18 '13 at 05:14
  • After you have created the MultiFieldQueryParser. You will then add the query to your finalQuery like this finalQuery.Add(query, BooleanClause.Occur.SHOULD); – jvanrhyn Sep 18 '13 at 05:41
  • hi i added these. but not occur any fuzzy search.. my code is below. var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, searchfields, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)); var finalQuery = new BooleanQuery(); var query = parser.GetFuzzyQuery("ContentText", searchString, 0.7f); // ContentText is column name. searchString is input string. finalQuery.Add(query, BooleanClause.Occur.SHOULD); – user2773170 Sep 18 '13 at 07:08
  • this is my final answer. Query query = new FuzzyQuery(new Term("ContentText", searchString)); finalQuery.Add(query, BooleanClause.Occur.SHOULD); – user2773170 Sep 24 '13 at 10:04
0

You're probably looking for stemming: Stemming English words with Lucene - The link is Java, but you should be able to identify the corresponding parts of the lucene .Net API.

Community
  • 1
  • 1
penguat
  • 1,337
  • 1
  • 13
  • 25