使用多个术语时是否可以控制操作顺序?
例如,
Lucene.Net.Search.TermQuery tq1 = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("location", "seattle"));
Lucene.Net.Search.TermQuery tq2 = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("location", "portland"));
Lucene.Net.Search.TermQuery tq3 = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("location", "spokane"));
Lucene.Net.Search.TermQuery tq4 = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("type", "city"));
当我应用搜索时,假设我想应用上述术语来过滤我的搜索,让我们搜索食物......所以我的查询格式如下所示
食物 AND ((tq1 OR tq2 OR tq3) AND tq4)
目前我已经能够以以下格式构建它
{+xml:food +(location:seattle location:portland location:spokane +location:city)}
但是,我正在尝试以以下格式获取它
{+xml:food +(+(location:seattle location:portland location:spokane) +location:city)}
基本上,我所做的是这样的......
Lucene.Net.Search.BooleanQuery bq = new Lucene.Net.Search.BooleanQuery();
Lucene.Net.Search.BooleanQuery innerBQ = new Lucene.Net.Search.BooleanQuery();
bq.Add("xml:food", Lucene.Net.Search.BooleanClause.Occur.MUST);
foreach (Lucene.Net.Index.Term term in listOfTerms)
{
Lucene.Net.Search.TermQuery tq = new Lucene.Net.Search.TermQuery(term));
innerBQ.Add(tq, Lucene.Net.Search.BooleanClause.Occur.SHOULD);
}
innerBQ.Add("location:city", Lucene.Net.Search.BooleanClause.Occur.MUST);
bq.Add(innerBQ, Lucene.Net.Search.BooleanClause.Occur.MUST);
任何建议表示赞赏。