使用 lucene 发出数据库中的每个文档

发布于 2025-01-05 01:49:07 字数 99 浏览 5 评论 0原文

我有一个索引,需要通过标准搜索获取所有文档,即使文档不受欢迎,仍然按相关性排名。

我的第一个想法是添加一个始终匹配的字段,但这可能会使相关性分数变形。

I've got an index where I need to get all documents with a standard search, still ranked by relevance, even if a document isn't a hit.

My first idea is to add a field that is always matched, but that might deform the relevance score.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

丘比特射中我 2025-01-12 01:49:07

使用 BooleanQuery 将原始查询与 MatchAllDocsQuery 组合起来。在将 MatchAllDocsQuery 与主查询结合之前,您可以通过将其提升设置为零来减轻这对评分的影响。这样您就不必向索引添加其他虚假字段。

例如:

// Parse a query by the user.
QueryParser qp = new QueryParser(Version.LUCENE_35, "text", new StandardAnalyzer());
Query standardQuery = qp.parse("User query may go here");

// Make a query that matches everything, but has no boost.
MatchAllDocsQuery matchAllDocsQuery = new MatchAllDocsQuery();
matchAllDocsQuery.setBoost(0f);

// Combine the queries.
BooleanQuery boolQuery = new BooleanQuery();
boolQuery.add(standardQuery, BooleanClause.Occur.SHOULD);
boolQuery.add(matchAllDocsQuery, BooleanClause.Occur.SHOULD);

// Now just pass it to the searcher.

这应该为您提供来自 standardQuery 的点击,然后是索引中其余文档的点击。

Use a BooleanQuery to combine your original query with a MatchAllDocsQuery. You can mitigate the effect this has on scoring by setting the boost on the MatchAllDocsQuery to zero before you combine it with your main query. This way you don't have to add an otherwise bogus field to the index.

For example:

// Parse a query by the user.
QueryParser qp = new QueryParser(Version.LUCENE_35, "text", new StandardAnalyzer());
Query standardQuery = qp.parse("User query may go here");

// Make a query that matches everything, but has no boost.
MatchAllDocsQuery matchAllDocsQuery = new MatchAllDocsQuery();
matchAllDocsQuery.setBoost(0f);

// Combine the queries.
BooleanQuery boolQuery = new BooleanQuery();
boolQuery.add(standardQuery, BooleanClause.Occur.SHOULD);
boolQuery.add(matchAllDocsQuery, BooleanClause.Occur.SHOULD);

// Now just pass it to the searcher.

This should give you hits from standardQuery followed by the rest of the documents in the index.

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