use of org.hibernate.search.mapper.javabean.common.EntityReference in project hibernate-search by hibernate.
the class SearchTimeoutIT method failAfter.
@Test
public void failAfter() {
try (SearchSession session = mapping.createSession()) {
SearchQuery<EntityReference> query = session.search(IndexedEntity.class).selectEntityReference().where(f -> f.matchAll()).failAfter(5L, TimeUnit.SECONDS).toQuery();
SearchException timeoutException = new SearchException("Timed out");
backendMock.expectSearchReferences(Collections.singletonList(INDEX_NAME), // timeout is supposed to be set on the backend
b -> b.failAfter(5L, TimeUnit.SECONDS), StubSearchWorkBehavior.failing(() -> timeoutException));
// Just check that the exception is propagated
assertThatThrownBy(() -> query.fetchAll()).isSameAs(timeoutException);
}
}
use of org.hibernate.search.mapper.javabean.common.EntityReference in project hibernate-search by hibernate.
the class AnnotationMappingSmokeIT method search_multipleElementsProjection.
@Test
public void search_multipleElementsProjection() {
SearchScope<ParentIndexedEntity> scope = mapping.scope(Arrays.asList(IndexedEntity.class, YetAnotherIndexedEntity.class));
try (SearchSession session = mapping.createSession()) {
SearchQuery<List<?>> query = session.search(scope).select(scope.projection().field("myTextField", String.class).toProjection(), scope.projection().entityReference().toProjection(), scope.projection().id().toProjection(), scope.projection().field("myLocalDateField", LocalDate.class).toProjection(), scope.projection().documentReference().toProjection(), scope.projection().field("customBridgeOnClass.text", String.class).toProjection()).where(f -> f.matchAll()).toQuery();
backendMock.expectSearchProjection(Arrays.asList(IndexedEntity.INDEX, YetAnotherIndexedEntity.INDEX), StubSearchWorkBehavior.of(2L, Arrays.asList("text1", reference(IndexedEntity.INDEX, "0"), reference(IndexedEntity.INDEX, "0"), LocalDate.of(2017, 11, 1), reference(IndexedEntity.INDEX, "0"), "text2"), Arrays.asList(null, reference(YetAnotherIndexedEntity.INDEX, "1"), reference(YetAnotherIndexedEntity.INDEX, "1"), LocalDate.of(2017, 11, 2), reference(YetAnotherIndexedEntity.INDEX, "1"), null)));
SearchResult<List<?>> result = query.fetchAll();
assertThat(result.hits()).containsExactly(Arrays.asList("text1", EntityReferenceImpl.withDefaultName(IndexedEntity.class, 0), 0, LocalDate.of(2017, 11, 1), reference(IndexedEntity.INDEX, "0"), "text2"), Arrays.asList(null, EntityReferenceImpl.withDefaultName(YetAnotherIndexedEntity.class, 1), 1, LocalDate.of(2017, 11, 2), reference(YetAnotherIndexedEntity.INDEX, "1"), null));
assertThat(result.total().hitCount()).isEqualTo(2L);
backendMock.verifyExpectationsMet();
}
}
use of org.hibernate.search.mapper.javabean.common.EntityReference in project hibernate-search by hibernate.
the class DocumentIdBaseIT method customBridge_withParams_programmaticMapping.
@Test
public void customBridge_withParams_programmaticMapping() {
class IndexedEntity {
Integer id;
String value;
IndexedEntity(Integer id, String value) {
this.id = id;
this.value = value;
}
}
backendMock.expectSchema(INDEX_NAME, b -> b.field("value", String.class));
SearchMapping mapping = setupHelper.start().withConfiguration(builder -> {
builder.addEntityType(IndexedEntity.class);
TypeMappingStep indexedEntity = builder.programmaticMapping().type(IndexedEntity.class);
indexedEntity.indexed().index(INDEX_NAME);
indexedEntity.property("id").documentId().identifierBinder(new ParametricBridge.ParametricBinder(), Collections.singletonMap("fixedPrefix", "fixed-prefix-"));
indexedEntity.property("value").genericField();
}).expectCustomBeans().setup(IndexedEntity.class);
backendMock.verifyExpectationsMet();
try (SearchSession session = mapping.createSession()) {
IndexedEntity entity = new IndexedEntity(1, "bla-bla-bla");
session.indexingPlan().add(entity);
backendMock.expectWorks(INDEX_NAME).add("fixed-prefix-1", b -> b.field("value", "bla-bla-bla"));
}
backendMock.verifyExpectationsMet();
try (SearchSession session = mapping.createSession()) {
backendMock.expectSearchReferences(Collections.singletonList(INDEX_NAME), StubSearchWorkBehavior.of(1L, StubBackendUtils.reference("IndexedEntity", "fixed-prefix-1")));
SearchQuery<EntityReference> query = session.search(IndexedEntity.class).selectEntityReference().where(f -> f.matchAll()).toQuery();
assertThat(query.fetchAll().hits()).containsExactly(EntityReferenceImpl.withName(IndexedEntity.class, "IndexedEntity", 1));
}
backendMock.verifyExpectationsMet();
}
use of org.hibernate.search.mapper.javabean.common.EntityReference in project hibernate-search by hibernate.
the class DocumentIdDefaultBridgeOverridingIT method projection_entityReference.
@Test
public void projection_entityReference() {
try (SearchSession session = mapping.createSession()) {
backendMock.expectSearchReferences(Collections.singletonList(DefaultIdentifierBridgeExpectations.TYPE_WITH_IDENTIFIER_BRIDGE_1_NAME), StubSearchWorkBehavior.of(1L, StubBackendUtils.reference(DefaultIdentifierBridgeExpectations.TYPE_WITH_IDENTIFIER_BRIDGE_1_NAME, getDocumentIdentifierValue())));
SearchQuery<EntityReference> query = session.search(expectations.getTypeWithIdentifierBridge1()).selectEntityReference().where(f -> f.matchAll()).toQuery();
assertThat(query.fetchAll().hits()).containsExactly(EntityReferenceImpl.withName(expectations.getTypeWithIdentifierBridge1(), DefaultIdentifierBridgeExpectations.TYPE_WITH_IDENTIFIER_BRIDGE_1_NAME, getEntityIdentifierValue()));
backendMock.verifyExpectationsMet();
}
}
use of org.hibernate.search.mapper.javabean.common.EntityReference in project hibernate-search by hibernate.
the class ProvidedIdIT method indexAndSearch.
@Test
public void indexAndSearch() {
final String entityAndIndexName = "indexed";
@Indexed
class IndexedEntity {
}
// Schema
backendMock.expectSchema(entityAndIndexName, b -> {
});
SearchMapping mapping = withBaseConfiguration().withAnnotatedEntityType(IndexedEntity.class, entityAndIndexName).setup();
backendMock.verifyExpectationsMet();
// Indexing
try (SearchSession session = mapping.createSession()) {
IndexedEntity entity1 = new IndexedEntity();
session.indexingPlan().add("42", null, entity1);
backendMock.expectWorks(entityAndIndexName).add("42", b -> {
});
}
backendMock.verifyExpectationsMet();
// Searching
try (SearchSession session = mapping.createSession()) {
backendMock.expectSearchReferences(Collections.singletonList(entityAndIndexName), StubSearchWorkBehavior.of(1L, StubBackendUtils.reference(entityAndIndexName, "42")));
SearchQuery<EntityReference> query = session.search(IndexedEntity.class).selectEntityReference().where(f -> f.matchAll()).toQuery();
assertThat(query.fetchAll().hits()).containsExactly(EntityReferenceImpl.withName(IndexedEntity.class, entityAndIndexName, "42"));
}
backendMock.verifyExpectationsMet();
}
Aggregations