开发者

field cross search in lucene

开发者 https://www.devze.com 2023-01-27 07:27 出处:网络
Hi: I have two documents: titlebody Lucene In ActionA high-performance, full-featured text search engine library.

Hi: I have two documents:

title                       body
Lucene In Action            A high-performance, full-featured text search engine library.
Lucene Practice             Use lucene in your application

Now,I search "lucene performance" using

private String[] f = { "title", "body"};
private Occur[] should = { Occur.SHOULD, Occur.SHOULD};
Query q = MultiFieldQueryParser.parse(Version.LUCENE_29, "lucene performance", f, should,new IKAnalyzer());

Then I get two hits: "Lucene In Action" and "Lucene Practice".

However I do not want the "Lucene practice" in the search result.

That's to say,I just want the docume开发者_StackOverflownts who own all my search terms can be returned,the "lucene parctice" does not contain the term "performance",so it should not be returned.

Any ideas?


Lucene cannot match across fields. That is to say, for the query "a b", it won't match "a" in title and "b" in body. For that you need to create another field, say, all_text, which has title and body both indexed.

Also, when you are searching for "lucene performance" I suppose you are looking for documents that have both the terms - lucene as well as performance. By default, the boolean operator is OR. You need to specify default operator as AND to match all the terms in the query. (Otherwise in this case, the query "lucene performance" will start returning matches that talk about database performance.)

0

精彩评论

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