Lucene.Net 2.4 中的随机排序结果
如何按随机顺序对结果进行排序。我的代码目前看起来像这样:
Dim searcher As IndexSearcher = New IndexSearcher(dir, True)
Dim collector As TopScoreDocCollector = TopScoreDocCollector.create(100, True)
searcher.Search(query, collector)
Dim hits() As ScoreDoc = collector.TopDocs.scoreDocs
For Each sDoc As ScoreDoc In hits
'get doc and return
Next
How do I sort my results in a random order. my code looks something like this at the moment:
Dim searcher As IndexSearcher = New IndexSearcher(dir, True)
Dim collector As TopScoreDocCollector = TopScoreDocCollector.create(100, True)
searcher.Search(query, collector)
Dim hits() As ScoreDoc = collector.TopDocs.scoreDocs
For Each sDoc As ScoreDoc In hits
'get doc and return
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于这是一个 IEnumerable,因此您可以使用标准 linq 对其进行随机化。您可以在此处找到一个示例:
如果您想在 Lucene 本身内部执行此操作,您可以可以制作自己的排序器 (尽管请注意,您将不再随机化前 100 个结果,而是随机化所有结果)。
Since this is an IEnumerable, you can use standard linq to randomize it. You can find an example here:
If you want to do this inside of Lucene itself, you can make your own sorter (although note that you will no longer be randomizing the top 100 results, but rather randomizing all results).