Search in sources :

Example 1 with IndexSchemaObjectField

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField in project hibernate-search by hibernate.

the class ElasticsearchIndexSchemaManagerValidationMappingBaseIT method nestedProperty_attribute_invalid.

/**
 * Tests that properties within properties are correctly represented in the failure report.
 */
@Test
public void nestedProperty_attribute_invalid() {
    StubMappedIndex index = StubMappedIndex.ofNonRetrievable(root -> {
        IndexSchemaObjectField objectField = root.objectField("myObjectField");
        objectField.field("myField", f -> f.asLocalDate()).toReference();
        objectField.toReference();
    });
    elasticSearchClient.index(index.name()).deleteAndCreate();
    elasticSearchClient.index(index.name()).type().putMapping(simpleMappingForInitialization("'myObjectField': {" + "'type': 'object'," + "'dynamic': 'strict'," + "'properties': {" + "'myField': {" + "'type': 'date'," + "'format': '" + elasticSearchClient.getDialect().getConcatenatedLocalDateDefaultMappingFormats() + "'," + "'index': false" + "}" + "}" + "}"));
    setupAndValidateExpectingFailure(index, hasValidationFailureReport().indexFieldContext("myObjectField.myField").mappingAttributeContext("index").failure("Invalid value. Expected 'true', actual is 'false'"));
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) ElasticsearchAnalysisConfigurationContext(org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurationContext) Futures(org.hibernate.search.util.common.impl.Futures) ElasticsearchIndexSchemaManagerTestUtils.hasValidationFailureReport(org.hibernate.search.integrationtest.backend.elasticsearch.schema.management.ElasticsearchIndexSchemaManagerTestUtils.hasValidationFailureReport) StubMappingSchemaManagementStrategy(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingSchemaManagementStrategy) RunWith(org.junit.runner.RunWith) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) PortedFromSearch5(org.hibernate.search.util.impl.test.annotation.PortedFromSearch5) Test(org.junit.Test) ElasticsearchAnalysisConfigurer(org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) StubMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappedIndex) FailureReportChecker(org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportChecker) ElasticsearchExtension(org.hibernate.search.backend.elasticsearch.ElasticsearchExtension) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ElasticsearchIndexSchemaManagerTestUtils.simpleMappingForInitialization(org.hibernate.search.integrationtest.backend.elasticsearch.schema.management.ElasticsearchIndexSchemaManagerTestUtils.simpleMappingForInitialization) ElasticsearchIndexSchemaManagerTestUtils.defaultMetadataMappingAndCommaForInitialization(org.hibernate.search.integrationtest.backend.elasticsearch.schema.management.ElasticsearchIndexSchemaManagerTestUtils.defaultMetadataMappingAndCommaForInitialization) Assume.assumeTrue(org.junit.Assume.assumeTrue) EnumSet(java.util.EnumSet) Parameterized(org.junit.runners.Parameterized) ElasticsearchIndexSettings(org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchIndexSettings) TestElasticsearchClient(org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.rule.TestElasticsearchClient) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) StubMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappedIndex) Test(org.junit.Test)

Example 2 with IndexSchemaObjectField

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField in project hibernate-search by hibernate.

the class InvoiceLineItemsDetailBinder method bind.

// tag::bind[]
@Override
public void bind(PropertyBindingContext context) {
    context.dependencies().use("category").use("amount");
    // tag::bind[]
    IndexSchemaElement schemaElement = context.indexSchemaElement();
    IndexSchemaObjectField lineItemsField = // <1>
    schemaElement.objectField(// <2>
    "lineItems", // <3>
    ObjectStructure.NESTED).multiValued();
    context.bridge(List.class, new Bridge(// <5>
    lineItemsField.toReference(), // <6>
    lineItemsField.field("category", f -> f.asString()).toReference(), // <7>
    lineItemsField.field("amount", f -> f.asBigDecimal().decimalScale(2)).toReference()));
}
Also used : BigDecimal(java.math.BigDecimal) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) PropertyBridge(org.hibernate.search.mapper.pojo.bridge.PropertyBridge) PropertyBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.PropertyBindingContext) PropertyBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.PropertyBinder) PropertyBridgeWriteContext(org.hibernate.search.mapper.pojo.bridge.runtime.PropertyBridgeWriteContext) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) PropertyBridge(org.hibernate.search.mapper.pojo.bridge.PropertyBridge)

Example 3 with IndexSchemaObjectField

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField in project hibernate-search by hibernate.

the class UserMetadataBinder method bind.

@Override
public void bind(PropertyBindingContext context) {
    context.dependencies().useRootOnly();
    // tag::bind[]
    IndexSchemaElement schemaElement = context.indexSchemaElement();
    IndexSchemaObjectField userMetadataField = // <1>
    schemaElement.objectField("userMetadata");
    // <2>
    userMetadataField.fieldTemplate(// <3>
    "userMetadataValueTemplate", // <4>
    f -> f.asString().analyzer("english"));
    // <5>
    // <6>
    context.bridge(Map.class, new UserMetadataBridge(userMetadataField.toReference()));
}
Also used : IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)

Example 4 with IndexSchemaObjectField

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField in project hibernate-search by hibernate.

the class IndexSchemaElementImpl method objectField.

