[英]Get document scores within Hibernate Search
我們查詢多個索引但具有不同的字段名稱並將結果合並到全局搜索中。 要添加分頁,我想通過按分數對結果進行排序來使用分數並自己計算頁面。
我現在的問題是:如何獲得每個文檔的分數? 我看到我可以按分數排序,但不能按分數排序。
任何幫助都將不勝感激!
PS 我正在使用 Elasticsearch 后端和 hibernate 搜索 6.1.5
它在文檔中: score
projection 。
List<Float> hits = searchSession.search( Book.class )
.select( f -> f.score() )
.where( f -> f.match().field( "title" )
.matching( "robot dawn" ) )
.fetchHits( 20 );
如果你想要實體和分數,請同時使用score
投影和entity
投影,並將它們與composite
投影結合起來。
List<MyPair<Book, Float>> hits = searchSession.search( Book.class )
.select( f -> f.composite(
MyPair::new,
f.entity(),
f.score()
) )
.where( f -> f.matchAll() )
.fetchHits( 20 );
請注意,Hibernate Search 6.2(仍在開發中)將引入更明確的語法:
List<MyPair<Book, Float>> hits = searchSession.search( Book.class )
.select( f -> f.composite()
.from( f.entity(), f.score() )
.as( MyPair::new ) )
.where( f -> f.matchAll() )
.fetchHits( 20 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.