One of the ways I thought to get around this was to split up the query and loop over the terms and add them as a keyword query
Code:
QueryBuilder qb = fts.getSearchFactory().buildQueryBuilder()
.forEntity(Tag.class)
.overridesForField("tag_kw_" + languageCode, "qryAutocompleteAnalyzer")
.get();
for(String key: qry.split(" ")){
qb.keyword().onField("tag_kw_" + languageCode).ignoreFieldBridge().matching(key).createQuery();
}
However, this leads to an exception being thrown when a stopword is being used (filtered out by the queryAnalyzer).
E.g. Surgery of the hand
Code:
org.hibernate.search.errors.EmptyQueryException: HSEARCH000146: The query string 'of' applied on field 'tag_kw_pt' has no meaningfull tokens to be matched. Validate the query input against the Analyzer applied on this field.
at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:111)
at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsTermQueryBuilder.createQuery(ConnectedMultiFieldsTermQueryBuilder.java:81)
This seems a bit strange. Both the query and runtime analyzer filter out stopwords so I would expect any resulting "empty query term" to just lead to it being ignored with a warning in stead of an exception being thrown.
In any case, is there a utility that I might use to get a on-the-fly list of terms against a text and analyzer I provide?