-
Bug
-
Resolution: Done
-
Major
-
7.2.0.Final
-
None
When a HQL query that involves string comparison operation with the empty string matching is executed through hot rod client(java), it is resulting in the following error,
org.infinispan.client.hotrod.exceptions.HotRodClientException:Request for message id[7] returned server error (status=0x85): org.hibernate.search.exception.EmptyQueryException: HSEARCH000146: The query string '' applied on field 'CITY' has no meaningful tokens to be matched. Validate the query input against the Analyzer applied on this field.
The same problem may also occur when the string matching operation involves a string containing certain special keywords(hibernate search stop words), as operands.
The problem seems to be assosiated with the the 'hibernate-hql-lucene' parser used by the 'infinispan-remote-query-server' module. The problem here is that the hibernate-hql-lucene parser is translating comparison operations directly into lucene keyword matching operations, irrespective of the field type, though the phrase matching is more appropriate for string fields. This leads to invalid query formation when the field in concern is of type string, and is matched against an empty string(or a string containing one or more hibernate search stop words).
For example,
the where condition city='' present in the following HQL query
select name from com.test.User where city=''
is tralated to lucene query, the hql-lucene parser is currently translating to
queryBuilder.keyword().onField("city").matching("").createQuery()
whereas recommended one is
queryBuilder.phrase().onField("city").sentence("").createQuery()
In the former way of translation, Hibernate Search query execution fails due to its usage of standard analyzer while executing the query. Hence, the problem can also be avoided by disabling the standard analyzer while executing the query.
queryBuilder.keyword().onField("city").ignoreAnalyzer().matching("").createQuery()
Preferred solution may be to enhance the 'hibernate-hql-lucene' library to do type specific translations, and to specifically translate the string comparison operations of hql query into phrase matching operations of lucene query(instead of keyword matching operations).