Lucene 添加附加过滤器不返回任何结果
我正在尝试使用布尔查询查询一些结果。但是该查询不会返回任何结果。
这是我正在运行的 FilterQuery。即使字段 foo 包含 bar,并且字段 foo3 包含 bar3,这也不会返回任何结果。我已经对我的字段进行了三次检查,以确保这些字段确实存在于索引中。
+(foo:bar foo2:bar2) +foo3:bar3
现在,如果我从查询中删除 +foo3:bar3,我会正确返回结果。另外 foo3:bar3 是以编程方式添加的,所以我不解析它。这是一些相关代码
//This code creates the first part of the query.
MultiFieldQueryParser mfqp = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29,SearchFields, analyzer);
Query q = mfqp.Parse(query);
BooleanQuery filterquery = new BooleanQuery();
filterquery.Add(q,BooleanClause.Occur.MUST);
//This code creates the second part of the query
Query fq = new TermQuery(new Term("foo3","bar3"));
filterquery.Add(fq, BooleanClause.Occur.MUST);
//Perform the search
ScoreDoc[] hits = isearch.Search(filterquery, null, ResultsToReturn).scoreDocs;
仅供参考,我当前正在设置要分析的字段,并将向量设置为With_positions_offsets
I am attempting query some results using a Boolean Query. However the query does not return any results.
Here is the FilterQuery I am running. This returns no results, even though the field foo contains bar, and the field foo3 contains bar3. And I have triple checked my fields to make sure that the fields do exist in the index.
+(foo:bar foo2:bar2) +foo3:bar3
Now, If I remove the +foo3:bar3 from the query I get results back correctly. Also foo3:bar3 is being added programatically, so I am not parsing it. Here is some relevant code
//This code creates the first part of the query.
MultiFieldQueryParser mfqp = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29,SearchFields, analyzer);
Query q = mfqp.Parse(query);
BooleanQuery filterquery = new BooleanQuery();
filterquery.Add(q,BooleanClause.Occur.MUST);
//This code creates the second part of the query
Query fq = new TermQuery(new Term("foo3","bar3"));
filterquery.Add(fq, BooleanClause.Occur.MUST);
//Perform the search
ScoreDoc[] hits = isearch.Search(filterquery, null, ResultsToReturn).scoreDocs;
Just for reference, I am current setting the fields to be analyzed, and the vector is set to With_positions_offsets
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从使用 TermQuery 更改为使用 QueryParser,这似乎解决了问题。
I changed from using a TermQuery, to using a QueryParser, which seems to have fixed the issue.