use of org.hibernate.search.mapper.javabean.scope.SearchScope 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.scope.SearchScope in project hibernate-search by hibernate.
the class ProgrammaticMappingSmokeIT 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(Integer.class).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();
}
}
Aggregations