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

查看:172
本文介绍了在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天全站免登陆