开发者

Lucene.Net PrefixQuery

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( di开发者_JAVA技巧r,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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