use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.
the class ProgrammaticMappingSmokeIT method setup.
@Before
public void setup() {
backendMock.expectSchema(OtherIndexedEntity.INDEX, b -> b.field("numeric", Integer.class).field("numericAsString", String.class));
backendMock.expectSchema(YetAnotherIndexedEntity.INDEX, b -> b.objectField("customBridgeOnProperty", b2 -> b2.field("date", LocalDate.class).field("text", String.class)).field("myLocalDateField", LocalDate.class).field("numeric", Integer.class).objectField("embeddedIterable", b2 -> b2.multiValued(true).objectField("myEmbedded", b3 -> b3.field("myTextField", String.class))).objectField("myEmbeddedList", b2 -> b2.multiValued(true).objectField("myEmbedded", b3 -> b3.objectField("customBridgeOnClass", b4 -> b4.field("text", String.class)))).objectField("embeddedArrayList", b2 -> b2.multiValued(true).objectField("myEmbedded", b3 -> b3.objectField("customBridgeOnProperty", b4 -> b4.field("text", String.class)))).field("embeddedMapKeys", String.class, b2 -> b2.multiValued(true)).objectField("embeddedMap", b2 -> b2.multiValued(true).objectField("myEmbedded", b3 -> b3.field("myLocalDateField", LocalDate.class))));
backendMock.expectSchema(IndexedEntity.INDEX, b -> b.objectField("customBridgeOnClass", b2 -> b2.field("date", LocalDate.class).field("text", String.class)).objectField("customBridgeOnProperty", b2 -> b2.field("date", LocalDate.class).field("text", String.class)).objectField("myEmbedded", b2 -> b2.objectField("customBridgeOnClass", b3 -> b3.field("date", LocalDate.class).field("text", String.class)).objectField("customBridgeOnProperty", b3 -> b3.field("date", LocalDate.class).field("text", String.class)).objectField("myEmbedded", b3 -> b3.objectField("customBridgeOnClass", b4 -> b4.field("text", String.class))).field("myLocalDateField", LocalDate.class).field("myTextField", String.class)).field("myTextField", String.class).field("myLocalDateField", LocalDate.class));
mapping = setupHelper.start().expectCustomBeans().withConfiguration(builder -> {
builder.addEntityTypes(CollectionHelper.asSet(IndexedEntity.class, OtherIndexedEntity.class, YetAnotherIndexedEntity.class));
ProgrammaticMappingConfigurationContext mappingDefinition = builder.programmaticMapping();
TypeMappingStep indexedEntityMapping = mappingDefinition.type(IndexedEntity.class);
indexedEntityMapping.indexed().index(IndexedEntity.INDEX);
indexedEntityMapping.binder(new CustomTypeBridge.Binder().objectName("customBridgeOnClass"));
indexedEntityMapping.property("id").documentId();
indexedEntityMapping.property("text").genericField("myTextField");
indexedEntityMapping.property("embedded").indexedEmbedded("myEmbedded").includeDepth(1).includePaths("customBridgeOnClass.text", "myEmbedded.customBridgeOnClass.text");
ProgrammaticMappingConfigurationContext secondMappingDefinition = builder.programmaticMapping();
TypeMappingStep parentIndexedEntityMapping = secondMappingDefinition.type(ParentIndexedEntity.class);
parentIndexedEntityMapping.property("localDate").genericField("myLocalDateField");
parentIndexedEntityMapping.property("embedded").associationInverseSide(PojoModelPath.ofValue("embeddingAsSingle")).binder(new CustomPropertyBridge.Binder().objectName("customBridgeOnProperty"));
TypeMappingStep otherIndexedEntityMapping = secondMappingDefinition.type(OtherIndexedEntity.class);
otherIndexedEntityMapping.indexed().index(OtherIndexedEntity.INDEX);
otherIndexedEntityMapping.property("id").documentId();
otherIndexedEntityMapping.property("numeric").genericField().genericField("numericAsString").valueBridge(IntegerAsStringValueBridge.class);
TypeMappingStep yetAnotherIndexedEntityMapping = secondMappingDefinition.type(YetAnotherIndexedEntity.class);
yetAnotherIndexedEntityMapping.indexed().index(YetAnotherIndexedEntity.INDEX);
yetAnotherIndexedEntityMapping.property("id").documentId();
yetAnotherIndexedEntityMapping.property("numeric").genericField();
yetAnotherIndexedEntityMapping.property("embeddedIterable").associationInverseSide(PojoModelPath.ofValue("embeddingAsIterable")).indexedEmbedded().includePaths("myEmbedded.myTextField");
yetAnotherIndexedEntityMapping.property("embeddedList").associationInverseSide(PojoModelPath.ofValue("embeddingAsList")).indexedEmbedded("myEmbeddedList").includePaths("myEmbedded.customBridgeOnClass.text");
yetAnotherIndexedEntityMapping.property("embeddedArrayList").associationInverseSide(PojoModelPath.ofValue("embeddingAsArrayList")).indexedEmbedded().includePaths("myEmbedded.customBridgeOnProperty.text");
yetAnotherIndexedEntityMapping.property("embeddedMap").associationInverseSide(PojoModelPath.ofValue("embeddingAsMap")).genericField("embeddedMapKeys").extractor(BuiltinContainerExtractors.MAP_KEY).indexedEmbedded().includePaths("myEmbedded.myLocalDateField");
}).setup();
backendMock.verifyExpectationsMet();
}
use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.
the class ProgrammaticMappingGeoPointBindingIT method setup.
@Before
public void setup() {
backendMock.expectSchema(GeoPointOnTypeEntity.INDEX, b -> b.field("homeLocation", GeoPoint.class, b2 -> b2.projectable(Projectable.YES).sortable(Sortable.YES)).field("workLocation", GeoPoint.class, b2 -> b2.projectable(Projectable.DEFAULT).sortable(Sortable.DEFAULT)));
backendMock.expectSchema(GeoPointOnCoordinatesPropertyEntity.INDEX, b -> b.field("coord", GeoPoint.class).field("location", GeoPoint.class, b2 -> b2.projectable(Projectable.NO)));
backendMock.expectSchema(GeoPointOnCustomCoordinatesPropertyEntity.INDEX, b -> b.field("coord", GeoPoint.class, b2 -> b2.projectable(Projectable.DEFAULT).sortable(Sortable.DEFAULT)).field("location", GeoPoint.class, b2 -> b2.projectable(Projectable.DEFAULT).sortable(Sortable.DEFAULT)));
mapping = setupHelper.start().withConfiguration(builder -> {
builder.addEntityTypes(CollectionHelper.asSet(GeoPointOnTypeEntity.class, GeoPointOnCoordinatesPropertyEntity.class, GeoPointOnCustomCoordinatesPropertyEntity.class));
ProgrammaticMappingConfigurationContext mappingDefinition = builder.programmaticMapping();
TypeMappingStep geoPointOntTypeEntityMapping = mappingDefinition.type(GeoPointOnTypeEntity.class);
geoPointOntTypeEntityMapping.indexed().index(GeoPointOnTypeEntity.INDEX);
geoPointOntTypeEntityMapping.binder(GeoPointBinder.create().fieldName("homeLocation").markerSet("home").projectable(Projectable.YES).sortable(Sortable.YES));
geoPointOntTypeEntityMapping.binder(GeoPointBinder.create().fieldName("workLocation").markerSet("work"));
geoPointOntTypeEntityMapping.property("id").documentId();
geoPointOntTypeEntityMapping.property("homeLatitude").marker(GeoPointBinder.latitude().markerSet("home"));
geoPointOntTypeEntityMapping.property("homeLongitude").marker(GeoPointBinder.longitude().markerSet("home"));
geoPointOntTypeEntityMapping.property("workLatitude").marker(GeoPointBinder.latitude().markerSet("work"));
geoPointOntTypeEntityMapping.property("workLongitude").marker(GeoPointBinder.longitude().markerSet("work"));
TypeMappingStep geoPointOnCoordinatesPropertyEntityMapping = mappingDefinition.type(GeoPointOnCoordinatesPropertyEntity.class);
geoPointOnCoordinatesPropertyEntityMapping.indexed().index(GeoPointOnCoordinatesPropertyEntity.INDEX);
geoPointOnCoordinatesPropertyEntityMapping.property("id").documentId();
geoPointOnCoordinatesPropertyEntityMapping.property("coord").genericField().genericField("location").projectable(Projectable.NO);
TypeMappingStep geoPointOnCustomCoordinatesPropertyEntityMapping = mappingDefinition.type(GeoPointOnCustomCoordinatesPropertyEntity.class);
geoPointOnCustomCoordinatesPropertyEntityMapping.indexed().index(GeoPointOnCustomCoordinatesPropertyEntity.INDEX);
geoPointOnCustomCoordinatesPropertyEntityMapping.property("id").documentId();
geoPointOnCustomCoordinatesPropertyEntityMapping.property("coord").binder(GeoPointBinder.create()).binder(GeoPointBinder.create().fieldName("location"));
TypeMappingStep customCoordinatesMapping = mappingDefinition.type(CustomCoordinates.class);
customCoordinatesMapping.property("lat").marker(GeoPointBinder.latitude());
customCoordinatesMapping.property("lon").marker(GeoPointBinder.longitude());
}).setup();
backendMock.verifyExpectationsMet();
}
use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.
the class DefaultReindexOnUpdateIT method default_associationInverseSideKnown.
/**
* If ReindexOnUpdate.DEFAULT is the default,
* and the inverse side of associations is correctly set up,
* then Hibernate Search will handle embedding *and* automatic reindexing.
*/
@Test
public void default_associationInverseSideKnown() {
backendMock.expectSchema("ParentEntity", b -> b.field("value", String.class).objectField("child", b2 -> b2.field("value", String.class)));
backendMock.expectSchema("ChildEntity", b -> b.field("value", String.class));
mapping = setupHelper.start().withConfiguration(builder -> {
builder.defaultReindexOnUpdate(ReindexOnUpdate.DEFAULT);
builder.addEntityType(ParentEntity.class);
builder.addEntityType(ChildEntity.class);
ProgrammaticMappingConfigurationContext mappingDefinition = builder.programmaticMapping();
TypeMappingStep parentMapping = mappingDefinition.type(ParentEntity.class);
parentMapping.indexed();
parentMapping.property("id").documentId();
parentMapping.property("value").genericField();
parentMapping.property("child").associationInverseSide(PojoModelPath.ofValue("parent")).indexedEmbedded();
TypeMappingStep childMapping = mappingDefinition.type(ChildEntity.class);
childMapping.indexed();
childMapping.property("id").documentId();
childMapping.property("value").genericField();
}).setup();
backendMock.verifyExpectationsMet();
ParentEntity parent = new ParentEntity();
parent.id = 1;
parent.value = "val1";
ChildEntity child = new ChildEntity();
child.id = 2;
child.value = "val2";
parent.child = child;
child.parent = parent;
// Test indexed-embedding
try (SearchSession session = mapping.createSession()) {
session.indexingPlan().add(parent);
backendMock.expectWorks("ParentEntity").add("1", b -> b.field("value", "val1").objectField("child", b2 -> b2.field("value", "val2")));
}
// Test automatic reindexing
try (SearchSession session = mapping.createSession()) {
session.indexingPlan().addOrUpdate(child);
backendMock.expectWorks("ChildEntity").addOrUpdate("2", b -> b.field("value", "val2"));
// The child was updated, thus the parent (which index-embeds the childs) is reindexed.
backendMock.expectWorks("ParentEntity").addOrUpdate("1", b -> b.field("value", "val1").objectField("child", b2 -> b2.field("value", "val2")));
}
}
use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project infinispan by infinispan.
the class SerializationContextSearchMapping method createBuilder.
public static SearchMappingBuilder createBuilder(SearchMappingCommonBuilding commonBuilding, EntityLoader<EntityReference, ?> entityLoader, Set<String> indexedEntityTypes, SerializationContext serializationContext) {
GlobalReferenceHolder globalReferenceHolder = new GlobalReferenceHolder(serializationContext.getGenericDescriptors());
ProtobufBootstrapIntrospector introspector = new ProtobufBootstrapIntrospector();
SearchMappingBuilder builder = commonBuilding.builder(introspector);
builder.setEntityLoader(entityLoader);
builder.setEntityConverter(new ProtobufEntityConverter(serializationContext, globalReferenceHolder.getRootMessages()));
ProgrammaticMappingConfigurationContext programmaticMapping = builder.programmaticMapping();
boolean existIndexedEntities = false;
for (GlobalReferenceHolder.RootMessageInfo rootMessage : globalReferenceHolder.getRootMessages()) {
String fullName = rootMessage.getFullName();
if (!indexedEntityTypes.contains(fullName)) {
continue;
}
existIndexedEntities = true;
programmaticMapping.type(fullName).binder(new ProtobufMessageBinder(globalReferenceHolder, fullName)).indexed().index(rootMessage.getIndexName());
builder.addEntityType(byte[].class, fullName);
}
return existIndexedEntities ? builder : null;
}
use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.
the class DocumentationSetupHelper method testParamsForBothAnnotationsAndProgrammatic.
public static List<DocumentationSetupHelper> testParamsForBothAnnotationsAndProgrammatic(BackendConfiguration backendConfiguration, Consumer<ProgrammaticMappingConfigurationContext> programmaticMappingContributor) {
HibernateOrmSearchMappingConfigurer mappingConfigurer = context -> programmaticMappingContributor.accept(context.programmaticMapping());
List<DocumentationSetupHelper> result = new ArrayList<>();
// Annotation-based mapping
result.add(withSingleBackend(backendConfiguration, null));
// Programmatic mapping
result.add(withSingleBackend(backendConfiguration, mappingConfigurer));
return result;
}
Aggregations