How to search 2 fields for 2 different keywords? Lucene.net

时间:2015-07-28 17:01:00

标签: c# lucene lucene.net

How could i perform a search like this in Lucene.net?

Return all results where Title field equals "someTitle" and where isPrivate field equals "false"?

I guess that i could create 2 indexes, one with all documents and one with only the non-private ones. But it would be even better if it would be possible to do it with only 1 index.

1 个答案:

答案 0 :(得分:1)

您可以使用QueryParser's query syntax

轻松完成此操作
+Title:someTitle +isPrivate:false

或者通过在BooleanQuery中组合要搜索的两个术语:

BooleanQuery bq = new BooleanQuery();
bq.Add(new TermQuery(new Term("Title", "someTitle"), Occur.MUST);
bq.Add(new TermQuery(new Term("isPrivate", "false"), Occur.MUST);