场景:使用hibernate search,先按某字段rank排序,然后按相关度即文档得分进行排序。
model:
@Indexed
@Entity
@Table(name="book")
public class Book{
@DocumentId(name="book_id")
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="book_id", nullable=false)
private int bookId;
@Field(name="rank",index=Index.UN_TOKENIZED,store=Store.YES)
@Column(name="rank")
private String rank;
...(省略get,set方法及其他属性)
}
SortField[] sortFields = new SortField[2];
sortFields[0] = new SortField(“rank",SortField.STRING,true);//参数true表示将排序的结果反转
sortFields[1] = new SortField(null,SortField.SCORE);
Sort sort = new Sort(sortFields);
注意几点:
1.想要先按name排序再按相关度排序的话,必须得加上store=Store.YES,否则无论如何也
达不到要求,不知是只在hibernate search中这样,还是单纯用lucene也是这样
2.若只设置了一个sortfield的话,即只有
new SortField(“name",SortField.STRING,true),则会先按这个字段排序,然后按document添加到索引中的顺序排列
3.new SortField()的第三个参数为true表示是natural order的逆顺序,默认为false《lucene in
action 2nd edition》中介绍:
The default sort direction for sort fields (including relevance and document ID) is natural
ordering. Natural order is descending for relevance but increasing for all other
fields. The natural order can be reversed per Sort object by specifying true for the second
argument.
4.若Book类是嵌在其它类中时,注意在字段前加上"book.",即
sortFields[0] = new SortField(“book.name",SortField.STRING,true);
5.另参见http://lucene-group.group.iteye.com/group/topic/17748
分享到:
相关推荐
5.3.5. 改变SortField中的Locale信息 15 6. 过滤器 16 7. 分析器Analysis 16 7.1. 自带分析器和过滤器 16 7.2. 第三方过分析器 17 7.2.1. JE分词用法 17 8. 索引的合并 18 9. 各种Query 18 9.1. 概述 18 9.2. 使用...
由集合支持的带有React性可重列表: 到达集合中的新元素将按您期望的那样更新列表 从集合中删除的元素将从列表中... {{ #sortable items =< collection> sortField = " order " }} 服务器: Sortable . collections
使用属性items来指定可用选项使用selectize的选项指定要用作标签和值的模型属性 例子 <input type="text" selection="myModel" selectize="{valueField: 'id', labelField: 'name', sortField: 'name', ...
$TreeBuild->sortField = 'sort'; //排序字段 $TreeBuild->topId='0'; //设定顶级id的值 默认为0 $TreeBuild->id='id'; //设定id 字段名 $TreeBuild->pid='pid'; //设定父id 字段名 $TreeBuild->childrens ='...
-AuthorDto,pageNo,pageSize,sortField,sortDirection => CollectionDTO ОPOST / authors / {id} / update <-id,UpdateAuthorDto => AuthorDto或NotFoundException УдалениеPOST / authors / {id} ...
selectize.js 的插件为 selectize.js 创建的一些插件option_selected_remove 此插件将在...selected_on_top 此插件将动态地将选定的选项放在顶部注意:要使其工作,您必须设置sortField: '$order'而没有任何其他字段。
@connection ( name : " MarketProducts " , sortField : " createdAt " ) tags : [ String ] owner : String ! createdAt : String } type Product @model @auth ( rules : [{ allow : owner , identityField :...