Search in sources :

Example 1 with StubMappingScope

use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.

the class FieldSearchSortTypeCheckingAndConversionIT method multiIndex_withCompatibleIndex_usingField.

@Test
public void multiIndex_withCompatibleIndex_usingField() {
    StubMappingScope scope = mainIndex.createScope(compatibleIndex);
    SearchQuery<DocumentReference> query;
    String fieldPath = getFieldPath();
    query = matchAllQuery(f -> f.field(fieldPath).asc().missing().use(getSingleValueForMissingUse(BEFORE_DOCUMENT_1_ORDINAL)), scope);
    /*
		 * Not testing the ordering of results here because some documents have the same value.
		 * It's not what we want to test anyway: we just want to check that fields are correctly
		 * detected as compatible and that no exception is thrown.
		 */
    assertThatQuery(query).hasDocRefHitsAnyOrder(b -> {
        b.doc(mainIndex.typeName(), EMPTY);
        b.doc(mainIndex.typeName(), DOCUMENT_1);
        b.doc(mainIndex.typeName(), DOCUMENT_2);
        b.doc(mainIndex.typeName(), DOCUMENT_3);
        b.doc(compatibleIndex.typeName(), COMPATIBLE_INDEX_DOCUMENT_1);
    });
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) SimpleFieldModelsByType(org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModelsByType) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) BeforeClass(org.junit.BeforeClass) SimpleFieldModel(org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel) Searchable(org.hibernate.search.engine.backend.types.Searchable) RunWith(org.junit.runner.RunWith) SortFinalStep(org.hibernate.search.engine.search.sort.dsl.SortFinalStep) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) SearchSortFactory(org.hibernate.search.engine.search.sort.dsl.SearchSortFactory) Function(java.util.function.Function) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BulkIndexer(org.hibernate.search.util.impl.integrationtest.mapper.stub.BulkIndexer) Locale(java.util.Locale) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ValueConvert(org.hibernate.search.engine.search.common.ValueConvert) FailureReportUtils(org.hibernate.search.util.impl.integrationtest.common.FailureReportUtils) ClassRule(org.junit.ClassRule) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) Parameterized(org.junit.runners.Parameterized) ValueWrapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.ValueWrapper) FieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.FieldTypeDescriptor) Sortable(org.hibernate.search.engine.backend.types.Sortable) EventContexts(org.hibernate.search.engine.reporting.spi.EventContexts) Test(org.junit.Test) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) InvalidType(org.hibernate.search.integrationtest.backend.tck.testsupport.util.InvalidType) NormalizedStringFieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.NormalizedStringFieldTypeDescriptor) Consumer(java.util.function.Consumer) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Aggregable(org.hibernate.search.engine.backend.types.Aggregable) StandardIndexFieldTypeOptionsStep(org.hibernate.search.engine.backend.types.dsl.StandardIndexFieldTypeOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) Assume.assumeTrue(org.junit.Assume.assumeTrue) Projectable(org.hibernate.search.engine.backend.types.Projectable) TckConfiguration(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 2 with StubMappingScope

use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.

the class FieldSearchSortUnsupportedTypesIT method error_notSupported.

@Test
@TestForIssue(jiraKey = "HSEARCH-3798")
public void error_notSupported() {
    StubMappingScope scope = index.createScope();
    String absoluteFieldPath = getFieldPath();
    assertThatThrownBy(() -> scope.sort().field(absoluteFieldPath)).isInstanceOf(SearchException.class).hasMessageContainingAll("Cannot use 'sort:field' on field '" + absoluteFieldPath + "'", "'sort:field' is not available for fields of this type").satisfies(FailureReportUtils.hasContext(EventContexts.fromIndexFieldAbsolutePath(absoluteFieldPath)));
}
Also used : StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue)

Example 3 with StubMappingScope

use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.

the class DistanceSearchProjectionComplexCasesIT method withDistanceSort.

/**
 * See also {@link DistanceSearchProjectionSingleValuedBaseIT#sortable_withSort()}.
 * <p>
 * The main difference is that we're composing multiple sorts here.
 */
@Test
public void withDistanceSort() {
    StubMappingScope scope = mainIndex.createScope();
    GeoPoint center = GeoPoint.of(45.749828, 4.854172);
    assertThatQuery(scope.query().select(f -> f.distance("geoPoint", center)).where(f -> f.matchAll()).sort(f -> f.distance("geoPoint", GeoPoint.of(43.749828, 1.854172)).then().distance("geoPoint", center)).toQuery()).hits().asIs().usingElementComparator(APPROX_M_COMPARATOR).containsExactly(1300d, 430d, 2730d, null);
}
Also used : List(java.util.List) DistanceUnit(org.hibernate.search.engine.spatial.DistanceUnit) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) ListAssert(org.assertj.core.api.ListAssert) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) DistanceSearchProjectionSingleValuedBaseIT(org.hibernate.search.integrationtest.backend.tck.search.projection.DistanceSearchProjectionSingleValuedBaseIT) TestComparators(org.hibernate.search.util.impl.integrationtest.common.assertion.TestComparators) Comparator(java.util.Comparator) AbstractSpatialWithinSearchPredicateIT(org.hibernate.search.integrationtest.backend.tck.search.predicate.AbstractSpatialWithinSearchPredicateIT) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test)

