use of org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory in project hibernate-search by hibernate.
the class NestedPredicateSpecificsIT method multiIndex_missingNestedField.
/**
* Test that no failure occurs when a nested predicate targets a nested field
* that only exists in one of the targeted indexes.
*/
@Test
@TestForIssue(jiraKey = "HSEARCH-4173")
public void multiIndex_missingNestedField() {
StubMappingScope scope = mainIndex.createScope(missingFieldIndex);
SearchPredicateFactory f = scope.predicate();
SearchPredicate nestedPredicate = f.nested("nestedObject").must(f.nested("nestedObject.nestedObject").must(f.match().field("nestedObject.nestedObject.field1").matching(MATCHING_SECOND_LEVEL_CONDITION1_FIELD1)).must(f.match().field("nestedObject.nestedObject.field2").matching(MATCHING_SECOND_LEVEL_CONDITION1_FIELD2))).must(f.nested("nestedObject.nestedObject").must(f.match().field("nestedObject.nestedObject.field1").matching(MATCHING_SECOND_LEVEL_CONDITION2_FIELD1)).must(f.match().field("nestedObject.nestedObject.field2").matching(MATCHING_SECOND_LEVEL_CONDITION2_FIELD2))).toPredicate();
// The "nested" predicate should not match anything in missingFieldIndex
assertThatQuery(mainIndex.createScope(missingFieldIndex).query().where(nestedPredicate)).hasDocRefHitsAnyOrder(mainIndex.typeName(), DOCUMENT_1).hasTotalHitCount(1);
// ... but it should not prevent the query from executing either:
// if the "nested" predicate is optional, it should be ignored for missingFieldIndex.
assertThatQuery(mainIndex.createScope(missingFieldIndex).query().where(f.bool().should(nestedPredicate).should(f.id().matching(MISSING_FIELD_INDEX_DOCUMENT_1)).toPredicate())).hasDocRefHitsAnyOrder(c -> c.doc(mainIndex.typeName(), DOCUMENT_1).doc(missingFieldIndex.typeName(), MISSING_FIELD_INDEX_DOCUMENT_1)).hasTotalHitCount(2);
}
use of org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory in project hibernate-search by hibernate.
the class AbstractPredicateInvalidFieldIT method unknownField.
@Test
public void unknownField() {
SearchPredicateFactory f = index.createScope().predicate();
assertThatThrownBy(() -> tryPredicate(f, "unknown_field")).isInstanceOf(SearchException.class).hasMessageContaining("Unknown field").hasMessageContaining("'unknown_field'");
}
use of org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory in project hibernate-search by hibernate.
the class AbstractPredicateInvalidFieldIT method objectField_nested.
@Test
public void objectField_nested() {
SearchPredicateFactory f = index.createScope().predicate();
String fieldPath = index.binding().nested.relativeFieldName;
assertThatThrownBy(() -> tryPredicate(f, fieldPath)).isInstanceOf(SearchException.class).hasMessageContaining("Cannot use '" + predicateNameInErrorMessage() + "' on field '" + fieldPath + "'");
}
use of org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory in project hibernate-search by hibernate.
the class AbstractPredicateSearchableIT method unsearchable.
@Test
public void unsearchable() {
SearchPredicateFactory f = searchableNoIndex.createScope().predicate();
String fieldPath = searchableNoIndex.binding().field.get(fieldType).relativeFieldName;
assertThatThrownBy(() -> tryPredicate(f, fieldPath)).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use '" + predicateNameInErrorMessage() + "' on field '" + fieldPath + "'", "Make sure the field is marked as searchable/sortable/projectable/aggregable (whichever is relevant)");
}
use of org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory in project hibernate-search by hibernate.
the class AbstractPredicateSearchableIT method multiIndex_incompatibleSearchable.
@Test
public void multiIndex_incompatibleSearchable() {
SearchPredicateFactory f = searchableYesIndex.createScope(searchableNoIndex).predicate();
String fieldPath = searchableYesIndex.binding().field.get(fieldType).relativeFieldName;
assertThatThrownBy(() -> tryPredicate(f, fieldPath)).isInstanceOf(SearchException.class).hasMessageContainingAll("Inconsistent configuration for field '" + fieldPath + "' in a search query across multiple indexes", "Inconsistent support for '" + predicateNameInErrorMessage() + "'");
}
Aggregations