use of org.hibernate.search.engine.backend.types.ObjectStructure 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();
}
use of org.hibernate.search.engine.backend.types.ObjectStructure in project hibernate-search by hibernate.
the class IndexedEmbeddedBaseIT method structure.
/**
* Check that the "structure" parameter is at least taken into account.
* <p>
* Details of how filtering handles all corner cases is tested in the engine (see this class' javadoc).
*/
@Test
public void structure() {
class IndexedEmbeddedLevel1 {
@GenericField
String level1Property;
public String getLevel1Property() {
return level1Property;
}
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
@IndexedEmbedded(structure = ObjectStructure.NESTED)
IndexedEmbeddedLevel1 level1;
public IndexedEntity(int id, String level1Value) {
this.id = id;
this.level1 = new IndexedEmbeddedLevel1();
this.level1.level1Property = level1Value;
}
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.objectStructure(ObjectStructure.NESTED).field("level1Property", String.class)));
SearchMapping mapping = setupHelper.start().withAnnotatedEntityTypes(IndexedEntity.class).withAnnotatedTypes(IndexedEmbeddedLevel1.class).setup();
backendMock.verifyExpectationsMet();
doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, "level1Value"), document -> document.objectField("level1", b2 -> b2.field("level1Property", "level1Value")));
}
use of org.hibernate.search.engine.backend.types.ObjectStructure in project hibernate-search by hibernate.
the class TypeBridgeBaseIT method objectFieldTemplate.
/**
* Test that object field template definitions are forwarded to the backend.
*/
@Test
@TestForIssue(jiraKey = "HSEARCH-3273")
public void objectFieldTemplate() {
class Contained {
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
@IndexedEmbedded
Contained contained;
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("contained", b2 -> b2.objectFieldTemplate("stringFromBridge", b3 -> b3.matchingPathGlob("*_string")).fieldTemplate("stringFromBridge_value", String.class, b3 -> b3.matchingPathGlob("*_string.value")).objectFieldTemplate("listFromBridge", b3 -> b3.objectStructure(ObjectStructure.NESTED).multiValued(true).matchingPathGlob("*_list")).fieldTemplate("listFromBridge_value", Integer.class, b3 -> b3.matchingPathGlob("*_list.value"))));
SearchMapping mapping = setupHelper.start().withConfiguration(b -> b.programmaticMapping().type(Contained.class).binder((TypeBinder) context -> {
context.dependencies().useRootOnly();
context.indexSchemaElement().objectFieldTemplate("stringFromBridge").matchingPathGlob("*_string");
context.indexSchemaElement().fieldTemplate("stringFromBridge_value", f -> f.asString()).matchingPathGlob("*_string.value");
context.indexSchemaElement().objectFieldTemplate("listFromBridge", ObjectStructure.NESTED).matchingPathGlob("*_list").multiValued();
context.indexSchemaElement().fieldTemplate("listFromBridge_value", f -> f.asInteger()).matchingPathGlob("*_list.value");
context.bridge(new UnusedTypeBridge());
})).setup(IndexedEntity.class);
backendMock.verifyExpectationsMet();
}
use of org.hibernate.search.engine.backend.types.ObjectStructure in project hibernate-search by hibernate.
the class TypeBridgeBaseIT 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;
@IndexedEmbedded
Contained contained;
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("contained", b2 -> b2.objectField("stringFromBridge", b3 -> b3.field("value", String.class)).objectField("listFromBridge", b3 -> b3.objectStructure(ObjectStructure.NESTED).multiValued(true).field("value", Integer.class))));
SearchMapping mapping = setupHelper.start().withConfiguration(b -> b.programmaticMapping().type(Contained.class).binder((TypeBinder) context -> {
context.dependencies().useRootOnly();
IndexSchemaObjectField stringObjectField = context.indexSchemaElement().objectField("stringFromBridge");
stringObjectField.toReference();
stringObjectField.field("value", f -> f.asString()).toReference();
IndexSchemaObjectField listObjectField = context.indexSchemaElement().objectField("listFromBridge", ObjectStructure.NESTED).multiValued();
listObjectField.toReference();
listObjectField.field("value", f -> f.asInteger()).toReference();
context.bridge(new UnusedTypeBridge());
})).setup(IndexedEntity.class);
backendMock.verifyExpectationsMet();
}
use of org.hibernate.search.engine.backend.types.ObjectStructure in project hibernate-search by hibernate.
the class PropertyBridgeBaseIT method objectFieldTemplate.
/**
* Test that object field template definitions are forwarded to the backend.
*/
@Test
@TestForIssue(jiraKey = "HSEARCH-3273")
public void objectFieldTemplate() {
class Contained {
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
Contained contained;
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectFieldTemplate("stringFromBridge", b2 -> b2.matchingPathGlob("*_string")).fieldTemplate("stringFromBridge_value", String.class, b2 -> b2.matchingPathGlob("*_string.value")).objectFieldTemplate("listFromBridge", b2 -> b2.objectStructure(ObjectStructure.NESTED).multiValued(true).matchingPathGlob("*_list")).fieldTemplate("listFromBridge_value", Integer.class, b2 -> b2.matchingPathGlob("*_list.value")));
SearchMapping mapping = setupHelper.start().withConfiguration(b -> b.programmaticMapping().type(IndexedEntity.class).property("contained").binder(context -> {
context.dependencies().useRootOnly();
// Single-valued field
context.indexSchemaElement().objectFieldTemplate("stringFromBridge").matchingPathGlob("*_string");
context.indexSchemaElement().fieldTemplate("stringFromBridge_value", f -> f.asString()).matchingPathGlob("*_string.value");
// Multi-valued field
context.indexSchemaElement().objectFieldTemplate("listFromBridge", ObjectStructure.NESTED).matchingPathGlob("*_list").multiValued();
context.indexSchemaElement().fieldTemplate("listFromBridge_value", f -> f.asInteger()).matchingPathGlob("*_list.value");
context.bridge(new UnusedPropertyBridge());
})).setup(IndexedEntity.class);
backendMock.verifyExpectationsMet();
}
Aggregations