In Chapter 3, Performing Queries, we saw how to boost a field's relevance at index time, on either a fixed or a dynamic basis. It is also possible to dynamically change the weight at query time.
All query types in the Hibernate Search DSL include the
andField methods. For each query type, these two clauses also support a
boostedTo method, taking a
weight factor as a
float parameter. Whatever the index-time weight of that field might be, adding a
boostedTo clause multiplies it by the indicated number:
... luceneQuery = queryBuilder .phrase() .onField("name").boostedTo(2) .andField("description").boostedTo(2) .andField("supportedDevices.name") .andField("customerReviews.comments") .sentence(unquotedSearchString) .createQuery(); ...