1
//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);

结果排序不正确,为什么?我正在使用 Lucene4.0

4

1 回答 1

1

LongDocValuesField在本质上与LongField有所不同。

看起来(根据: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);
于 2012-12-19T19:58:30.817 回答