Search in sources :

Example 1 with Sortable

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

the class DistanceSearchSearchableSortableIT method searchableNotSortable.

@Test
public void searchableNotSortable() {
    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) 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) 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 Sortable

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

the class FullNameBinder method bind.

@Override
public void bind(TypeBindingContext context) {
    context.dependencies().use("firstName").use("lastName");
    IndexFieldReference<String> fullNameField = context.indexSchemaElement().field("fullName", f -> f.asString().analyzer("name")).toReference();
    IndexFieldReference<String> fullNameSortField = null;
    if (this.sortField) {
        // <2>
        fullNameSortField = context.indexSchemaElement().field("fullName_sort", f -> f.asString().normalizer("name").sortable(Sortable.YES)).toReference();
    }
    context.bridge(Author.class, new Bridge(fullNameField, fullNameSortField));
}
Also used : IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) Sortable(org.hibernate.search.engine.backend.types.Sortable) TypeBridgeWriteContext(org.hibernate.search.mapper.pojo.bridge.runtime.TypeBridgeWriteContext) TypeBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.TypeBindingContext) TypeBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.TypeBinder) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) TypeBridge(org.hibernate.search.mapper.pojo.bridge.TypeBridge) TypeBridge(org.hibernate.search.mapper.pojo.bridge.TypeBridge)

Example 3 with Sortable

use of org.hibernate.search.engine.backend.types.Sortable 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 4 with Sortable

use of org.hibernate.search.engine.backend.types.Sortable 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 5 with Sortable

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

Aggregations

Sortable (org.hibernate.search.engine.backend.types.Sortable)11 IndexFieldReference (org.hibernate.search.engine.backend.document.IndexFieldReference)8 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)6 GeoPoint (org.hibernate.search.engine.spatial.GeoPoint)6 Before (org.junit.Before)6 Rule (org.junit.Rule)6 Test (org.junit.Test)6 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)5 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)5 Searchable (org.hibernate.search.engine.backend.types.Searchable)5 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)5 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)5 SearchException (org.hibernate.search.util.common.SearchException)5 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)5 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)5 StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)5 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)4 Projectable (org.hibernate.search.engine.backend.types.Projectable)4 TckConfiguration (org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration)3 Assume.assumeFalse (org.junit.Assume.assumeFalse)3