在 lucene.net 中排序 [英] Sorting in lucene.net

查看:19
本文介绍了在 lucene.net 中排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 lucene 索引中有一个需要排序的字段.我有我的查询,我可以创建我的 Sort 对象.如果我从 javadoc 中理解正确,我应该能够执行 query.SetSort().但是好像没有这样的方法……

I got my lucene index with a field that needs to be sorted on. I have my query and I can make my Sort object. If I understand right from the javadoc I should be able to do query.SetSort(). But there seems to be no such method...

当然,我错过了一些重要的东西.有什么建议吗?

Sure I'm missing something vital. Any suggestions?

推荐答案

其实有两点很重要.首先,该字段必须被索引.其次,将 Sort 对象传递给重载的 search 方法.

There are actually two important points. First, the field must be indexed. Second, pass the Sort object into the overloaded search method.

上次我查看时,文档并没有很好地指出索引部分,当然也没有解释为什么会这样.花了一些时间来找出原因.

Last time I looked, the docs didn't do a very good job of pointing out the indexing part, and certainly didn't explain why this is so. It took some digging to find out why.

当一个字段是可排序的时,搜索器会为索引中的每个文档创建一个包含一个元素的数组.它使用术语索引中的信息来填充这个数组,以便它可以非常快速地执行排序.如果你有很多文档,它会占用很多内存,所以除非有需要,否则不要让字段可排序.

When a field is sortable, the searcher creates an array with one element for each document in the index. It uses information from the term index to populate this array so that it can perform sorting very quickly. If you have a lot of documents, it can use a lot of memory, so don't make a field sortable unless there is a need.

还有一点需要注意:可排序字段的每个字段中存储的值不得超过一个.如果有多个值,Lucene 不知道使用哪个作为排序键.

One more caveat: a sortable field must have no more than one value stored in each field. If there are multiple values, Lucene doesn't know which to use as the sort key.

这篇关于在 lucene.net 中排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