Search in sources :

Example 1 with HibernateOrmSearchMappingConfigurer

use of org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer in project hibernate-search by hibernate.

the class ElasticsearchAnalysisIT method advanced.

@Test
public void advanced() {
    EntityManagerFactory entityManagerFactory = setupHelper.start().withBackendProperty(ElasticsearchIndexSettings.ANALYSIS_CONFIGURER, new AdvancedElasticsearchAnalysisConfigurer()).withProperty(HibernateOrmMapperSettings.MAPPING_CONFIGURER, (HibernateOrmSearchMappingConfigurer) context -> context.programmaticMapping().type(IndexedEntity.class).property("text").fullTextField("standard").analyzer("standard")).setup(IndexedEntity.class);
    with(entityManagerFactory).runInTransaction(entityManager -> {
        IndexedEntity entity = new IndexedEntity();
        entity.setText("the Wording");
        entityManager.persist(entity);
    });
    with(entityManagerFactory).runInTransaction(entityManager -> {
        SearchSession searchSession = Search.session(entityManager);
        assertThat(searchSession.search(IndexedEntity.class).where(f -> f.match().field("standard").matching("wording")).fetchHits(20)).hasSize(1);
    });
}
Also used : Entity(javax.persistence.Entity) Search(org.hibernate.search.mapper.orm.Search) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BackendConfigurations(org.hibernate.search.documentation.testsupport.BackendConfigurations) Test(org.junit.Test) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) DocumentationSetupHelper(org.hibernate.search.documentation.testsupport.DocumentationSetupHelper) Rule(org.junit.Rule) GeneratedValue(javax.persistence.GeneratedValue) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) HibernateOrmMapperSettings(org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) EntityManagerFactory(javax.persistence.EntityManagerFactory) OrmUtils.with(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with) Id(javax.persistence.Id) ElasticsearchIndexSettings(org.hibernate.search.backend.elasticsearch.cfg.ElasticsearchIndexSettings) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) Test(org.junit.Test)

Example 2 with HibernateOrmSearchMappingConfigurer

use of org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer in project hibernate-search by hibernate.

the class LuceneAnalysisIT method similarity.

@Test
public void similarity() {
    EntityManagerFactory entityManagerFactory = setupHelper.start().withBackendProperty(LuceneBackendSettings.ANALYSIS_CONFIGURER, new CustomSimilarityLuceneAnalysisConfigurer()).withProperty(HibernateOrmMapperSettings.MAPPING_CONFIGURER, (HibernateOrmSearchMappingConfigurer) context -> context.programmaticMapping().type(IndexedEntity.class).property("text").fullTextField("standard").analyzer("english")).setup(IndexedEntity.class);
    with(entityManagerFactory).runInTransaction(entityManager -> {
        IndexedEntity entity = new IndexedEntity();
        entity.setText("the Wording");
        entityManager.persist(entity);
    });
    with(entityManagerFactory).runInTransaction(entityManager -> {
        SearchSession searchSession = Search.session(entityManager);
        assertThat(searchSession.search(IndexedEntity.class).where(f -> f.match().field("standard").matching("wording")).fetchHits(20)).hasSize(1);
    });
}
Also used : Entity(javax.persistence.Entity) Search(org.hibernate.search.mapper.orm.Search) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BackendConfigurations(org.hibernate.search.documentation.testsupport.BackendConfigurations) Test(org.junit.Test) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) DocumentationSetupHelper(org.hibernate.search.documentation.testsupport.DocumentationSetupHelper) Rule(org.junit.Rule) GeneratedValue(javax.persistence.GeneratedValue) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) HibernateOrmMapperSettings(org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) EntityManagerFactory(javax.persistence.EntityManagerFactory) OrmUtils.with(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with) LuceneBackendSettings(org.hibernate.search.backend.lucene.cfg.LuceneBackendSettings) Id(javax.persistence.Id) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) Test(org.junit.Test)

