Search in sources :

Example 1 with Projectable

use of org.hibernate.search.engine.backend.types.Projectable in project hibernate-search by hibernate.

the class DistanceSearchableSortableIT method searchableNotSortable.

@Test
public void searchableNotSortable() {
    assumeFalse("Skipping test for ES GeoPoint as those would become sortable by default in this case.", TckConfiguration.get().getBackendFeatures().fieldsProjectableByDefault());
    StubMappingScope scope = index.createScope();
    String fieldPath = "searchableNotSortable";
    assertThatThrownBy(() -> scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery()).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'sort:distance' on field '" + fieldPath + "'", "Make sure the field is marked as searchable/sortable/projectable/aggregable (whichever is relevant)");
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Sortable(org.hibernate.search.engine.backend.types.Sortable) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) Assume.assumeFalse(org.junit.Assume.assumeFalse) Searchable(org.hibernate.search.engine.backend.types.Searchable) 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) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Projectable(org.hibernate.search.engine.backend.types.Projectable) TckConfiguration(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchException(org.hibernate.search.util.common.SearchException) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 2 with Projectable

use of org.hibernate.search.engine.backend.types.Projectable in project hibernate-search by hibernate.

the class DistanceSearchableSortableIT method searchableDefaultSortable.

@Test
public void searchableDefaultSortable() {
    assumeFalse("Skipping test for ES GeoPoint as those would become sortable by default in this case.", TckConfiguration.get().getBackendFeatures().fieldsProjectableByDefault());
    StubMappingScope scope = index.createScope();
    String fieldPath = "searchableDefaultSortable";
    assertThatThrownBy(() -> scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery()).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'sort:distance' on field '" + fieldPath + "'", "Make sure the field is marked as searchable/sortable/projectable/aggregable (whichever is relevant)");
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field(fieldPath).circle(METRO_GARIBALDI, 1_500)).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Sortable(org.hibernate.search.engine.backend.types.Sortable) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) Assume.assumeFalse(org.junit.Assume.assumeFalse) Searchable(org.hibernate.search.engine.backend.types.Searchable) 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) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Projectable(org.hibernate.search.engine.backend.types.Projectable) TckConfiguration(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchException(org.hibernate.search.util.common.SearchException) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 3 with Projectable

use of org.hibernate.search.engine.backend.types.Projectable in project hibernate-search by hibernate.

the class ProgrammaticMappingGeoPointBindingIT method setup.

@Before
public void setup() {
    backendMock.expectSchema(GeoPointOnTypeEntity.INDEX, b -> b.field("homeLocation", GeoPoint.class, b2 -> b2.projectable(Projectable.YES).sortable(Sortable.YES)).field("workLocation", GeoPoint.class, b2 -> b2.projectable(Projectable.DEFAULT).sortable(Sortable.DEFAULT)));
    backendMock.expectSchema(GeoPointOnCoordinatesPropertyEntity.INDEX, b -> b.field("coord", GeoPoint.class).field("location", GeoPoint.class, b2 -> b2.projectable(Projectable.NO)));
    backendMock.expectSchema(GeoPointOnCustomCoordinatesPropertyEntity.INDEX, b -> b.field("coord", GeoPoint.class, b2 -> b2.projectable(Projectable.DEFAULT).sortable(Sortable.DEFAULT)).field("location", GeoPoint.class, b2 -> b2.projectable(Projectable.DEFAULT).sortable(Sortable.DEFAULT)));
    mapping = setupHelper.start().withConfiguration(builder -> {
        builder.addEntityTypes(CollectionHelper.asSet(GeoPointOnTypeEntity.class, GeoPointOnCoordinatesPropertyEntity.class, GeoPointOnCustomCoordinatesPropertyEntity.class));
        ProgrammaticMappingConfigurationContext mappingDefinition = builder.programmaticMapping();
        TypeMappingStep geoPointOntTypeEntityMapping = mappingDefinition.type(GeoPointOnTypeEntity.class);
        geoPointOntTypeEntityMapping.indexed().index(GeoPointOnTypeEntity.INDEX);
        geoPointOntTypeEntityMapping.binder(GeoPointBinder.create().fieldName("homeLocation").markerSet("home").projectable(Projectable.YES).sortable(Sortable.YES));
        geoPointOntTypeEntityMapping.binder(GeoPointBinder.create().fieldName("workLocation").markerSet("work"));
        geoPointOntTypeEntityMapping.property("id").documentId();
        geoPointOntTypeEntityMapping.property("homeLatitude").marker(GeoPointBinder.latitude().markerSet("home"));
        geoPointOntTypeEntityMapping.property("homeLongitude").marker(GeoPointBinder.longitude().markerSet("home"));
        geoPointOntTypeEntityMapping.property("workLatitude").marker(GeoPointBinder.latitude().markerSet("work"));
        geoPointOntTypeEntityMapping.property("workLongitude").marker(GeoPointBinder.longitude().markerSet("work"));
        TypeMappingStep geoPointOnCoordinatesPropertyEntityMapping = mappingDefinition.type(GeoPointOnCoordinatesPropertyEntity.class);
        geoPointOnCoordinatesPropertyEntityMapping.indexed().index(GeoPointOnCoordinatesPropertyEntity.INDEX);
        geoPointOnCoordinatesPropertyEntityMapping.property("id").documentId();
        geoPointOnCoordinatesPropertyEntityMapping.property("coord").genericField().genericField("location").projectable(Projectable.NO);
        TypeMappingStep geoPointOnCustomCoordinatesPropertyEntityMapping = mappingDefinition.type(GeoPointOnCustomCoordinatesPropertyEntity.class);
        geoPointOnCustomCoordinatesPropertyEntityMapping.indexed().index(GeoPointOnCustomCoordinatesPropertyEntity.INDEX);
        geoPointOnCustomCoordinatesPropertyEntityMapping.property("id").documentId();
        geoPointOnCustomCoordinatesPropertyEntityMapping.property("coord").binder(GeoPointBinder.create()).binder(GeoPointBinder.create().fieldName("location"));
        TypeMappingStep customCoordinatesMapping = mappingDefinition.type(CustomCoordinates.class);
        customCoordinatesMapping.property("lat").marker(GeoPointBinder.latitude());
        customCoordinatesMapping.property("lon").marker(GeoPointBinder.longitude());
    }).setup();
    backendMock.verifyExpectationsMet();
}
Also used : Sortable(org.hibernate.search.engine.backend.types.Sortable) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) MethodHandles(java.lang.invoke.MethodHandles) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) Test(org.junit.Test) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) ProgrammaticMappingConfigurationContext(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext) Rule(org.junit.Rule) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) GeoPointBinder(org.hibernate.search.mapper.pojo.bridge.builtin.programmatic.GeoPointBinder) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) Projectable(org.hibernate.search.engine.backend.types.Projectable) CollectionHelper(org.hibernate.search.util.common.impl.CollectionHelper) Before(org.junit.Before) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) ProgrammaticMappingConfigurationContext(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext) Before(org.junit.Before)

