use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.
the class MySearchMappingConfigurer method configure.
@Override
public void configure(HibernateOrmMappingConfigurationContext context) {
// <1>
ProgrammaticMappingConfigurationContext mapping = context.programmaticMapping();
// <2>
TypeMappingStep bookMapping = mapping.type(Book.class);
// <3>
bookMapping.indexed();
// <4>
bookMapping.property("title").fullTextField().analyzer(// <5>
"english");
}
use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.
the class ProgrammaticMappingAccessTypeIT method setup.
@Before
public void setup() {
backendMock.expectSchema(IndexedEntity.NAME, b -> b.field("propertyWithGetterAndFieldDeclaredInParent", String.class).field("propertyWithFieldDeclaredInParent", String.class).field("propertyWithFieldDeclaredInParentThenGetterInChild", String.class).field("propertyWithGetterAndFieldDeclaredInParentThenOverridden", String.class).field("propertyWithGetterDeclaredAbstractInParent", String.class).field("propertyWithGetterAndField", String.class).field("propertyWithFieldOnly", String.class).field("propertyWithGetterAndDifferentlyNamedField", String.class));
mapping = setupHelper.start().withConfiguration(b -> {
ProgrammaticMappingConfigurationContext mapping = b.programmaticMapping();
TypeMappingStep indexedEntityMapping = mapping.type(IndexedEntity.class);
indexedEntityMapping.indexed().index(IndexedEntity.NAME);
indexedEntityMapping.property("id").documentId();
indexedEntityMapping.property("propertyWithGetterAndFieldDeclaredInParent").genericField();
indexedEntityMapping.property("propertyWithFieldDeclaredInParent").genericField();
indexedEntityMapping.property("propertyWithFieldDeclaredInParentThenGetterInChild").genericField();
indexedEntityMapping.property("propertyWithGetterAndFieldDeclaredInParentThenOverridden").genericField();
indexedEntityMapping.property("propertyWithGetterDeclaredAbstractInParent").genericField();
indexedEntityMapping.property("propertyWithGetterAndField").genericField();
indexedEntityMapping.property("propertyWithFieldOnly").genericField();
indexedEntityMapping.property("propertyWithGetterAndDifferentlyNamedField").genericField();
}).setup(IndexedEntity.class, ParentIndexedEntity.class);
backendMock.verifyExpectationsMet();
}
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(BackendSetupStrategy backendSetupStrategy, BackendConfiguration defaultBackendConfiguration, Set<Class<?>> additionalAnnotatedClasses, Consumer<ProgrammaticMappingConfigurationContext> programmaticMappingContributor) {
List<DocumentationSetupHelper> result = new ArrayList<>();
// Annotation-based mapping
HibernateOrmSearchMappingConfigurer annotationMappingConfigurer = additionalAnnotatedClasses.isEmpty() ? null : context -> context.annotationMapping().add(additionalAnnotatedClasses);
result.add(new DocumentationSetupHelper(backendSetupStrategy, null, annotationMappingConfigurer));
// Programmatic mapping
HibernateOrmSearchMappingConfigurer programmaticMappingConfigurer = context -> programmaticMappingContributor.accept(context.programmaticMapping());
result.add(new DocumentationSetupHelper(backendSetupStrategy, false, programmaticMappingConfigurer));
return result;
}
use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.
the class DefaultReindexOnUpdateIT method no_associationInverseSideUnknown.
/**
* If ReindexOnUpdate.NO is the default,
* even if the inverse side of associations is not correctly set up,
* then Hibernate Search will handle embedding, but not automatic reindexing.
*/
@Test
public void no_associationInverseSideUnknown() {
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.NO);
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").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, but automatic reindexing is disabled,
// thus the parent (which index-embeds the childs) will NOT be reindexed.
}
}
use of org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext in project hibernate-search by hibernate.
the class DefaultReindexOnUpdateIT method default_associationInverseSideUnknown.
/**
* If ReindexOnUpdate.DEFAULT is the default,
* and the inverse side of associations is NOT correctly set up,
* then Hibernate Search bootstrap will fail.
*/
@Test
public void default_associationInverseSideUnknown() {
assertThatThrownBy(() -> 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").indexedEmbedded();
TypeMappingStep childMapping = mappingDefinition.type(ChildEntity.class);
childMapping.indexed();
childMapping.property("id").documentId();
childMapping.property("value").genericField();
}).setup()).isInstanceOf(SearchException.class).satisfies(FailureReportUtils.hasFailureReport().typeContext(ParentEntity.class.getName()).pathContext(".child<no value extractors>.value<no value extractors>").failure("Unable to find the inverse side of the association on type '" + ParentEntity.class.getName() + "'" + " at path '.child<no value extractors>'", "Hibernate Search needs this information in order to reindex '" + ParentEntity.class.getName() + "' when '" + ChildEntity.class.getName() + "' is modified."));
}
Aggregations