Lucene 添加附加过滤器不返回任何结果

发布于 2024-09-10 05:17:40 字数 902 浏览 2 评论 0原文

我正在尝试使用布尔查询查询一些结果。但是该查询不会返回任何结果。

这是我正在运行的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悸初 2024-09-17 05:17:40

我从使用 TermQuery 更改为使用 QueryParser,这似乎解决了问题。

I changed from using a TermQuery, to using a QueryParser, which seems to have fixed the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文