Search in sleep mode

Search in sleep mode sorts the results according to relevance, this is normal. In addition to this, if two documents have the same score, they are sorted by their main keys.

For example,

book1: id = 1, booktitle = "sleeping search by example".

book2: id = 2, booktitle = "sleep search in action"

If I execute a query to search for the terms "sleeping search", I will have this order: book1 then book2

I would like to invert this order: book2 then book1. This means inverting the order of the primary key. Is there a way to do this without implementing user affinity? At the same time, compliance with the order of compliance.

+7
hibernate hibernate-search lucene
source share
1 answer

Yes, you need to create a Sort object that sets the required sort and sets it in your request. See section 5.1.3.3 of the Hibernate docs . Then in the SortFields list SortFields go SortField.FIELD_SCORE . The SortField constructor also allows you to reorder.

 org.hibernate.search.FullTextQuery query = s.createFullTextQuery( luceneQuery, MyEntity.class ); org.apache.lucene.search.Sort sort = new Sort( SortField.FIELD_SCORE, new SortField("id", SortField.STRING, true)); query.setSort(sort); List results = query.list(); 
+8
source share

All Articles