Search in sources :

Example 1 with SearchPredicateFactory

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);
}
Also used : SearchPredicateFactory(org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory) SearchException(org.hibernate.search.util.common.SearchException) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) BeforeClass(org.junit.BeforeClass) SearchPredicateFactory(org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) Test(org.junit.Test) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BulkIndexer(org.hibernate.search.util.impl.integrationtest.mapper.stub.BulkIndexer) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ClassRule(org.junit.ClassRule) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) Test(org.junit.Test) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue)

Example 2 with SearchPredicateFactory

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'");
}
Also used : SearchPredicateFactory(org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory) Test(org.junit.Test)

Example 3 with SearchPredicateFactory

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 + "'");
}
Also used : SearchPredicateFactory(org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory) SearchException(org.hibernate.search.util.common.SearchException) Test(org.junit.Test)

Example 4 with SearchPredicateFactory

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)");
}
Also used : SearchPredicateFactory(org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory) SearchException(org.hibernate.search.util.common.SearchException) Test(org.junit.Test)

Example 5 with SearchPredicateFactory

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() + "'");
}
Also used : SearchPredicateFactory(org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory) SearchException(org.hibernate.search.util.common.SearchException) Test(org.junit.Test)

Aggregations

SearchPredicateFactory (org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory)41 Test (org.junit.Test)35 SearchException (org.hibernate.search.util.common.SearchException)11 SearchPredicate (org.hibernate.search.engine.search.predicate.SearchPredicate)9 InvalidType (org.hibernate.search.integrationtest.backend.tck.testsupport.util.InvalidType)6 IndexFieldReference (org.hibernate.search.engine.backend.document.IndexFieldReference)3 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)3 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)3 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)3 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)3 BeforeClass (org.junit.BeforeClass)3 ClassRule (org.junit.ClassRule)3 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)2 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)2 IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)2 ObjectStructure (org.hibernate.search.engine.backend.types.ObjectStructure)2 BulkIndexer (org.hibernate.search.util.impl.integrationtest.mapper.stub.BulkIndexer)2 StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)2 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)2