@Override
public IndexSchemaObjectField objectField(String relativeFieldName, ObjectStructure structure) {
    checkRelativeFieldName(relativeFieldName);
    IndexSchemaObjectField objectField = nestingContext.nest(relativeFieldName, (prefixedName, inclusion, nestedNestingContext) -> {
        IndexObjectFieldBuilder objectFieldBuilder = this.objectNodeBuilder.addObjectField(prefixedName, inclusion, structure);
        return new IndexSchemaObjectFieldImpl(typeFactory, objectFieldBuilder, nestedNestingContext, false);
    });
    if (directChildrenAreMultiValuedByDefault) {
        objectField.multiValued();
    }
    return objectField;
}
Also used : IndexObjectFieldBuilder(org.hibernate.search.engine.backend.document.model.dsl.spi.IndexObjectFieldBuilder) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)

Example 5 with IndexSchemaObjectField

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField in project hibernate-search by hibernate.

the class PropertyBridgeBaseIT method objectField.

/**
 * Test that object field definitions are forwarded to the backend.
 */
@Test
@TestForIssue(jiraKey = "HSEARCH-3324")
public void objectField() {
    class Contained {
    }
    @Indexed(index = INDEX_NAME)
    class IndexedEntity {

        @DocumentId
        Integer id;

        Contained contained;
    }
    backendMock.expectSchema(INDEX_NAME, b -> b.objectField("stringFromBridge", b2 -> b2.field("value", String.class)).objectField("listFromBridge", b2 -> b2.objectStructure(ObjectStructure.NESTED).multiValued(true).field("value", Integer.class)));
    SearchMapping mapping = setupHelper.start().withConfiguration(b -> b.programmaticMapping().type(IndexedEntity.class).property("contained").binder(context -> {
        context.dependencies().useRootOnly();
        // Single-valued field
        IndexSchemaObjectField stringObjectField = context.indexSchemaElement().objectField("stringFromBridge");
        stringObjectField.toReference();
        stringObjectField.field("value", f -> f.asString()).toReference();
        // Multi-valued field
        IndexSchemaObjectField listObjectField = context.indexSchemaElement().objectField("listFromBridge", ObjectStructure.NESTED).multiValued();
        listObjectField.toReference();
        listObjectField.field("value", f -> f.asInteger()).toReference();
        context.bridge(new UnusedPropertyBridge());
    })).setup(IndexedEntity.class);
    backendMock.verifyExpectationsMet();
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) CollectionElementExtractor(org.hibernate.search.mapper.pojo.extractor.builtin.impl.CollectionElementExtractor) PojoModelPath(org.hibernate.search.mapper.pojo.model.path.PojoModelPath) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) DocumentId(org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId) CustomPropertyMappingAnnotationBaseIT(org.hibernate.search.integrationtest.mapper.pojo.mapping.annotation.processing.CustomPropertyMappingAnnotationBaseIT) PropertyBridgeWriteContext(org.hibernate.search.mapper.pojo.bridge.runtime.PropertyBridgeWriteContext) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) BuiltinContainerExtractors(org.hibernate.search.mapper.pojo.extractor.builtin.BuiltinContainerExtractors) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ContainerExtractorPath(org.hibernate.search.mapper.pojo.extractor.mapping.programmatic.ContainerExtractorPath) PropertyBridge(org.hibernate.search.mapper.pojo.bridge.PropertyBridge) PropertyBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.PropertyBinder) PropertyBinding(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyBinding) FailureReportUtils(org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportUtils) NamedPredicateProvider(org.hibernate.search.engine.search.predicate.factories.NamedPredicateProvider) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) AssociationInverseSide(org.hibernate.search.mapper.pojo.mapping.definition.annotation.AssociationInverseSide) AssertionFailure(org.hibernate.search.util.common.AssertionFailure) MethodHandles(java.lang.invoke.MethodHandles) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) PojoElementAccessor(org.hibernate.search.mapper.pojo.model.PojoElementAccessor) Test(org.junit.Test) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Rule(org.junit.Rule) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) PropertyBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.PropertyBindingContext) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) PropertyBinderRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.PropertyBinderRef) ObjectPath(org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) Test(org.junit.Test) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue)

Aggregations

IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)15 PropertyBridge (org.hibernate.search.mapper.pojo.bridge.PropertyBridge)8 BigDecimal (java.math.BigDecimal)6 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)4 IndexFieldReference (org.hibernate.search.engine.backend.document.IndexFieldReference)4 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)4 ObjectStructure (org.hibernate.search.engine.backend.types.ObjectStructure)4 Rule (org.junit.Rule)4 Test (org.junit.Test)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)3 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)3 PropertyBindingContext (org.hibernate.search.mapper.pojo.bridge.binding.PropertyBindingContext)3 PropertyBinder (org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.PropertyBinder)3 PropertyBridgeWriteContext (org.hibernate.search.mapper.pojo.bridge.runtime.PropertyBridgeWriteContext)3 MethodHandles (java.lang.invoke.MethodHandles)2 EnumSet (java.util.EnumSet)2 List (java.util.List)2 ElasticsearchAnalysisConfigurationContext (org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurationContext)2 ElasticsearchAnalysisConfigurer (org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer)2 ElasticsearchIndexSettings (org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchIndexSettings)2