use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField in project hibernate-search by hibernate.
the class ElasticsearchIndexSchemaManagerValidationMappingBaseIT method nestedProperty_attribute_invalid.
/**
* Tests that properties within properties are correctly represented in the failure report.
*/
@Test
public void nestedProperty_attribute_invalid() {
StubMappedIndex index = StubMappedIndex.ofNonRetrievable(root -> {
IndexSchemaObjectField objectField = root.objectField("myObjectField");
objectField.field("myField", f -> f.asLocalDate()).toReference();
objectField.toReference();
});
elasticSearchClient.index(index.name()).deleteAndCreate();
elasticSearchClient.index(index.name()).type().putMapping(simpleMappingForInitialization("'myObjectField': {" + "'type': 'object'," + "'dynamic': 'strict'," + "'properties': {" + "'myField': {" + "'type': 'date'," + "'format': '" + elasticSearchClient.getDialect().getConcatenatedLocalDateDefaultMappingFormats() + "'," + "'index': false" + "}" + "}" + "}"));
setupAndValidateExpectingFailure(index, hasValidationFailureReport().indexFieldContext("myObjectField.myField").mappingAttributeContext("index").failure("Invalid value. Expected 'true', actual is 'false'"));
}
use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField 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.IndexSchemaObjectField 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.IndexSchemaObjectField in project hibernate-search by hibernate.
the class IndexSchemaElementImpl method objectField.
@Override
public IndexSchemaObjectField objectField(String relativeFieldName, ObjectStructure structure) {
checkRelativeFieldName(relativeFieldName);
IndexSchemaObjectField objectField = nestingContext.nest(relativeFieldName, (prefixedName, inclusion, nestedNestingContext) -> {
IndexObjectFieldBuilder objectFieldBuilder = this.objectNodeBuilder.addObjectField(prefixedName, inclusion, structure);
return new IndexSchemaObjectFieldImpl(typeFactory, objectFieldBuilder, nestedNestingContext, false);
});
if (directChildrenAreMultiValuedByDefault) {
objectField.multiValued();
}
return objectField;
}
use of org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField in project hibernate-search by hibernate.
the class PropertyBridgeBaseIT method objectField.
/**
* Test that object field definitions are forwarded to the backend.
*/
@Test
@TestForIssue(jiraKey = "HSEARCH-3324")
public void objectField() {
class Contained {
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
Contained contained;
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("stringFromBridge", b2 -> b2.field("value", String.class)).objectField("listFromBridge", b2 -> b2.objectStructure(ObjectStructure.NESTED).multiValued(true).field("value", Integer.class)));
SearchMapping mapping = setupHelper.start().withConfiguration(b -> b.programmaticMapping().type(IndexedEntity.class).property("contained").binder(context -> {
context.dependencies().useRootOnly();
// Single-valued field
IndexSchemaObjectField stringObjectField = context.indexSchemaElement().objectField("stringFromBridge");
stringObjectField.toReference();
stringObjectField.field("value", f -> f.asString()).toReference();
// Multi-valued field
IndexSchemaObjectField listObjectField = context.indexSchemaElement().objectField("listFromBridge", ObjectStructure.NESTED).multiValued();
listObjectField.toReference();
listObjectField.field("value", f -> f.asInteger()).toReference();
context.bridge(new UnusedPropertyBridge());
})).setup(IndexedEntity.class);
backendMock.verifyExpectationsMet();
}
Aggregations