Reputation: 13
I´m development a suggest box for my site search service. I has to search fields like these:
Visual Basic Enterprise Edition
Visual C++
Visual J++
My code is:
Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory("Index", false);
IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher( dir,true);
Term term = new Term("nombreAnalizado", _que);
PrefixQuery query = new PrefixQuery(term);
TopDocs topDocs = searcher.Search(query, 10000);
This code works well in this case:
"Enterprise" will match "Visual Basic Enterprise Edition"
But "Enterprise E" doesn´t match anything.
I removed white spaces at indexing time and when the user is searching.
Thanks.
Upvotes: 1
Views: 1239
Reputation: 6928
I think you should use the QueryParser and let it build the appropriate Query object instead of using something specific like the PrefixQuery.
In Java:
QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, "nombreAnalizado", new StandardAnalyzer(Version.LUCENE_CURRENT));
Query query = parser.parse(_que);
Make sure you are using the same analyzer that you used for indexing.
Upvotes: 2