How to sort IntPont or LongPoint field in Lucene 6

岁酱吖の 提交于 2019-12-21 06:55:09

问题


Hi: I am migrating to Lucene 6 from Lucene 5.1. I found out that InPoint does not support sorting as its DocValuesType is frozen to NONE and sorting requires NUMERIC. In Lucene 5.1, I could set the field type of a newmeric field so I could do range based search and sort the result. I know I can migrate to LegacyIntField but I'd like migrate to the new IntPoint instead. Does any one know how to index a numeric value to support both range based query and sorting?

Thank you!


回答1:


You have to use additional SortedNumericDocValuesField

document.add(new SortedNumericDocValuesField("bid_sorter", bid));

and make sort based on it

searcher.search(query, hitsPerPage, new Sort(new SortField("bid_sorter", SortField.Type.SCORE, true)))



回答2:


You need to store the value in a NumericDocValuesField or its subclasses. doc.add(new NumericDocValuesField(field, 10));

Then search docs ranked by this field will be :

Sort sort = new Sort(new SortedNumericSortField(field, SortField.Type.INT, true)); TopDocs topDocs = indexsearcher.search(query, returnedDocNum, sort);



来源:https://stackoverflow.com/questions/38358087/how-to-sort-intpont-or-longpoint-field-in-lucene-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!