我正在尝试为 Lucene 创建一个查询以进行如下搜索
word:"searched_word" AND (category:0 OR category:1)
什么意思 searched_word 必须在 word 字段中,并且 category 字段是 0 或 1。
word字段是普通字段类型类别字段是NumericField类型
BooleanQuery mainQuery = new BooleanQuery();
Query query1 = new TermQuery(new Term("category", NumericUtils.IntToPrefixCoded(0)));
Query query2 = new TermQuery(new Term("category", NumericUtils.IntToPrefixCoded(1));
Query queryTerm= new TermQuery(new Term("word", searchedWord));
mainQuery.Add(queryTerm, BooleanClause.Occur.MUST);
BooleanQuery innerOrQuery = new BooleanQuery();
//How do i add them as OR and as AND to mainQuery
innerOrQuery.Add(querySingleDirection, BooleanClause.Occur.MUST);
innerOrQuery.Add(queryBothDirection, BooleanClause.Occur.MUST);
mainQuery.Add(innerOrQuery, BooleanClause.Occur.MUST);
TopDocs topDocs = _indexSearcher.Search(mainQuery, Settings.Current.MaximumTopScoreCount);