Example 4 with Projectable

use of org.hibernate.search.engine.backend.types.Projectable in project hibernate-search by hibernate.

the class JpaIdAsDocumentIdIT method test.

@Test
public void test() {
    backendMock.expectSchema(IndexedEntity.NAME, b -> b.objectField("contained", b2 -> b2.multiValued(true).field("id", Integer.class, b3 -> b3.searchable(Searchable.YES).projectable(Projectable.YES))));
    SessionFactory sessionFactory = ormSetupHelper.start().setup(IndexedEntity.class, ContainedEntity.class);
    backendMock.verifyExpectationsMet();
    with(sessionFactory).runInTransaction(session -> {
        IndexedEntity entity1 = new IndexedEntity();
        entity1.setId(0);
        ContainedEntity contained1 = new ContainedEntity();
        contained1.setId(1);
        entity1.getContained().add(contained1);
        contained1.containing = entity1;
        ContainedEntity contained2 = new ContainedEntity();
        contained2.setId(2);
        entity1.getContained().add(contained2);
        contained2.containing = entity1;
        session.persist(entity1);
        session.persist(contained1);
        session.persist(contained2);
        backendMock.expectWorks(IndexedEntity.NAME).add("0", b -> b.objectField("contained", b2 -> b2.field("id", 1)).objectField("contained", b2 -> b2.field("id", 2)));
    });
}
Also used : Entity(javax.persistence.Entity) ManyToOne(javax.persistence.ManyToOne) Searchable(org.hibernate.search.engine.backend.types.Searchable) OneToMany(javax.persistence.OneToMany) SessionFactory(org.hibernate.SessionFactory) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) ArrayList(java.util.ArrayList) List(java.util.List) OrderColumn(javax.persistence.OrderColumn) Rule(org.junit.Rule) OrmUtils.with(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) OrmSetupHelper(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper) Projectable(org.hibernate.search.engine.backend.types.Projectable) Id(javax.persistence.Id) SessionFactory(org.hibernate.SessionFactory) Test(org.junit.Test)

Example 5 with Projectable

use of org.hibernate.search.engine.backend.types.Projectable 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)

Aggregations

Projectable (org.hibernate.search.engine.backend.types.Projectable)18 Rule (org.junit.Rule)16 Test (org.junit.Test)16 Searchable (org.hibernate.search.engine.backend.types.Searchable)15 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)14 SearchException (org.hibernate.search.util.common.SearchException)14 BackendMock (org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock)13 MethodHandles (java.lang.invoke.MethodHandles)12 JavaBeanMappingSetupHelper (org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper)12 SearchMapping (org.hibernate.search.mapper.javabean.mapping.SearchMapping)12 SearchSession (org.hibernate.search.mapper.javabean.session.SearchSession)12 Indexed (org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 DocumentId (org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId)11 Arrays (java.util.Arrays)10 Collections (java.util.Collections)10 Optional (java.util.Optional)10 Consumer (java.util.function.Consumer)10 Function (java.util.function.Function)10