Search in sources :

Example 1 with SearchScope

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();
    }
}
Also used : EntityReferenceImpl(org.hibernate.search.mapper.javabean.common.impl.EntityReferenceImpl) IntegerAsStringValueBridge(org.hibernate.search.integrationtest.mapper.pojo.smoke.bridge.IntegerAsStringValueBridge) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubBackendUtils.reference(org.hibernate.search.util.impl.integrationtest.common.stub.backend.StubBackendUtils.reference) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) EntityReference(org.hibernate.search.mapper.javabean.common.EntityReference) DocumentId(org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId) PropertyValue(org.hibernate.search.mapper.pojo.mapping.definition.annotation.PropertyValue) BuiltinContainerExtractors(org.hibernate.search.mapper.pojo.extractor.builtin.BuiltinContainerExtractors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) Map(java.util.Map) StubSearchWorkBehavior(org.hibernate.search.util.impl.integrationtest.common.rule.StubSearchWorkBehavior) LinkedHashSet(java.util.LinkedHashSet) AssociationInverseSide(org.hibernate.search.mapper.pojo.mapping.definition.annotation.AssociationInverseSide) Before(org.junit.Before) SearchScope(org.hibernate.search.mapper.javabean.scope.SearchScope) ContainerExtraction(org.hibernate.search.mapper.pojo.extractor.mapping.annotation.ContainerExtraction) CustomPropertyBinding(org.hibernate.search.integrationtest.mapper.pojo.smoke.bridge.CustomPropertyBinding) MethodHandles(java.lang.invoke.MethodHandles) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) Set(java.util.Set) ValueBridgeRef(org.hibernate.search.mapper.pojo.bridge.mapping.annotation.ValueBridgeRef) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) List(java.util.List) Rule(org.junit.Rule) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) LocalDate(java.time.LocalDate) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SearchResult(org.hibernate.search.engine.search.query.SearchResult) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) ObjectPath(org.hibernate.search.mapper.pojo.mapping.definition.annotation.ObjectPath) CustomTypeBinding(org.hibernate.search.integrationtest.mapper.pojo.smoke.bridge.CustomTypeBinding) CollectionHelper(org.hibernate.search.util.common.impl.CollectionHelper) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with SearchScope

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();
    }
}
Also used : EntityReferenceImpl(org.hibernate.search.mapper.javabean.common.impl.EntityReferenceImpl) IntegerAsStringValueBridge(org.hibernate.search.integrationtest.mapper.pojo.smoke.bridge.IntegerAsStringValueBridge) Arrays(java.util.Arrays) PojoModelPath(org.hibernate.search.mapper.pojo.model.path.PojoModelPath) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubBackendUtils.reference(org.hibernate.search.util.impl.integrationtest.common.stub.backend.StubBackendUtils.reference) JavaBeanMappingSetupHelper(org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper) EntityReference(org.hibernate.search.mapper.javabean.common.EntityReference) BuiltinContainerExtractors(org.hibernate.search.mapper.pojo.extractor.builtin.BuiltinContainerExtractors) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SearchMapping(org.hibernate.search.mapper.javabean.mapping.SearchMapping) Map(java.util.Map) TypeMappingStep(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.TypeMappingStep) StubSearchWorkBehavior(org.hibernate.search.util.impl.integrationtest.common.rule.StubSearchWorkBehavior) LinkedHashSet(java.util.LinkedHashSet) Before(org.junit.Before) SearchScope(org.hibernate.search.mapper.javabean.scope.SearchScope) CustomPropertyBridge(org.hibernate.search.integrationtest.mapper.pojo.smoke.bridge.CustomPropertyBridge) CustomTypeBridge(org.hibernate.search.integrationtest.mapper.pojo.smoke.bridge.CustomTypeBridge) MethodHandles(java.lang.invoke.MethodHandles) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) Test(org.junit.Test) List(java.util.List) ProgrammaticMappingConfigurationContext(org.hibernate.search.mapper.pojo.mapping.definition.programmatic.ProgrammaticMappingConfigurationContext) Rule(org.junit.Rule) LocalDate(java.time.LocalDate) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SearchResult(org.hibernate.search.engine.search.query.SearchResult) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) CollectionHelper(org.hibernate.search.util.common.impl.CollectionHelper) SearchSession(org.hibernate.search.mapper.javabean.session.SearchSession) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

MethodHandles (java.lang.invoke.MethodHandles)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Map (java.util.Map)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)2 SearchResult (org.hibernate.search.engine.search.query.SearchResult)2 IntegerAsStringValueBridge (org.hibernate.search.integrationtest.mapper.pojo.smoke.bridge.IntegerAsStringValueBridge)2 JavaBeanMappingSetupHelper (org.hibernate.search.integrationtest.mapper.pojo.testsupport.util.rule.JavaBeanMappingSetupHelper)2 EntityReference (org.hibernate.search.mapper.javabean.common.EntityReference)2 EntityReferenceImpl (org.hibernate.search.mapper.javabean.common.impl.EntityReferenceImpl)2 SearchMapping (org.hibernate.search.mapper.javabean.mapping.SearchMapping)2 SearchScope (org.hibernate.search.mapper.javabean.scope.SearchScope)2 SearchSession (org.hibernate.search.mapper.javabean.session.SearchSession)2 BuiltinContainerExtractors (org.hibernate.search.mapper.pojo.extractor.builtin.BuiltinContainerExtractors)2 CollectionHelper (org.hibernate.search.util.common.impl.CollectionHelper)2