在 Lucene 搜索结果中查找项目位置的最佳方法
我正在使用 Lucene.NET,并且能够搜索并获得 ScoreDoc[] 形式的命中结果。
我需要知道 ScoreDoc[] 中的具体项目位置。 ScoreDoc[] 中的所有项目都是唯一的。
示例代码: luceneSearcher.Search(查询,收集器); ScoreDoc[] Scores = Collector.TopDocs().scoreDocs
例如,我需要在 ScoreDoc[] 中查找项目位置,它具有自定义 ID 属性,其中值可以是“99999”。
我可以迭代 Scores[] 中的项目并检查与“99999”匹配的 ID 属性,然后返回位置,但这可能会影响性能,因为 Scores[] 可以包含数千个项目。
有没有更好的技术?
谢谢
I am using Lucene.NET and able to search get hit results as ScoreDoc[].
I need to know specific item position in ScoreDoc[]. All items in ScoreDoc[] are unique.
Sample code:
luceneSearcher.Search(query, collector);
ScoreDoc[] scores = collector.TopDocs().scoreDocs
For example, I need to get find item position in ScoreDoc[], which has custom ID property where value could be '99999'.
I can iterate through item in scores[] and check for ID property which matches '99999' then return the position, but this can have performance hit because scores[] can have thousands of items.
Is there any better technique?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了创建新的 ExtendedCollector 来存储 CollectedDocuments。
CollectedDocument 看起来像这样
每当您想要获得结果时,您都会这样做
您还可以使用按分数排序的文档
这可能不是最简单的解决方案,但它有效。如果有人有更好的解决方案,请发布,因为我也想知道。
I came up with creating new ExtendedCollector which stores CollectedDocuments.
CollectedDocument looks like this
Whenever you want to get results you would do
You can also get the documents ordered by score using
This might not be the easiest solution, but it works. If anyone has a better solution, please post it as I'd like to know that as well.