Search in sources :

Example 6 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class FieldSearchSortTypeCheckingAndConversionIT method multiIndex_withRawFieldCompatibleIndex_dslConverterDisabled.

@Test
public void multiIndex_withRawFieldCompatibleIndex_dslConverterDisabled() {
    StubMappingScope scope = mainIndex.createScope(rawFieldCompatibleIndex);
    SearchQuery<DocumentReference> query;
    String fieldPath = getFieldPath();
    query = matchAllQuery(f -> f.field(fieldPath).asc().missing().use(getSingleValueForMissingUse(BEFORE_DOCUMENT_1_ORDINAL), ValueConvert.NO), 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(rawFieldCompatibleIndex.typeName(), RAW_FIELD_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 7 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class DistanceSearchSearchableSortableIT method searchableSortable.

@Test
public void searchableSortable() {
    StubMappingScope scope = index.createScope();
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field("searchableSortable").circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance("searchableSortable", METRO_GARIBALDI)).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) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 8 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery 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 9 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class DistanceSearchSearchableSortableIT method defaultSearchableSortable.

@Test
public void defaultSearchableSortable() {
    StubMappingScope scope = index.createScope();
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.spatial().within().field("defaultSearchableSortable").circle(METRO_GARIBALDI, 1_500)).sort(f -> f.distance("defaultSearchableSortable", METRO_GARIBALDI)).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) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 10 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class DistanceSearchSearchableSortableIT method notSearchableSortable.

@Test
public void notSearchableSortable() {
    StubMappingScope scope = index.createScope();
    String fieldPath = "notSearchableSortable";
    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 'predicate:spatial:within-circle' on field '" + fieldPath + "'");
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.matchAll()).sort(f -> f.distance(fieldPath, METRO_GARIBALDI)).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), CHEZ_MARGOTTE_ID, IMOUTO_ID, OURSON_QUI_BOIT_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)

Aggregations

SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)229 Test (org.junit.Test)222 Rule (org.junit.Rule)197 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)186 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)185 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)185 StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)179 Before (org.junit.Before)177 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)164 List (java.util.List)158 IndexFieldReference (org.hibernate.search.engine.backend.document.IndexFieldReference)153 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)151 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)135 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)129 Projectable (org.hibernate.search.engine.backend.types.Projectable)127 SearchException (org.hibernate.search.util.common.SearchException)119 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)113 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)110 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)102 IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)102