use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.
the class IndexedEmbeddedBaseIT method multiValued.
/**
* Check @IndexedEmbedded on a multi-valued property
* results in the corresponding object field being automatically marked as multi-valued
* (and not its own fields).
*/
@Test
@TestForIssue(jiraKey = "HSEARCH-3324")
public void multiValued() {
class IndexedEmbeddedLevel1 {
@GenericField
String level1SingleValuedProperty;
@GenericField
List<String> level1MultiValuedProperty;
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
@IndexedEmbedded
List<IndexedEmbeddedLevel1> level1 = new ArrayList<>();
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.multiValued(true).field("level1SingleValuedProperty", String.class).field("level1MultiValuedProperty", String.class, b3 -> b3.multiValued(true))));
SearchMapping mapping = setupHelper.start().withAnnotatedEntityTypes(IndexedEntity.class).withAnnotatedTypes(IndexedEmbeddedLevel1.class).setup();
backendMock.verifyExpectationsMet();
doTestEmbeddedRuntime(mapping, id -> {
IndexedEntity entity = new IndexedEntity();
entity.id = id;
IndexedEmbeddedLevel1 level1_1 = new IndexedEmbeddedLevel1();
level1_1.level1SingleValuedProperty = "1";
level1_1.level1MultiValuedProperty = Arrays.asList("1_1", "1_2");
entity.level1.add(level1_1);
IndexedEmbeddedLevel1 level1_2 = new IndexedEmbeddedLevel1();
level1_2.level1SingleValuedProperty = "2";
level1_2.level1MultiValuedProperty = Arrays.asList("2_1", "2_2");
entity.level1.add(level1_2);
return entity;
}, document -> document.objectField("level1", b2 -> b2.field("level1SingleValuedProperty", "1").field("level1MultiValuedProperty", "1_1", "1_2")).objectField("level1", b2 -> b2.field("level1SingleValuedProperty", "2").field("level1MultiValuedProperty", "2_1", "2_2")));
}
use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.
the class IndexedEmbeddedBaseIT method includeDepth.
/**
* Check that the "includeDepth" 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 includeDepth() {
class IndexedEmbeddedLevel2 {
String level2Property;
@GenericField
public String getLevel2Property() {
return level2Property;
}
}
class IndexedEmbeddedLevel1 {
String level1Property;
IndexedEmbeddedLevel2 level2;
@GenericField
public String getLevel1Property() {
return level1Property;
}
@IndexedEmbedded
public IndexedEmbeddedLevel2 getLevel2() {
return level2;
}
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
@IndexedEmbedded(includeDepth = 1)
IndexedEmbeddedLevel1 level1;
public IndexedEntity(int id, String level1Value, String level2Value) {
this.id = id;
this.level1 = new IndexedEmbeddedLevel1();
this.level1.level1Property = level1Value;
this.level1.level2 = new IndexedEmbeddedLevel2();
this.level1.level2.level2Property = level2Value;
}
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.field("level1Property", String.class)));
SearchMapping mapping = setupHelper.start().withAnnotatedEntityTypes(IndexedEntity.class).withAnnotatedTypes(IndexedEmbeddedLevel1.class, IndexedEmbeddedLevel2.class).setup();
backendMock.verifyExpectationsMet();
doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, "level1Value", "level2Value"), document -> document.objectField("level1", b2 -> b2.field("level1Property", "level1Value")));
}
use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.
the class IndexedEmbeddedBaseIT method includeEmbeddedObjectId_identifierBridge.
@Test
@TestForIssue(jiraKey = "HSEARCH-3071")
public void includeEmbeddedObjectId_identifierBridge() {
class IndexedEmbeddedLevel1 {
@DocumentId(identifierBridge = @IdentifierBridgeRef(type = MyCustomIdentifierBinder.Bridge.class))
Long theId;
@AssociationInverseSide(inversePath = @ObjectPath(@PropertyValue(propertyName = "level1")))
Object containing;
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
@IndexedEmbedded(includeEmbeddedObjectId = true)
IndexedEmbeddedLevel1 level1;
public IndexedEntity(int id, Long level1Id) {
this.id = id;
this.level1 = new IndexedEmbeddedLevel1();
this.level1.theId = level1Id;
this.level1.containing = this;
}
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.field("theId", String.class, b3 -> b3.searchable(Searchable.YES).projectable(Projectable.YES))));
SearchMapping mapping = setupHelper.start().expectCustomBeans().setup(IndexedEntity.class, IndexedEmbeddedLevel1.class);
backendMock.verifyExpectationsMet();
doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, 4242L), document -> document.objectField("level1", b2 -> b2.field("theId", "4243")));
}
use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.
the class IndexedEmbeddedBaseIT method includeEmbeddedObjectId_noIdentifierBridge.
@Test
@TestForIssue(jiraKey = "HSEARCH-3071")
public void includeEmbeddedObjectId_noIdentifierBridge() {
class IndexedEmbeddedLevel1 {
@DocumentId
Long theId;
@AssociationInverseSide(inversePath = @ObjectPath(@PropertyValue(propertyName = "level1")))
Object containing;
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
@IndexedEmbedded(includeEmbeddedObjectId = true)
IndexedEmbeddedLevel1 level1;
public IndexedEntity(int id, Long level1Id) {
this.id = id;
this.level1 = new IndexedEmbeddedLevel1();
this.level1.theId = level1Id;
this.level1.containing = this;
}
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("level1", b2 -> b2.field("theId", Long.class, b3 -> b3.searchable(Searchable.YES).projectable(Projectable.YES))));
SearchMapping mapping = setupHelper.start().setup(IndexedEntity.class, IndexedEmbeddedLevel1.class);
backendMock.verifyExpectationsMet();
doTestEmbeddedRuntime(mapping, id -> new IndexedEntity(id, 4242L), document -> document.objectField("level1", b2 -> b2.field("theId", 4242L)));
}
use of org.hibernate.search.mapper.javabean.mapping.SearchMapping in project hibernate-search by hibernate.
the class IndexedEmbeddedBaseIT method name.
@Test
public void name() {
class IndexedEmbeddedLevel1 {
@GenericField
String level1Property;
}
@Indexed(index = INDEX_NAME)
class IndexedEntity {
@DocumentId
Integer id;
@IndexedEmbedded(name = "explicitName")
IndexedEmbeddedLevel1 level1;
public IndexedEntity(int id, String value) {
this.id = id;
this.level1 = new IndexedEmbeddedLevel1();
this.level1.level1Property = value;
}
}
backendMock.expectSchema(INDEX_NAME, b -> b.objectField("explicitName", b2 -> b2.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("explicitName", b2 -> b2.field("level1Property", "level1Value")));
}
Aggregations