Hibernate Search 6

can I have any document for HS 6 regarding bool queries like we do in HS5
thnaks

We do have subjected class bool at run time and in final result we have conjunction of result in result list.
HS5 CODE for refrence .

QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(clazz).get()
BooleanJunction booleanJunction = queryBuilder.bool();

//multiple queries on the basis of request params to filter data and on the different classes
//1
Query query = queryBuilder.keyword().onField(field).ignoreFieldBridge().matching(fromValue).createQuery();
//2
Query query = queryBuilder.keyword().wildcard().onField(field).ignoreFieldBridge().matching(StringUtils.stripAccents(f
romValue.toLowerCase())).createQuery();
//3
Query query = queryBuilder.keyword().onField(field).ignoreFieldBridge().matching(Long.parseLong(fromValue)).createQuery();
//and many more
// And all the query will be added in search request using booleanJunction
booleanJunction.must(query);

Query query = booleanJunction.createQuery();

I’m not sure what you’re asking. The Search 6 API is different, but there definitely is support for boolean predicates.

See:

image

So what I was trying to do is in the generic search api client will invoke api; along with class information in query itself and in the last a boolean conjunction will be put in result.
i.e client will provide a array of 3 matching queries.
1: on BASE class object
2:on IMMEDIATE CHILD class object
3:on CHILD class object

and in the last when we are actually hitting HS that time we build the query on top of boolean junction like we did in HS 5
Query query = booleanJunction.createQuery();

You got What I mean??

I’m really not sure I did…

But anyway… If lambdas are what’s causing you trouble, there’s also an API similar to Hibernate Search 5 where you build one object per predicate. Instead of building a Query, you build a SearchPredicate. Then you can pass this object around and add it to a boolean predicate later.

SearchSession searchSession = Search.session( entityManager );

SearchScope<Book> scope = searchSession.scope( Book.class );
SearchPredicateFactory factory = scope.predicate();

SearchPredicate predicate1 = factory.match().field(field)
        .matching(fromValue)
        .toPredicate();

SearchPredicate predicate2 = factory.wildcard().field(field)
        .matching(StringUtils.stripAccents(fromValue.toLowerCase()))
        .toPredicate();

SearchPredicate predicate3 = factory.match().field(field)
        .matching(Long.parseLong(fromValue))
        .toPredicate();

BooleanPredicateClausesStep<?> booleanJunction = factory.bool();
booleanJunction.must( predicate1 );
booleanJunction.must( predicate2 );
booleanJunction.must( predicate3 );
SearchPredicate boolPredicate = booleanJunction.toPredicate();

List<Book> result = searchSession.search( scope )
        .where( boolPredicate )
        .fetchHits( 20 );

See the second example here; it’s the same idea for all predicates.

If this does not address your problem, please give an example of code in Hibernate Search 5, then what you ended up with in Hibernate Search 6, and explain what is wrong in the code for Hibernate Search 6.

1 Like

@yrodiere can u please provide any link possible to accommodate the range query in here specially for Date range and long range queries

Please refer to the documentation: https://docs.jboss.org/hibernate/search/6.0/reference/en-US/html_single/#search-dsl-predicate-range