Search in sources :

Example 1 with IndexSchemaElement

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement in project hibernate-search by hibernate.

the class InvoiceLineItemsDetailBinder method bind.

// tag::bind[]
@Override
public void bind(PropertyBindingContext context) {
    context.dependencies().use("category").use("amount");
    // tag::bind[]
    IndexSchemaElement schemaElement = context.indexSchemaElement();
    IndexSchemaObjectField lineItemsField = // <1>
    schemaElement.objectField(// <2>
    "lineItems", // <3>
    ObjectStructure.NESTED).multiValued();
    context.bridge(List.class, new Bridge(// <5>
    lineItemsField.toReference(), // <6>
    lineItemsField.field("category", f -> f.asString()).toReference(), // <7>
    lineItemsField.field("amount", f -> f.asBigDecimal().decimalScale(2)).toReference()));
}
Also used : BigDecimal(java.math.BigDecimal) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) PropertyBridge(org.hibernate.search.mapper.pojo.bridge.PropertyBridge) PropertyBindingContext(org.hibernate.search.mapper.pojo.bridge.binding.PropertyBindingContext) PropertyBinder(org.hibernate.search.mapper.pojo.bridge.mapping.programmatic.PropertyBinder) PropertyBridgeWriteContext(org.hibernate.search.mapper.pojo.bridge.runtime.PropertyBridgeWriteContext) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) PropertyBridge(org.hibernate.search.mapper.pojo.bridge.PropertyBridge)

Example 2 with IndexSchemaElement

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement in project hibernate-search by hibernate.

the class MultiValuedNamesBinder method bind.

// tag::bind[]
@Override
public void bind(TypeBindingContext context) {
    context.dependencies().use("firstName").use("lastName");
    // tag::bind[]
    IndexSchemaElement schemaElement = context.indexSchemaElement();
    context.bridge(Author.class, new Bridge(schemaElement.field("names", f -> f.asString().analyzer("name")).multiValued().toReference()));
}
Also used : IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) TypeBridge(org.hibernate.search.mapper.pojo.bridge.TypeBridge)

Example 3 with IndexSchemaElement

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement in project hibernate-search by hibernate.

the class SingleValuedNamesBinder method bind.

// tag::bind[]
@Override
public void bind(TypeBindingContext context) {
    context.dependencies().use("firstName").use("lastName");
    // tag::bind[]
    IndexSchemaElement schemaElement = context.indexSchemaElement();
    IndexFieldType<String> nameType = // <1>
    context.typeFactory().asString().analyzer("name").toIndexFieldType();
    context.bridge(Author.class, new Bridge(// <4>
    schemaElement.field("firstName", nameType).toReference(), // <4>
    schemaElement.field("lastName", nameType).toReference(), // <4>
    schemaElement.field("fullName", nameType).toReference()));
}
Also used : IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) TypeBridge(org.hibernate.search.mapper.pojo.bridge.TypeBridge)

Example 4 with IndexSchemaElement

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement in project hibernate-search by hibernate.

the class UserMetadataBinder method bind.

@Override
public void bind(PropertyBindingContext context) {
    context.dependencies().useRootOnly();
    // tag::bind[]
    IndexSchemaElement schemaElement = context.indexSchemaElement();
    IndexSchemaObjectField userMetadataField = // <1>
    schemaElement.objectField("userMetadata");
    // <2>
    userMetadataField.fieldTemplate(// <3>
    "userMetadataValueTemplate", // <4>
    f -> f.asString().analyzer("english"));
    // <5>
    // <6>
    context.bridge(Map.class, new UserMetadataBridge(userMetadataField.toReference()));
}
Also used : IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)

Example 5 with IndexSchemaElement

use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement in project hibernate-search by hibernate.

the class FieldTemplateIT method simple.

@Test
@TestForIssue(jiraKey = "HSEARCH-3273")
public void simple() {
    Consumer<IndexSchemaElement> templatesBinder = root -> {
        IndexSchemaFieldTemplateOptionsStep<?> step = root.fieldTemplate("myTemplate", f -> f.asString());
        if (fieldStructure.isMultiValued()) {
            step.multiValued();
        }
    };
    StubMapping mapping = setup(StubMappingSchemaManagementStrategy.DROP_AND_CREATE_ON_STARTUP_ONLY, templatesBinder);
    // Index a few documents
    index.bulkIndexer().add(EMPTY, document -> {
    }).add(DOCUMENT_1, document -> initDocument(document, "foo", "matchedValue", "notMatchedValue1", "notMatchedValue2")).add(DOCUMENT_2, document -> initDocument(document, "foo", "notMatchedValue1", "notMatchedValue1", "matchedValue")).join();
    // Check that documents are indexed and the dynamic field can be searched
    assertThatQuery(query(f -> f.match().field(getFieldPath("foo")).matching("matchedValue"))).hasDocRefHitsAnyOrder(index.typeName(), DOCUMENT_1);
    // Try again with a clean Hibernate Search instance, where local schema caches are empty
    mapping.close();
    setup(StubMappingSchemaManagementStrategy.DROP_ON_SHUTDOWN_ONLY, templatesBinder);
    assertThatQuery(query(f -> f.match().field(getFieldPath("foo")).matching("matchedValue"))).hasDocRefHitsAnyOrder(index.typeName(), DOCUMENT_1);
}
Also used : IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) IndexFieldLocation(org.hibernate.search.integrationtest.backend.tck.testsupport.util.IndexFieldLocation) StubMapping(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapping) RunWith(org.junit.runner.RunWith) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) Function(java.util.function.Function) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) ArrayList(java.util.ArrayList) PredicateFinalStep(org.hibernate.search.engine.search.predicate.dsl.PredicateFinalStep) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) Parameterized(org.junit.runners.Parameterized) SearchPredicateFactory(org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory) StubMappingSchemaManagementStrategy(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingSchemaManagementStrategy) Test(org.junit.Test) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) Consumer(java.util.function.Consumer) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) IndexSchemaFieldTemplateOptionsStep(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaFieldTemplateOptionsStep) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Rule(org.junit.Rule) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) TestedFieldStructure(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TestedFieldStructure) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) StubMapping(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapping) IndexSchemaFieldTemplateOptionsStep(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaFieldTemplateOptionsStep) Test(org.junit.Test) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue)

Aggregations

IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)19 IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)15 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)13 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)12 Consumer (java.util.function.Consumer)11 ObjectStructure (org.hibernate.search.engine.backend.types.ObjectStructure)11 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)11 Rule (org.junit.Rule)11 Test (org.junit.Test)11 Function (java.util.function.Function)10 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)10 PredicateFinalStep (org.hibernate.search.engine.search.predicate.dsl.PredicateFinalStep)10 SearchPredicateFactory (org.hibernate.search.engine.search.predicate.dsl.SearchPredicateFactory)10 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)10 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)10 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)10 StubMapping (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapping)10 StubMappingSchemaManagementStrategy (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingSchemaManagementStrategy)10 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)10 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)8