Native Lucene Query not working in Hibernate Search 7.2.1

Hello, We are working on migrating our application to hibernate 6 and we’ve been testing various scenarios. One such case is using native lucene query using LuceneExtension. But the native lucene query isn’t returning any results. Whereas the same predicate returns the correct results if used with hibernate 6 search predicate.

Below is the query that we are using

SearchResult<List<?>> result =
                searchSession
                        .search(getDomainClass())
                        .extension(LuceneExtension.get())
                        .select(projections.toArray( SearchProjection[]::new ))
                        .where(f -> f.fromLuceneQuery(luceneQuery))
                        .fetchAll();

The query string is “+_hibernate_class:com.rbs.ebpm.mireporting.common.service.clientdomain.XxxRequest +status:claimed”

The same query returns the correct results if used as below

SearchResult<List<?>> result =
                searchSession
                        .search(getDomainClass())
                        .select(projections.toArray( SearchProjection[]::new ))
                        .where(f -> f.match().field("status").matching("claimed"))
                        .fetchAll();

We are using the latest lucene version 9.11.1. Can you please help on this? whether we are using the query in correct format.

Hi,

I’d encourage you to look at simpleQueryString and queryString predicates if you need to work with string queries.

If those do not cover your needs in functionality and you have some custom Lucene queries and must use those then make sure you do not rely on internal fields as those may change, like they did here:

_hibernate_class isn’t there. “type filtering” would already happen for you when you defined the query scope:

Removing that first must clause should provide you with the same results.

Thanks for the quick response. Yes removing the entity class in query string worked. My bad! And yeah we plan to retain native lucene queries for now as there are some complex custom queries.