| Correction: actually, due to how this is implemented, you need to call onField() for the first element only, then call andField for the others. You would do it naturally if you used the fluent API with hard-coded field names, but since you're translating values from your list of IndexedField, it's a bit more difficult. Something like this:
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
QueryBuilder builder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(IndexedEntity.class).get();
TermContext ctx = builder.keyword();
TermMatchingContext matchingContext = null;
for(IndexedField field : indexedFields){
if ( matchingContext == null ) {
matchingContext = ctx.onField(field.getName()).boostedTo(field.getBoost());
}
else {
matchingContext = ctx.andField(field.getName()).boostedTo(field.getBoost());
}
}
|