Search in sources :

Example 1 with DocumentElement

use of org.hibernate.search.engine.backend.document.DocumentElement in project hibernate-search by hibernate.

the class DistanceSearchSortTypeCheckingAndConversionIT method initDocument.

private static void initDocument(IndexBinding indexBinding, DocumentElement document, Integer ordinal) {
    addValue(indexBinding.fieldModel, document, ordinal);
    addValue(indexBinding.fieldWithDslConverterModel, document, ordinal);
    DocumentElement nested = document.addObject(indexBinding.nested.self);
    addValue(indexBinding.nested.fieldModel, nested, ordinal);
    addValue(indexBinding.nested.fieldWithDslConverterModel, nested, ordinal);
}
Also used : DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement)

Example 2 with DocumentElement

use of org.hibernate.search.engine.backend.document.DocumentElement in project hibernate-search by hibernate.

the class FieldSearchProjectionTypeCheckingAndConversionIT method initDocument.

private static <F> void initDocument(IndexBinding binding, DocumentElement document, int documentNumber) {
    binding.fieldModels.forEach(f -> addFieldValue(document, f, documentNumber));
    binding.fieldWithConverterModels.forEach(f -> addFieldValue(document, f, documentNumber));
    // Note: this object must be single-valued for these tests
    DocumentElement flattenedObject = document.addObject(binding.flattenedObject.self);
    binding.flattenedObject.fieldModels.forEach(f -> addFieldValue(flattenedObject, f, documentNumber));
    // Note: this object must be single-valued for these tests
    DocumentElement nestedObject = document.addObject(binding.nestedObject.self);
    binding.nestedObject.fieldModels.forEach(f -> addFieldValue(nestedObject, f, documentNumber));
}
Also used : DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement)

Example 3 with DocumentElement

use of org.hibernate.search.engine.backend.document.DocumentElement in project hibernate-search by hibernate.

the class DistanceSearchProjectionTypeCheckingAndConversionIT method initDocument.

private static <F> void initDocument(IndexBinding binding, DocumentElement document, int documentNumber) {
    addFieldValue(document, binding.fieldModel, documentNumber);
    addFieldValue(document, binding.fieldWithConverterModel, documentNumber);
    // Note: this object must be single-valued for these tests
    DocumentElement flattenedObject = document.addObject(binding.flattenedObject.self);
    addFieldValue(flattenedObject, binding.flattenedObject.fieldModel, documentNumber);
    // Note: this object must be single-valued for these tests
    DocumentElement nestedObject = document.addObject(binding.nestedObject.self);
    addFieldValue(nestedObject, binding.nestedObject.fieldModel, documentNumber);
}
Also used : DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement)

Example 4 with DocumentElement

use of org.hibernate.search.engine.backend.document.DocumentElement in project hibernate-search by hibernate.

the class FieldSearchSortTypeCheckingAndConversionIT method initDocument.

private static void initDocument(IndexBinding indexBinding, DocumentElement document, Integer ordinal) {
    indexBinding.fieldModels.forEach(fieldModel -> addValue(fieldModel, document, ordinal));
    indexBinding.fieldWithDslConverterModels.forEach(fieldModel -> addValue(fieldModel, document, ordinal));
    DocumentElement nested = document.addObject(indexBinding.nested.self);
    indexBinding.nested.fieldModels.forEach(fieldModel -> addValue(fieldModel, nested, ordinal));
    indexBinding.nested.fieldWithDslConverterModels.forEach(fieldModel -> addValue(fieldModel, nested, ordinal));
}
Also used : DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement)

Example 5 with DocumentElement

use of org.hibernate.search.engine.backend.document.DocumentElement in project hibernate-search by hibernate.

the class ElasticsearchExtensionIT method initData.

