简体   繁体   English

如何在Lucene中按长字段排序

[英]How to Sort by Long field in Lucene

//create
Document doc = new Document();
//get value from JDBC ResultSet
doc.add(new LongDocValuesField("LastContactTime", rs.getLong("LastContactTime")));
//....
//Search
Sort sort = new Sort(new SortField("LastContactTime",
                    SortField.Type.LONG, false));
TopDocs rs = scher.search(query, total, sort);

The results are not sorted correctly,Why? 结果排序不正确,为什么? I'm using Lucene4.0 我正在使用Lucene4.0

LongDocValuesField is somewhat different in nature from a LongField . LongDocValuesField本质上与LongField有所不同。

It looks like (according to: http://www.searchworkings.org/blog/-/blogs/377217 ) you may be able to sort on them simply by calling setUseIndexValues, like: 看起来(根据: http : //www.searchworkings.org/blog/-/blogs/377217 ),您可以简单地通过调用setUseIndexValues对它们进行排序,例如:

SortField field = new SortField("LastContactTime",
                SortField.Type.LONG, false);
field.setUseIndexValues(true);
Sort sort = new Sort(sort);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM