Let say we have following entity {code:java} @Entity @Indexed public class YourAnnotatedEntity {
@Id @DocumentId private Long id;
@Field private String firstName;
@Field private String lastName; {code} Query constructed in following way
{code:java} Query query = qb.bool() .must( qb.bool() .must( new TermQuery(new Term("id", "1"))) .createQuery()) .filteredBy(qb.bool() .should(new TermQuery(new Term("firstName", "nonexisting"))) .must(new TermQuery(new Term("lastName", "jaric"))) .createQuery() ) .createQuery(); {code}
for given data set:
{code:java} YourAnnotatedEntity yourEntity = new YourAnnotatedEntity( 1L, "goran", "jaric" ); {code}
returns different results (0 documents) if hibernate.search.default.indexmanager=elasticsearch and different result (1 document) if hibernate.search.default.indexmanager=directory-based
If you use *HSEARCH-3534_lucene.patch* against https://github.com/hibernate/hibernate-test-case-templates/tree/master/search/hibernate-search-lucene, noneOfShouldMatchedWithinBooleanQueryInsideFilter_differentResults_directoryBasedVSElasticsearch test will pass, but when you use *HSEARCH-3534_elasticsearch.patch* against https://github.com/hibernate/hibernate-test-case-templates/tree/master/search/hibernate-search-elasticsearch/hibernate-search-elasticsearch-5 the same test will fail.
Maybe using *should* and *must* in *filters* like siblings does not make much sense, because *should* (in *directory-based*) clause will be ignored, because document *must* fulfill must criterias and therefor *should* is ignored, and makes more sense in queries while scoring the search, however I ran into the issue while migrating huge project where such cases appear time to time, due to dynamic queries creation. |
|