Search in sources :

Example 1 with SearchMapping

use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.

the class IndexedEmbeddedBaseIT method multiValued.

/**
 * Check @IndexedEmbedded on a multi-valued property
 * results in the corresponding object field being automatically marked as multi-valued
 * (and not its own fields).
 */
@Test
@TestForIssue(jiraKey = "HSEARCH-3324")
public void multiValued() {
    class IndexedEmbeddedLevel1 {

        @GenericField
        String level1SingleValuedProperty;

        @GenericField
        List<String> level1MultiValuedProperty;
    }
    @Indexed(index = INDEX_NAME)
    class IndexedEntity {

        @DocumentId
        Integer id;

        @IndexedEmbedded
        List<IndexedEmbeddedLevel1> level1 = new ArrayList<>();
    }
    backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.multiValued(true).field("level1SingleValuedProperty", String.class).field("level1MultiValuedProperty", String.class, b3 -> b3.multiValued(true))));
    SearchMapping mapping = setupHelper.start().withAnnotatedEntityTypes(IndexedEntity.class).withAnnotatedTypes(IndexedEmbeddedLevel1.class).setup();
    backendMock.verifyExpectationsMet();
    doTestEmbeddedRuntime(mapping, id -> {
        IndexedEntity entity = new IndexedEntity();
        entity.id = id;
        IndexedEmbeddedLevel1 level1_1 = new IndexedEmbeddedLevel1();
        level1_1.level1SingleValuedProperty = "1";
        level1_1.level1MultiValuedProperty = Arrays.asList("1_1", "1_2");
        entity.level1.add(level1_1);
        IndexedEmbeddedLevel1 level1_2 = new IndexedEmbeddedLevel1();
        level1_2.level1SingleValuedProperty = "2";
        level1_2.level1MultiValuedProperty = Arrays.asList("2_1", "2_2");
        entity.level1.add(level1_2);
        return entity;
    }, document -> document.objectField("level1", b2 -> b2.field("level1SingleValuedProperty", "1").field("level1MultiValuedProperty", "1_1", "1_2")).objectField("level1", b2 -> b2.field("level1SingleValuedProperty", "2").field("level1MultiValuedProperty", "2_1", "2_2")));
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Arrays(java.util.Arrays) StartupStubBridge(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.StartupStubBridge) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DocumentId(org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) FailureReportUtils(org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportUtils) IdentifierBridgeRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBridgeRef) AssociationInverseSide(org.hibernate.search.mapper.pojo.mapping.definition.annotation.AssociationInverseSide) MethodHandles(java.lang.invoke.MethodHandles) ProgrammaticMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.ProgrammaticMappingSmokeIT) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) GeoPointBridge(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.GeoPointBridge) Optional(java.util.Optional) AnnotationMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.AnnotationMappingSmokeIT) Projectable(org.hibernate.search.engine.backend.types.Projectable) IdentifierBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.IdentifierBinder) CollectionHelper(org.hibernate.search.util.common.impl.CollectionHelper) LongitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LongitudeMarker) PojoModelPath(org.hibernate.search.mapper.pojo.model.path.PojoModelPath) Searchable(org.hibernate.search.engine.backend.types.Searchable) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) Param(org.hibernate.search.mapper.pojo.common.annotation.Param) LatitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LatitudeMarker) Function(java.util.function.Function) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) IdentifierBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.IdentifierBindingContext) StubDocumentNode(org.hibernate.search.util.impl.integrationtest.common.stub.backend.document.StubDocumentNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) IdentifierBinderRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBinderRef) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) StaticCounters(org.hibernate.search.util.impl.test.rule.StaticCounters) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) IdentifierBridge(org.hibernate.search.mapper.pojo.bridge.IdentifierBridge) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) IdentifierBridgeFromDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeFromDocumentIdentifierContext) IdentifierBridgeToDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeToDocumentIdentifierContext) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) Collections(java.util.Collections) ObjectPath(org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath) Assert.assertEquals(org.junit.Assert.assertEquals) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) List(java.util.List) ArrayList(java.util.ArrayList) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) Test(org.junit.Test) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue)

Example 2 with SearchMapping

use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.

the class IndexedEmbeddedBaseIT method includeDepth.

/**
 * Check that the "includeDepth" parameter is at least taken into account.
 * <p>
 * Details of how filtering handles all corner cases is tested in the engine (see this class' javadoc).
 */
