/** *//** * Sorts by computed relevance. This is the same sort criteria as calling * {@link Searcher#search(Query) Searcher#search()}without a sort criteria, * only with slightly more overhead. */ public Sort() ...{ this(new SortField[] ...{ SortField.FIELD_SCORE, SortField.FIELD_DOC }); }
/** *//** Creates a sort, possibly in reverse, by terms in the given field with the * type of term values explicitly given. * @param field Name of field to sort by. Can be <code>null</code> if * <code>type</code> is SCORE or DOC. * @param type Type of values in the terms. * @param reverse True if natural order should be reversed. */ public SortField (String field, int type, boolean reverse) ...{ this.field = (field !=null) ? field.intern() : field; this.type = type; this.reverse = reverse; }
由此可见,只要构造一个SortField[]就可以实现我们要的功能,请看:
// 评分降序,评分一样时后索引的排前面 new SortField[] ...{ SortField.FIELD_SCORE, new SortField(null, SortField.DOC, true) } // 评分升序,评分一样时后索引的排前面,呵呵,此为最不相关的排前面,挺有趣的 new SortField[] ...{ new SortField(null, SortField.SCORE, true), new SortField(null, SortField.DOC, true) }