Example 4 with StubMappingScope

use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.

the class DistanceSearchProjectionComplexCasesIT method several.

/**
 * See also {@link DistanceSearchProjectionSingleValuedBaseIT#several()}.
 * <p>
 * The main difference is that we're targeting multiple fields here.
 */
@Test
public void several() {
    StubMappingScope scope = mainIndex.createScope();
    ListAssert<List<?>> hitsAssert = assertThatQuery(scope.query().select(f -> f.composite(f.distance("geoPoint", GeoPoint.of(45.749828, 4.854172)), f.distance("geoPoint", GeoPoint.of(45.763363, 4.833527)), f.distance("geoPoint_1", GeoPoint.of(45.749828, 4.854172)).unit(DistanceUnit.KILOMETERS))).where(f -> f.matchAll()).sort(f -> f.field("string").missing().last().asc()).toQuery()).hits().asIs();
    hitsAssert.extracting(tuple -> (Double) tuple.get(0)).usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(430d, 1300d, 2730d, null);
    hitsAssert.extracting(tuple -> (Double) tuple.get(1)).usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(1780d, 1095d, 812d, null);
    hitsAssert.extracting(tuple -> (Double) tuple.get(2)).usingElementComparator(APPROX_KM_COMPARATOR).containsExactlyInAnyOrder(135.834, 136.294, 134.967, null);
}
Also used : List(java.util.List) DistanceUnit(org.hibernate.search.engine.spatial.DistanceUnit) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) ListAssert(org.assertj.core.api.ListAssert) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) DistanceSearchProjectionSingleValuedBaseIT(org.hibernate.search.integrationtest.backend.tck.search.projection.DistanceSearchProjectionSingleValuedBaseIT) TestComparators(org.hibernate.search.util.impl.integrationtest.common.assertion.TestComparators) Comparator(java.util.Comparator) AbstractSpatialWithinSearchPredicateIT(org.hibernate.search.integrationtest.backend.tck.search.predicate.AbstractSpatialWithinSearchPredicateIT) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) List(java.util.List) Test(org.junit.Test)

Example 5 with StubMappingScope

use of org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope in project hibernate-search by hibernate.

the class DistanceSearchProjectionComplexCasesIT method longFieldName.

/**
 * Test that projections will work even with very long field names.
 * <p>
 * This is relevant for Elasticsearch, which generates a name for computed values based on the field name.
 */
@Test
public void longFieldName() {
    StubMappingScope scope = mainIndex.createScope();
    assertThatQuery(scope.query().select(f -> f.distance("geoPoint_with_a_veeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyy_long_name", GeoPoint.of(45.74982800099999888371, 4.85417200099999888371))).where(f -> f.matchAll()).toQuery()).hits().asIs().usingElementComparator(APPROX_M_COMPARATOR).containsExactlyInAnyOrder(430d, 1300d, 2730d, null);
}
Also used : List(java.util.List) DistanceUnit(org.hibernate.search.engine.spatial.DistanceUnit) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) ListAssert(org.assertj.core.api.ListAssert) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) DistanceSearchProjectionSingleValuedBaseIT(org.hibernate.search.integrationtest.backend.tck.search.projection.DistanceSearchProjectionSingleValuedBaseIT) TestComparators(org.hibernate.search.util.impl.integrationtest.common.assertion.TestComparators) Comparator(java.util.Comparator) AbstractSpatialWithinSearchPredicateIT(org.hibernate.search.integrationtest.backend.tck.search.predicate.AbstractSpatialWithinSearchPredicateIT) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test)

Aggregations

StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)449 Test (org.junit.Test)447 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)316 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)306 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)288 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)286 SearchException (org.hibernate.search.util.common.SearchException)268 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)239 Projectable (org.hibernate.search.engine.backend.types.Projectable)226 List (java.util.List)221 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)209 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)208 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)186 Sortable (org.hibernate.search.engine.backend.types.Sortable)176 Rule (org.junit.Rule)176 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)175 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)174 IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)174 ObjectStructure (org.hibernate.search.engine.backend.types.ObjectStructure)174 Before (org.junit.Before)173