@Test
public void includeDepth() {
    class IndexedEmbeddedLevel2 {

        String level2Property;

        @GenericField
        public String getLevel2Property() {
            return level2Property;
        }
    }
    class IndexedEmbeddedLevel1 {

        String level1Property;

        IndexedEmbeddedLevel2 level2;

        @GenericField
        public String getLevel1Property() {
            return level1Property;
        }

        @IndexedEmbedded
        public IndexedEmbeddedLevel2 getLevel2() {
            return level2;
        }
    }
    @Indexed(index = INDEX_NAME)
    class IndexedEntity {

        @DocumentId
        Integer id;

        @IndexedEmbedded(includeDepth = 1)
        IndexedEmbeddedLevel1 level1;

        public IndexedEntity(int id, String level1Value, String level2Value) {
            this.id = id;
            this.level1 = new IndexedEmbeddedLevel1();
            this.level1.level1Property = level1Value;
            this.level1.level2 = new IndexedEmbeddedLevel2();
            this.level1.level2.level2Property = level2Value;
        }
    }
    backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.field("level1Property", String.class)));
    SearchMapping mapping = setupHelper.start().withAnnotatedEntityTypes(IndexedEntity.class).withAnnotatedTypes(IndexedEmbeddedLevel1.class, IndexedEmbeddedLevel2.class).setup();
    backendMock.verifyExpectationsMet();
    doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, "level1Value", "level2Value"), document -> document.objectField("level1", b2 -> b2.field("level1Property", "level1Value")));
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Arrays(java.util.Arrays) StartupStubBridge(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.StartupStubBridge) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DocumentId(org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) FailureReportUtils(org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportUtils) IdentifierBridgeRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBridgeRef) AssociationInverseSide(org.hibernate.search.mapper.pojo.mapping.definition.annotation.AssociationInverseSide) MethodHandles(java.lang.invoke.MethodHandles) ProgrammaticMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.ProgrammaticMappingSmokeIT) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) GeoPointBridge(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.GeoPointBridge) Optional(java.util.Optional) AnnotationMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.AnnotationMappingSmokeIT) Projectable(org.hibernate.search.engine.backend.types.Projectable) IdentifierBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.IdentifierBinder) CollectionHelper(org.hibernate.search.util.common.impl.CollectionHelper) LongitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LongitudeMarker) PojoModelPath(org.hibernate.search.mapper.pojo.model.path.PojoModelPath) Searchable(org.hibernate.search.engine.backend.types.Searchable) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) Param(org.hibernate.search.mapper.pojo.common.annotation.Param) LatitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LatitudeMarker) Function(java.util.function.Function) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) IdentifierBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.IdentifierBindingContext) StubDocumentNode(org.hibernate.search.util.impl.integrationtest.common.stub.backend.document.StubDocumentNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) IdentifierBinderRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBinderRef) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) StaticCounters(org.hibernate.search.util.impl.test.rule.StaticCounters) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) IdentifierBridge(org.hibernate.search.mapper.pojo.bridge.IdentifierBridge) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) IdentifierBridgeFromDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeFromDocumentIdentifierContext) IdentifierBridgeToDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeToDocumentIdentifierContext) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) Collections(java.util.Collections) ObjectPath(org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath) Assert.assertEquals(org.junit.Assert.assertEquals) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) Test(org.junit.Test)

Example 3 with SearchMapping

use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.

the class IndexedEmbeddedBaseIT method includeEmbeddedObjectId_identifierBridge.

