I've got Hibernate search set up and running and a search query based on two fields. One of those two fields is nullable, and I want to exclude it from the search result in case it is null (even when the other field matches).
I've read the Filter chapter (5.3) in the documentation a few times, but none of the examples comes even close to checking a field for null.
My attempt to work with Lucene directly to create a filter was rather futile.
Replacing the null-check with something else, that can be expressed with Lucene, would be fine, too. I just have no idea how to do that.
Here is my query code:
Code:
// transactions are handled by Spring
private SortedSet<Game> search(String searchFor) {
FullTextSession fullTextSession = Search.createFullTextSession(session());
MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{"config.title", "config.item.description"}, new StandardAnalyzer());
org.apache.lucene.search.Query luceneQuery;
try {
luceneQuery = parser.parse( searchFor );
} catch (ParseException e) {
throw new RuntimeException(e);
}
FullTextQuery query = fullTextSession.createFullTextQuery( luceneQuery, Game.class );
return toSet(query);
}
I want to exclude all results where config.item.description is null.
Thanks for any ideas or solutions.