Example 3 with HibernateOrmSearchMappingConfigurer

use of org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer in project hibernate-search by hibernate.

the class LuceneAnalysisIT method luceneClasses.

@Test
public void luceneClasses() {
    EntityManagerFactory entityManagerFactory = setupHelper.start().withBackendProperty(LuceneBackendSettings.ANALYSIS_CONFIGURER, new LuceneClassesAnalysisConfigurer()).withProperty(HibernateOrmMapperSettings.MAPPING_CONFIGURER, (HibernateOrmSearchMappingConfigurer) context -> context.programmaticMapping().type(IndexedEntity.class).property("text").fullTextField("standard").analyzer("english")).setup(IndexedEntity.class);
    with(entityManagerFactory).runInTransaction(entityManager -> {
        IndexedEntity entity = new IndexedEntity();
        entity.setText("the Wording");
        entityManager.persist(entity);
    });
    with(entityManagerFactory).runInTransaction(entityManager -> {
        SearchSession searchSession = Search.session(entityManager);
        assertThat(searchSession.search(IndexedEntity.class).where(f -> f.match().field("standard").matching("wording")).fetchHits(20)).hasSize(1);
    });
}
Also used : Entity(javax.persistence.Entity) Search(org.hibernate.search.mapper.orm.Search) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BackendConfigurations(org.hibernate.search.documentation.testsupport.BackendConfigurations) Test(org.junit.Test) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) DocumentationSetupHelper(org.hibernate.search.documentation.testsupport.DocumentationSetupHelper) Rule(org.junit.Rule) GeneratedValue(javax.persistence.GeneratedValue) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) HibernateOrmMapperSettings(org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) EntityManagerFactory(javax.persistence.EntityManagerFactory) OrmUtils.with(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with) LuceneBackendSettings(org.hibernate.search.backend.lucene.cfg.LuceneBackendSettings) Id(javax.persistence.Id) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) Test(org.junit.Test)

Example 4 with HibernateOrmSearchMappingConfigurer

use of org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer in project hibernate-search by hibernate.

the class LuceneAnalysisIT method advanced.

@Test
public void advanced() {
    EntityManagerFactory entityManagerFactory = setupHelper.start().withBackendProperty(LuceneBackendSettings.ANALYSIS_CONFIGURER, new AdvancedLuceneAnalysisConfigurer()).withProperty(HibernateOrmMapperSettings.MAPPING_CONFIGURER, (HibernateOrmSearchMappingConfigurer) context -> context.programmaticMapping().type(IndexedEntity.class).property("text").fullTextField("standard").analyzer("my-standard")).setup(IndexedEntity.class);
    with(entityManagerFactory).runInTransaction(entityManager -> {
        IndexedEntity entity = new IndexedEntity();
        entity.setText("the Wording");
        entityManager.persist(entity);
    });
    with(entityManagerFactory).runInTransaction(entityManager -> {
        SearchSession searchSession = Search.session(entityManager);
        assertThat(searchSession.search(IndexedEntity.class).where(f -> f.match().field("standard").matching("wording")).fetchHits(20)).hasSize(1);
    });
}
Also used : Entity(javax.persistence.Entity) Search(org.hibernate.search.mapper.orm.Search) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BackendConfigurations(org.hibernate.search.documentation.testsupport.BackendConfigurations) Test(org.junit.Test) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) DocumentationSetupHelper(org.hibernate.search.documentation.testsupport.DocumentationSetupHelper) Rule(org.junit.Rule) GeneratedValue(javax.persistence.GeneratedValue) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) HibernateOrmMapperSettings(org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) EntityManagerFactory(javax.persistence.EntityManagerFactory) OrmUtils.with(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with) LuceneBackendSettings(org.hibernate.search.backend.lucene.cfg.LuceneBackendSettings) Id(javax.persistence.Id) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) Test(org.junit.Test)

Example 5 with HibernateOrmSearchMappingConfigurer

use of org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer in project hibernate-search by hibernate.