@Test
@TestForIssue(jiraKey = "HSEARCH-3071")
public void includeEmbeddedObjectId_identifierBridge() {
    class IndexedEmbeddedLevel1 {

        @DocumentId(identifierBridge = @IdentifierBridgeRef(type = MyCustomIdentifierBinder.Bridge.class))
        Long theId;

        @AssociationInverseSide(inversePath = @ObjectPath(@PropertyValue(propertyName = "level1")))
        Object containing;
    }
    @Indexed(index = INDEX_NAME)
    class IndexedEntity {

        @DocumentId
        Integer id;

        @IndexedEmbedded(includeEmbeddedObjectId = true)
        IndexedEmbeddedLevel1 level1;

        public IndexedEntity(int id, Long level1Id) {
            this.id = id;
            this.level1 = new IndexedEmbeddedLevel1();
            this.level1.theId = level1Id;
            this.level1.containing = this;
        }
    }
    backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.field("theId", String.class, b3 -> b3.searchable(Searchable.YES).projectable(Projectable.YES))));
    SearchMapping mapping = setupHelper.start().expectCustomBeans().setup(IndexedEntity.class, IndexedEmbeddedLevel1.class);
    backendMock.verifyExpectationsMet();
    doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, 4242L), document -> document.objectField("level1", b2 -> b2.field("theId", "4243")));
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Arrays(java.util.Arrays) StartupStubBridge(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.StartupStubBridge) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DocumentId(org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) FailureReportUtils(org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportUtils) IdentifierBridgeRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBridgeRef) AssociationInverseSide(org.hibernate.search.mapper.pojo.mapping.definition.annotation.AssociationInverseSide) MethodHandles(java.lang.invoke.MethodHandles) ProgrammaticMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.ProgrammaticMappingSmokeIT) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) GeoPointBridge(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.GeoPointBridge) Optional(java.util.Optional) AnnotationMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.AnnotationMappingSmokeIT) Projectable(org.hibernate.search.engine.backend.types.Projectable) IdentifierBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.IdentifierBinder) CollectionHelper(org.hibernate.search.util.common.impl.CollectionHelper) LongitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LongitudeMarker) PojoModelPath(org.hibernate.search.mapper.pojo.model.path.PojoModelPath) Searchable(org.hibernate.search.engine.backend.types.Searchable) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) Param(org.hibernate.search.mapper.pojo.common.annotation.Param) LatitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LatitudeMarker) Function(java.util.function.Function) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) IdentifierBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.IdentifierBindingContext) StubDocumentNode(org.hibernate.search.util.impl.integrationtest.common.stub.backend.document.StubDocumentNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) IdentifierBinderRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBinderRef) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) StaticCounters(org.hibernate.search.util.impl.test.rule.StaticCounters) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) IdentifierBridge(org.hibernate.search.mapper.pojo.bridge.IdentifierBridge) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) IdentifierBridgeFromDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeFromDocumentIdentifierContext) IdentifierBridgeToDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeToDocumentIdentifierContext) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) Collections(java.util.Collections) ObjectPath(org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath) Assert.assertEquals(org.junit.Assert.assertEquals) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) StartupStubBridge(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.StartupStubBridge) GeoPointBridge(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.GeoPointBridge) IdentifierBridge(org.hibernate.search.mapper.pojo.bridge.IdentifierBridge) Test(org.junit.Test) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue)

Example 4 with SearchMapping

use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.

the class IndexedEmbeddedBaseIT method includeEmbeddedObjectId_noIdentifierBridge.

@Test
@TestForIssue(jiraKey = "HSEARCH-3071")
public void includeEmbeddedObjectId_noIdentifierBridge() {
    class IndexedEmbeddedLevel1 {

        @DocumentId
        Long theId;

        @AssociationInverseSide(inversePath = @ObjectPath(@PropertyValue(propertyName = "level1")))
        Object containing;
    }
    @Indexed(index = INDEX_NAME)
    class IndexedEntity {

        @DocumentId
        Integer id;

        @IndexedEmbedded(includeEmbeddedObjectId = true)
        IndexedEmbeddedLevel1 level1;

        public IndexedEntity(int id, Long level1Id) {
            this.id = id;
            this.level1 = new IndexedEmbeddedLevel1();
            this.level1.theId = level1Id;
            this.level1.containing = this;
        }
    }
    backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.field("theId", Long.class, b3 -> b3.searchable(Searchable.YES).projectable(Projectable.YES))));
    SearchMapping mapping = setupHelper.start().setup(IndexedEntity.class, IndexedEmbeddedLevel1.class);
    backendMock.verifyExpectationsMet();
    doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, 4242L), document -> document.objectField("level1", b2 -> b2.field("theId", 4242L)));
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Arrays(java.util.Arrays) StartupStubBridge(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.StartupStubBridge) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DocumentId(org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) FailureReportUtils(org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportUtils) IdentifierBridgeRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBridgeRef) AssociationInverseSide(org.hibernate.search.mapper.pojo.mapping.definition.annotation.AssociationInverseSide) MethodHandles(java.lang.invoke.MethodHandles) ProgrammaticMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.ProgrammaticMappingSmokeIT) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) GeoPointBridge(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.GeoPointBridge) Optional(java.util.Optional) AnnotationMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.AnnotationMappingSmokeIT) Projectable(org.hibernate.search.engine.backend.types.Projectable) IdentifierBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.IdentifierBinder) CollectionHelper(org.hibernate.search.util.common.impl.CollectionHelper) LongitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LongitudeMarker) PojoModelPath(org.hibernate.search.mapper.pojo.model.path.PojoModelPath) Searchable(org.hibernate.search.engine.backend.types.Searchable) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) Param(org.hibernate.search.mapper.pojo.common.annotation.Param) LatitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LatitudeMarker) Function(java.util.function.Function) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) IdentifierBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.IdentifierBindingContext) StubDocumentNode(org.hibernate.search.util.impl.integrationtest.common.stub.backend.document.StubDocumentNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) IdentifierBinderRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBinderRef) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) StaticCounters(org.hibernate.search.util.impl.test.rule.StaticCounters) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) IdentifierBridge(org.hibernate.search.mapper.pojo.bridge.IdentifierBridge) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) IdentifierBridgeFromDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeFromDocumentIdentifierContext) IdentifierBridgeToDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeToDocumentIdentifierContext) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) Collections(java.util.Collections) ObjectPath(org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath) Assert.assertEquals(org.junit.Assert.assertEquals) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) Test(org.junit.Test) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue)

