NullPointerException when using simpleQueryString() on non-analyzed, non-normalized fields

Description

When use:

if (searchFullText != null) {
select = scope.predicate().simpleQueryString()
.field("shoppingName")
.matching(searchFullText)
.defaultOperator(BooleanOperator.AND);
} else {
select = scope.predicate().matchAll();
}

SearchQuery<Assortment> query = session.search(scope)
.where((f) -> select)
.sort(sort.toSort()).toQuery();

I have an exception only for simpleQueryString, for matchAll it's fine.

Exception: null: java.lang.NullPointerException
at org.apache.lucene.util.QueryBuilder.createFieldQuery(QueryBuilder.java:239)
at org.apache.lucene.util.QueryBuilder.createBooleanQuery(QueryBuilder.java:96)
at org.hibernate.search.backend.lucene.lowlevel.query.impl.FieldContextSimpleQueryParser.newDefaultQuery(FieldContextSimpleQueryParser.java:50)
at org.apache.lucene.queryparser.simple.SimpleQueryParser.consumeToken(SimpleQueryParser.java:415)
at org.apache.lucene.queryparser.simple.SimpleQueryParser.parseSubQuery(SimpleQueryParser.java:216)
at org.apache.lucene.queryparser.simple.SimpleQueryParser.parse(SimpleQueryParser.java:156)
at org.hibernate.search.backend.lucene.search.predicate.impl.LuceneSimpleQueryStringPredicateBuilder.doBuild(LuceneSimpleQueryStringPredicateBuilder.java:107)
at org.hibernate.search.backend.lucene.search.predicate.impl.AbstractLuceneSearchPredicateBuilder.build(AbstractLuceneSearchPredicateBuilder.java:40)

Environment

wildflay

Activity

Show:
Yoann Rodière
February 27, 2020, 4:56 PM
Edited

You are mixing two approaches here, which may be the reason you're getting this exception (though maybe not).

*Step objects, like the one you're storing in the "select" and "sort" variables, are not meant to be passed around at all. For that, you should call toPredicate()/toSort() etc. and then you will get a SearchPredicate/SearchSort/etc. that you can safely pass around and even re-use.

Try this:

or this:

Yoann Rodière
February 27, 2020, 5:02 PM

Alright, fixing your code won't solve the issue. I found the culprit; I'll send a PR.

Yoann Rodière
February 27, 2020, 5:47 PM

The fix is ready, it'll be part of the next release.

In the meantime, you can work around the problem by setting an analyzer or normalizer on your field using @KeywordField(normalizer = ...) or @FullTextField(analyzer = ...). Which is something you'll want to do anyway to take advantage of full-text capabilities.

See here for more information about analysis, here for more information about property/field mapping. In particular, here is how to define your analyzers/normalizers with the Lucene backend.

Waldemar Kłaczyński
February 27, 2020, 7:01 PM

Maybe if not defined, assign StandardAnalyzer ()?

Waldemar Kłaczyński
February 27, 2020, 7:57 PM

The solution seems to work. If there is no analyzer, it assigns the default analyzer to the field.


 

Assignee

Yoann Rodière

Reporter

Waldemar Kłaczyński

Labels

None

Suitable for new contributors

None

Feedback Requested

None

Components

Fix versions

Affects versions

Priority

Major
Configure