the class AnnotationMappingDiscoveryIT method discoveryDisabled.

@Test
public void discoveryDisabled() {
    backendMock.expectSchema(IndexedEntity.INDEX, b -> b.objectField("annotationMappedEmbedded", b2 -> {
        /*
					 * This object field should contain only the property mapped using the programmatic API,
					 * because the annotation mapping for the embedded type has *NOT* been automatically discovered.
					 */
        b2.field("alwaysPresent", String.class);
    }).objectField("nonAnnotationMappedEmbedded", b2 -> {
        /*
					 * This object field should contain only the property mapped using the programmatic API,
					 * because the annotation mapping for the embedded type has *NOT* been automatically discovered.
					 */
        b2.field("alwaysPresent", String.class);
    }));
    ormSetupHelper.start().withProperty(HibernateOrmMapperSettings.MAPPING_PROCESS_ANNOTATIONS, "false").withProperty(HibernateOrmMapperSettings.MAPPING_CONFIGURER, (HibernateOrmSearchMappingConfigurer) context -> {
        context.programmaticMapping().type(IndexedEntity.class).property("nonAnnotationMappedEmbedded").indexedEmbedded();
        TypeMappingStep indexedEntityMapping = context.programmaticMapping().type(IndexedEntity.class);
        indexedEntityMapping.indexed().index(IndexedEntity.INDEX);
        indexedEntityMapping.property("id").documentId();
        indexedEntityMapping.property("annotationMappedEmbedded").indexedEmbedded();
        mapAlwaysPresentProperty(context.programmaticMapping());
    }).setup(IndexedEntity.class, NonExplicitlyRegisteredType.class, NonExplicitlyRegisteredNonMappedType.class, NonExplicitlyRegisteredNonAnnotationMappedType.class);
    backendMock.verifyExpectationsMet();
}
Also used : IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) MappedSuperclass(javax.persistence.MappedSuperclass) PropertyBridgeWriteContext(org.hibernate.search.mapper.pojo.bridge.runtime.PropertyBridgeWriteContext) ArrayList(java.util.ArrayList) HibernateOrmMapperSettings(org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings) 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) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) Id(javax.persistence.Id) MarkerBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.MarkerBinder) MarkerBinding(org.hibernate.search.mapper.pojo.mapping.definition.annotation.MarkerBinding) Entity(javax.persistence.Entity) Embedded(javax.persistence.Embedded) MarkerBinderRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.MarkerBinderRef) PojoModelProperty(org.hibernate.search.mapper.pojo.model.PojoModelProperty) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) List(java.util.List) ProgrammaticMappingConfigurationContext(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext) Rule(org.junit.Rule) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) MarkerBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.MarkerBindingContext) PropertyBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.PropertyBindingContext) Embeddable(javax.persistence.Embeddable) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) OrmSetupHelper(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper) PropertyBinderRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.PropertyBinderRef) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) HibernateOrmSearchMappingConfigurer(org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer) Test(org.junit.Test)

Aggregations

HibernateOrmSearchMappingConfigurer (org.hibernate.search.mapper.orm.mapping.HibernateOrmSearchMappingConfigurer)31 HibernateOrmMapperSettings (org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings)28 Test (org.junit.Test)27 Rule (org.junit.Rule)26 OrmUtils.with (org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with)25 List (java.util.List)23 SessionFactory (org.hibernate.SessionFactory)23 ArrayList (java.util.ArrayList)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)21 BackendMock (org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock)21 Search (org.hibernate.search.mapper.orm.Search)20 SearchSession (org.hibernate.search.mapper.orm.session.SearchSession)20 OrmSetupHelper (org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper)20 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)20 LinkedHashMap (java.util.LinkedHashMap)18 Map (java.util.Map)18 Arrays (java.util.Arrays)17 Set (java.util.Set)16 TypeMappingStep (org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep)16 LocalDate (java.time.LocalDate)15