Example 5 with SearchMapping

use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.

the class IndexedEmbeddedBaseIT method name.

@Test
public void name() {
    class IndexedEmbeddedLevel1 {

        @GenericField
        String level1Property;
    }
    @Indexed(index = INDEX_NAME)
    class IndexedEntity {

        @DocumentId
        Integer id;

        @IndexedEmbedded(name = "explicitName")
        IndexedEmbeddedLevel1 level1;

        public IndexedEntity(int id, String value) {
            this.id = id;
            this.level1 = new IndexedEmbeddedLevel1();
            this.level1.level1Property = value;
        }
    }
    backendMock.expectSchema(INDEX_NAME, b -> b.objectField("explicitName", b2 -> b2.field("level1Property", String.class)));
    SearchMapping mapping = setupHelper.start().withAnnotatedEntityTypes(IndexedEntity.class).withAnnotatedTypes(IndexedEmbeddedLevel1.class).setup();
    backendMock.verifyExpectationsMet();
    doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, "level1Value"), document -> document.objectField("explicitName", b2 -> b2.field("level1Property", "level1Value")));
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Arrays(java.util.Arrays) StartupStubBridge(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.StartupStubBridge) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DocumentId(org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) FailureReportUtils(org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportUtils) IdentifierBridgeRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBridgeRef) AssociationInverseSide(org.hibernate.search.mapper.pojo.mapping.definition.annotation.AssociationInverseSide) MethodHandles(java.lang.invoke.MethodHandles) ProgrammaticMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.ProgrammaticMappingSmokeIT) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) GeoPointBridge(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.GeoPointBridge) Optional(java.util.Optional) AnnotationMappingSmokeIT(org.hibernate.search.integrationtest.mapper.pojo.smoke.AnnotationMappingSmokeIT) Projectable(org.hibernate.search.engine.backend.types.Projectable) IdentifierBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.IdentifierBinder) CollectionHelper(org.hibernate.search.util.common.impl.CollectionHelper) LongitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LongitudeMarker) PojoModelPath(org.hibernate.search.mapper.pojo.model.path.PojoModelPath) Searchable(org.hibernate.search.engine.backend.types.Searchable) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) Param(org.hibernate.search.mapper.pojo.common.annotation.Param) LatitudeMarker(org.hibernate.search.mapper.pojo.bridge.builtin.spatial.impl.LatitudeMarker) Function(java.util.function.Function) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) IdentifierBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.IdentifierBindingContext) StubDocumentNode(org.hibernate.search.util.impl.integrationtest.common.stub.backend.document.StubDocumentNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) IdentifierBinderRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.IdentifierBinderRef) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) StaticCounters(org.hibernate.search.util.impl.test.rule.StaticCounters) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) IdentifierBridge(org.hibernate.search.mapper.pojo.bridge.IdentifierBridge) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) IdentifierBridgeFromDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeFromDocumentIdentifierContext) IdentifierBridgeToDocumentIdentifierContext(org.hibernate.search.mapper.pojo.bridge.runtime.IdentifierBridgeToDocumentIdentifierContext) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) Collections(java.util.Collections) ObjectPath(org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath) Assert.assertEquals(org.junit.Assert.assertEquals) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) Test(org.junit.Test)

Aggregations

SearchMapping (org.hibernate.search.mapper.javabean.mapping.SearchMapping)148 Test (org.junit.Test)148 Indexed (org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed)118 SearchSession (org.hibernate.search.mapper.javabean.session.SearchSession)96 SearchException (org.hibernate.search.util.common.SearchException)93 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)90 MethodHandles (java.lang.invoke.MethodHandles)87 JavaBeanMappingSetupHelper (org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper)87 BackendMock (org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock)87 Rule (org.junit.Rule)87 DocumentId (org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId)84 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)78 FailureReportUtils (org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportUtils)75 GenericField (org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField)62 Collections (java.util.Collections)50 List (java.util.List)48 TypeMappingStep (org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep)44 Param (org.hibernate.search.mapper.pojo.common.annotation.Param)42 ObjectStructure (org.hibernate.search.engine.backend.types.ObjectStructure)41 Optional (java.util.Optional)40