The fields used to determine sort order must be carefully chosen.
选择排序字段一定要细心。
Documents must contain a single term in such a field, and the value of
the term should indicate the document's relative position in a given
sort order.
用于排序的字段在文档当中必须只能含有单一的term,并且这个term的值应该能够准确的准确的定位当前文档在排序中的位置
The field must be indexed, but should not be tokenized, and
does not need to be stored (unless you happen to want it back with the
rest of your document data).
这个字段必须被索引,但是不能被分词,并且不是必须存储的(除非你碰巧希望它返回你文档的剩余字段)
In other words: 也就是说:
document.add (new Field ("byNumber", Integer.toString(x), Field.Store.NO, Field.Index.NOT_ANALYZED));
If I want to sort some field (for example name is "TITLE") and It must be Analyzed.
Then Do I have to make two field that one is ANALYZED and the other is NOT_ANALYZED like this?
document.add(new Field("TITLE", value, Field.Store.NO. Field.Index.ANALYZED)
document.add(new Field("TITLE_FOR_SORT", value, Field.Store.NO, Field.Index.NOT_ANALYZED)
that is right!
sort构造方法:
Sort()
Sorts by computed relevance.通过计算相关性排序
Sort(SortField... fields)
Sorts in succession by the criteria in each SortField.按照多个字段排序
Sort(SortField field)
Sorts by the criteria in the given SortField.指定单个字段排序