private void initData() {
    mainIndex.bulkIndexer().add(SECOND_ID, document -> {
        document.addValue(mainIndex.binding().string, "text 2");
        document.addValue(mainIndex.binding().nativeField_integer, new JsonPrimitive(2));
        document.addValue(mainIndex.binding().nativeField_integer_converted, new JsonPrimitive(2));
        document.addValue(mainIndex.binding().nativeField_unsupportedType, new JsonPrimitive("42"));
        document.addValue(mainIndex.binding().nativeField_sort1, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort2, new JsonPrimitive("a"));
        document.addValue(mainIndex.binding().nativeField_sort3, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort4, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort5, new JsonPrimitive("a"));
        document.addValue(mainIndex.binding().nativeField_aggregation, new JsonPrimitive("value-for-doc-1-and-2"));
        DocumentElement nestedObject1 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject1.addValue(mainIndex.binding().nestedObject.discriminator, "included");
        nestedObject1.addValue(mainIndex.binding().nestedObject.sort1, "b");
        nestedObject1.addValue(mainIndex.binding().nestedObject.aggregation1, "one");
        DocumentElement nestedObject2 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject2.addValue(mainIndex.binding().nestedObject.discriminator, "excluded");
        nestedObject2.addValue(mainIndex.binding().nestedObject.sort1, "a");
        nestedObject2.addValue(mainIndex.binding().nestedObject.aggregation1, "fifty-one");
    }).add(FIRST_ID, document -> {
        document.addValue(mainIndex.binding().string, "text 1");
        document.addValue(mainIndex.binding().nativeField_string, new JsonPrimitive("text 1"));
        document.addValue(mainIndex.binding().nativeField_sort1, new JsonPrimitive("a"));
        document.addValue(mainIndex.binding().nativeField_sort2, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort3, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort4, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort5, new JsonPrimitive("a"));
        document.addValue(mainIndex.binding().nativeField_aggregation, new JsonPrimitive("value-for-doc-1-and-2"));
        DocumentElement nestedObject1 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject1.addValue(mainIndex.binding().nestedObject.discriminator, "included");
        nestedObject1.addValue(mainIndex.binding().nestedObject.sort1, "a");
        nestedObject1.addValue(mainIndex.binding().nestedObject.aggregation1, "two");
        DocumentElement nestedObject2 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject2.addValue(mainIndex.binding().nestedObject.discriminator, "excluded");
        nestedObject2.addValue(mainIndex.binding().nestedObject.sort1, "b");
        nestedObject2.addValue(mainIndex.binding().nestedObject.aggregation1, "fifty-two");
    }).add(THIRD_ID, document -> {
        document.addValue(mainIndex.binding().string, "text 3");
        document.addValue(mainIndex.binding().nativeField_geoPoint, gson.fromJson("{'lat': 40.12, 'lon': -71.34}", JsonObject.class));
        document.addValue(mainIndex.binding().nativeField_sort1, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort2, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort3, new JsonPrimitive("a"));
        document.addValue(mainIndex.binding().nativeField_sort4, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort5, new JsonPrimitive("a"));
        document.addValue(mainIndex.binding().nativeField_aggregation, new JsonPrimitive("value-for-doc-3"));
        DocumentElement nestedObject1 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject1.addValue(mainIndex.binding().nestedObject.discriminator, "included");
        nestedObject1.addValue(mainIndex.binding().nestedObject.sort1, "c");
        nestedObject1.addValue(mainIndex.binding().nestedObject.aggregation1, "three");
        DocumentElement nestedObject2 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject2.addValue(mainIndex.binding().nestedObject.discriminator, "excluded");
        nestedObject2.addValue(mainIndex.binding().nestedObject.sort1, "b");
        nestedObject2.addValue(mainIndex.binding().nestedObject.aggregation1, "fifty-three");
    }).add(FOURTH_ID, document -> {
        document.addValue(mainIndex.binding().string, "text 4");
        document.addValue(mainIndex.binding().nativeField_dateWithColons, new JsonPrimitive("2018:01:12"));
        document.addValue(mainIndex.binding().nativeField_sort1, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort2, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort3, new JsonPrimitive("z"));
        document.addValue(mainIndex.binding().nativeField_sort4, new JsonPrimitive("a"));
        document.addValue(mainIndex.binding().nativeField_sort5, new JsonPrimitive("a"));
        DocumentElement nestedObject1 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject1.addValue(mainIndex.binding().nestedObject.discriminator, "included");
        nestedObject1.addValue(mainIndex.binding().nestedObject.sort1, "d");
        nestedObject1.addValue(mainIndex.binding().nestedObject.aggregation1, "four");
        DocumentElement nestedObject2 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject2.addValue(mainIndex.binding().nestedObject.discriminator, "excluded");
        nestedObject2.addValue(mainIndex.binding().nestedObject.sort1, "c");
        nestedObject2.addValue(mainIndex.binding().nestedObject.aggregation1, "fifty-four");
    }).add(FIFTH_ID, document -> {
        document.addValue(mainIndex.binding().string, "text 5");
        // This document should not match any query
        document.addValue(mainIndex.binding().nativeField_string, new JsonPrimitive("text 2"));
        document.addValue(mainIndex.binding().nativeField_integer, new JsonPrimitive(1));
        document.addValue(mainIndex.binding().nativeField_geoPoint, gson.fromJson("{'lat': 45.12, 'lon': -75.34}", JsonObject.class));
        document.addValue(mainIndex.binding().nativeField_dateWithColons, new JsonPrimitive("2018:01:25"));
        // ignore_malformed is enabled, this should be ignored
        document.addValue(mainIndex.binding().nativeField_unsupportedType, new JsonPrimitive("foobar"));
        document.addValue(mainIndex.binding().nativeField_sort5, new JsonPrimitive("z"));
        DocumentElement nestedObject1 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject1.addValue(mainIndex.binding().nestedObject.discriminator, "included");
        nestedObject1.addValue(mainIndex.binding().nestedObject.sort1, "e");
        nestedObject1.addValue(mainIndex.binding().nestedObject.aggregation1, "five");
        DocumentElement nestedObject2 = document.addObject(mainIndex.binding().nestedObject.self);
        nestedObject2.addValue(mainIndex.binding().nestedObject.discriminator, "excluded");
        nestedObject2.addValue(mainIndex.binding().nestedObject.sort1, "a");
        nestedObject2.addValue(mainIndex.binding().nestedObject.aggregation1, "fifty-five");
    }).add(EMPTY_ID, document -> {
    }).join();
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) JsonObject(com.google.gson.JsonObject) Backend(org.hibernate.search.engine.backend.Backend) ElasticsearchIndexManager(org.hibernate.search.backend.elasticsearch.index.ElasticsearchIndexManager) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) ElasticsearchSearchQueryWhereStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryWhereStep) JSONException(org.json.JSONException) Gson(com.google.gson.Gson) Map(java.util.Map) IndexManager(org.hibernate.search.engine.backend.index.IndexManager) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ElasticsearchSearchQueryOptionsStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQueryOptionsStep) SearchProjection(org.hibernate.search.engine.search.projection.SearchProjection) JsonHelper.assertJsonEquals(org.hibernate.search.util.impl.test.JsonHelper.assertJsonEquals) ElasticsearchSearchScrollResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScrollResult) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) Collectors(java.util.stream.Collectors) ElasticsearchIndexMetadataTestUtils.defaultPrimaryName(org.hibernate.search.util.impl.integrationtest.backend.elasticsearch.ElasticsearchIndexMetadataTestUtils.defaultPrimaryName) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Aggregable(org.hibernate.search.engine.backend.types.Aggregable) Response(org.elasticsearch.client.Response) JSONCompareMode(org.skyscreamer.jsonassert.JSONCompareMode) SearchHitsAssert.assertThatHits(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchHitsAssert.assertThatHits) Optional(java.util.Optional) ElasticsearchBackend(org.hibernate.search.backend.elasticsearch.ElasticsearchBackend) Projectable(org.hibernate.search.engine.backend.types.Projectable) ElasticsearchSearchQuery(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchQuery) RestClient(org.elasticsearch.client.RestClient) SearchLoadingContext(org.hibernate.search.engine.search.loading.spi.SearchLoadingContext) SearchIntegration(org.hibernate.search.engine.common.spi.SearchIntegration) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SearchSort(org.hibernate.search.engine.search.sort.SearchSort) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) ElasticsearchSearchResult(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchResult) JsonElement(com.google.gson.JsonElement) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ElasticsearchSearchScroll(org.hibernate.search.backend.elasticsearch.search.query.ElasticsearchSearchScroll) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) ValueConvert(org.hibernate.search.engine.search.common.ValueConvert) JsonPrimitive(com.google.gson.JsonPrimitive) ElasticsearchSearchQuerySelectStep(org.hibernate.search.backend.elasticsearch.search.query.dsl.ElasticsearchSearchQuerySelectStep) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) ValueWrapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.ValueWrapper) Before(org.junit.Before) Sortable(org.hibernate.search.engine.backend.types.Sortable) AggregationKey(org.hibernate.search.engine.search.aggregation.AggregationKey) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) SearchResultAssert.assertThatResult(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatResult) Request(org.elasticsearch.client.Request) ElasticsearchExtension(org.hibernate.search.backend.elasticsearch.ElasticsearchExtension) Rule(org.junit.Rule) StubLoadingOptionsStep(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubLoadingOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) HttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient) JsonPrimitive(com.google.gson.JsonPrimitive) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) JsonObject(com.google.gson.JsonObject)

Aggregations

DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)67 Test (org.junit.Test)47 IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)30 ObjectStructure (org.hibernate.search.engine.backend.types.ObjectStructure)30 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)27 Rule (org.junit.Rule)27 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)25 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)24 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)22 IndexFieldReference (org.hibernate.search.engine.backend.document.IndexFieldReference)21 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)21 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)21 SearchException (org.hibernate.search.util.common.SearchException)20 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)20 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)18 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)17 StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)14 List (java.util.List)12 Function (java.util.function.Function)11 FailureReportUtils (org.hibernate.search.util.impl.integrationtest.common.reporting.FailureReportUtils)11