Search in sources :

Example 1 with SimpleFieldModel

use of org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel in project hibernate-search by hibernate.

the class IndexingFieldTypesIT method withReference.

@Test
public void withReference() {
    List<F> values = new ArrayList<>(this.typeDescriptor.getIndexableValues().getSingle());
    // Also test null
    values.add(null);
    List<IdAndValue<F>> expectedDocuments = new ArrayList<>();
    SimpleFieldModel<F> fieldModel = index.binding().fieldModel;
    // Index all values, each in its own document
    IndexIndexingPlan plan = index.createIndexingPlan();
    for (int i = 0; i < values.size(); i++) {
        String documentId = "document_" + i;
        F value = values.get(i);
        plan.add(referenceProvider(documentId), document -> {
            document.addValue(fieldModel.reference, value);
        });
        expectedDocuments.add(new IdAndValue<>(documentId, value));
    }
    plan.execute().join();
    // If we get here, indexing went well.
    // However, it may have failed silently... Let's check the documents are there, with the right value.
    StubMappingScope scope = index.createScope();
    String absoluteFieldPath = fieldModel.relativeFieldName;
    for (int i = 0; i < values.size(); i++) {
        SearchQuery<IdAndValue<F>> query = scope.query().select(f -> f.composite().from(f.id(String.class), f.field(absoluteFieldPath, typeDescriptor.getJavaType())).as((id, val) -> new IdAndValue<>(id, val))).where(f -> f.matchAll()).toQuery();
        assertThatQuery(query).hasHitsAnyOrder(expectedDocuments);
    }
}
Also used : FieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.FieldTypeDescriptor) StubMapperUtils.referenceProvider(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapperUtils.referenceProvider) SimpleFieldModel(org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel) RunWith(org.junit.runner.RunWith) 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) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Rule(org.junit.Rule) IndexIndexingPlan(org.hibernate.search.engine.backend.work.execution.spi.IndexIndexingPlan) 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) Assume.assumeTrue(org.junit.Assume.assumeTrue) Projectable(org.hibernate.search.engine.backend.types.Projectable) TckConfiguration(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ArrayList(java.util.ArrayList) IndexIndexingPlan(org.hibernate.search.engine.backend.work.execution.spi.IndexIndexingPlan) Test(org.junit.Test)

Example 2 with SimpleFieldModel

use of org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel in project hibernate-search by hibernate.

the class AnalysisBuiltinIT method assertMatchQuery.

private SearchResultAssert<DocumentReference> assertMatchQuery(SimpleFieldModel<String> fieldModel, String valueToMatch) {
    StubMappingScope scope = index.createScope();
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.match().field(fieldModel.relativeFieldName).matching(valueToMatch)).toQuery();
    return assertThatQuery(query);
}
Also used : Arrays(java.util.Arrays) KeywordStringFieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.KeywordStringFieldTypeDescriptor) SimpleFieldModel(org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel) RunWith(org.junit.runner.RunWith) 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) List(java.util.List) Rule(org.junit.Rule) AnalyzerNames(org.hibernate.search.engine.backend.analysis.AnalyzerNames) 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) TckBackendHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckBackendHelper) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) SingleFieldDocumentBuilder(org.hibernate.search.util.impl.integrationtest.mapper.stub.SingleFieldDocumentBuilder) SearchResultAssert(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference)

Example 3 with SimpleFieldModel

use of org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel in project hibernate-search by hibernate.

the class AnalysisBuiltinOverrideIT method assertMatchQuery.

private SearchResultAssert<DocumentReference> assertMatchQuery(SimpleFieldModel<String> fieldModel, String valueToMatch) {
    StubMappingScope scope = index.createScope();
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.match().field(fieldModel.relativeFieldName).matching(valueToMatch)).toQuery();
    return assertThatQuery(query);
}
Also used : KeywordStringFieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.KeywordStringFieldTypeDescriptor) SimpleFieldModel(org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel) 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) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) AnalyzerNames(org.hibernate.search.engine.backend.analysis.AnalyzerNames) 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) TckBackendHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckBackendHelper) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) SingleFieldDocumentBuilder(org.hibernate.search.util.impl.integrationtest.mapper.stub.SingleFieldDocumentBuilder) SearchResultAssert(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference)

Example 4 with SimpleFieldModel

use of org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel in project hibernate-search by hibernate.

the class IndexingFieldTypesIT method withPath.

@Test
public void withPath() {
    List<F> values = new ArrayList<>(this.typeDescriptor.getIndexableValues().getSingle());
    // Also test null
    values.add(null);
    List<IdAndValue<F>> expectedDocuments = new ArrayList<>();
    SimpleFieldModel<F> fieldModel = index.binding().fieldModel;
    // Index all values, each in its own document
    IndexIndexingPlan plan = index.createIndexingPlan();
    for (int i = 0; i < values.size(); i++) {
        String documentId = "document_" + i;
        F value = values.get(i);
        plan.add(referenceProvider(documentId), document -> {
            document.addValue(fieldModel.relativeFieldName, value);
        });
        expectedDocuments.add(new IdAndValue<>(documentId, value));
    }
    plan.execute().join();
    // If we get here, indexing went well.
    // However, it may have failed silently... Let's check the documents are there, with the right value.
    StubMappingScope scope = index.createScope();
    String absoluteFieldPath = fieldModel.relativeFieldName;
    for (int i = 0; i < values.size(); i++) {
        SearchQuery<IdAndValue<F>> query = scope.query().select(f -> f.composite().from(f.entityReference(), f.field(absoluteFieldPath, typeDescriptor.getJavaType())).as((ref, val) -> new IdAndValue<>(ref.id(), val))).where(f -> f.matchAll()).toQuery();
        assertThatQuery(query).hasHitsAnyOrder(expectedDocuments);
    }
}
Also used : FieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.FieldTypeDescriptor) StubMapperUtils.referenceProvider(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapperUtils.referenceProvider) SimpleFieldModel(org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel) RunWith(org.junit.runner.RunWith) 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) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Rule(org.junit.Rule) IndexIndexingPlan(org.hibernate.search.engine.backend.work.execution.spi.IndexIndexingPlan) 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) Assume.assumeTrue(org.junit.Assume.assumeTrue) Projectable(org.hibernate.search.engine.backend.types.Projectable) TckConfiguration(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) ArrayList(java.util.ArrayList) IndexIndexingPlan(org.hibernate.search.engine.backend.work.execution.spi.IndexIndexingPlan) Test(org.junit.Test)

Aggregations

IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)4 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)4 SimpleFieldModel (org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel)4 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)4 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)4 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)4 StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)4 Before (org.junit.Before)4 Rule (org.junit.Rule)4 Test (org.junit.Test)4 List (java.util.List)3 RunWith (org.junit.runner.RunWith)3 Parameterized (org.junit.runners.Parameterized)3 ArrayList (java.util.ArrayList)2 Objects (java.util.Objects)2 AnalyzerNames (org.hibernate.search.engine.backend.analysis.AnalyzerNames)2 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)2 Projectable (org.hibernate.search.engine.backend.types.Projectable)2 IndexIndexingPlan (org.hibernate.search.engine.backend.work.execution.spi.IndexIndexingPlan)2 FieldTypeDescriptor (org.hibernate.search.integrationtest.backend.tck.testsupport.types.FieldTypeDescriptor)2