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()));
}
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()));
}
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()));
}
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()));
}
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);
}
Aggregations