Search in sources :

Example 1 with StubBackendUtils.reference

use of org.hibernate.search.util.impl.integrationtest.common.stub.backend.StubBackendUtils.reference in project hibernate-search by hibernate.

the class SearchQueryBaseIT method select_compositeAndLoading.

@Test
public void select_compositeAndLoading() {
    setupHolder.runInTransaction(session -> {
        SearchSession searchSession = Search.session(session);
        SearchQuery<Book_Author_Score> query = searchSession.search(Book.class).select(f -> f.composite().from(f.composite().from(f.entity(), f.field("author.name", String.class)).as(Book_Author::new), f.score()).as(Book_Author_Score::new)).where(f -> f.matchAll()).toQuery();
        backendMock.expectSearchProjection(Book.NAME, StubSearchWorkBehavior.of(3L, Arrays.asList(Arrays.asList(StubBackendUtils.reference(Book.NAME, "1"), AUTHOR_4_3_2_1), 4.0F), Arrays.asList(Arrays.asList(StubBackendUtils.reference(Book.NAME, "2"), AUTHOR_CIDER_HOUSE), 5.0F), Arrays.asList(Arrays.asList(StubBackendUtils.reference(Book.NAME, "3"), AUTHOR_AVENUE_OF_MYSTERIES), 6.0F)));
        assertThat(query.fetchAllHits()).containsExactlyInAnyOrder(new Book_Author_Score(new Book_Author(session.getReference(Book.class, 1), AUTHOR_4_3_2_1), 4.0F), new Book_Author_Score(new Book_Author(session.getReference(Book.class, 2), AUTHOR_CIDER_HOUSE), 5.0F), new Book_Author_Score(new Book_Author(session.getReference(Book.class, 3), AUTHOR_AVENUE_OF_MYSTERIES), 6.0F));
    });
}
Also used : Arrays(java.util.Arrays) ReusableOrmSetupHolder(org.hibernate.search.util.impl.integrationtest.mapper.orm.ReusableOrmSetupHolder) Search(org.hibernate.search.mapper.orm.Search) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubBackendUtils.reference(org.hibernate.search.util.impl.integrationtest.common.stub.backend.StubBackendUtils.reference) MethodRule(org.junit.rules.MethodRule) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SoftAssertions.assertSoftly(org.assertj.core.api.SoftAssertions.assertSoftly) SearchSort(org.hibernate.search.engine.search.sort.SearchSort) StubSearchPredicate(org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.predicate.impl.StubSearchPredicate) ArrayList(java.util.ArrayList) StubSearchSort(org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.sort.impl.StubSearchSort) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) EntityReference(org.hibernate.search.mapper.orm.common.EntityReference) TimeoutLoadingListener(org.hibernate.search.util.impl.integrationtest.mapper.orm.TimeoutLoadingListener) SearchMapping(org.hibernate.search.mapper.orm.mapping.SearchMapping) StubSearchWorkBehavior(org.hibernate.search.util.impl.integrationtest.common.rule.StubSearchWorkBehavior) ClassRule(org.junit.ClassRule) SearchAggregation(org.hibernate.search.engine.search.aggregation.SearchAggregation) Id(javax.persistence.Id) Before(org.junit.Before) Entity(javax.persistence.Entity) SearchProjection(org.hibernate.search.engine.search.projection.SearchProjection) ManyToOne(javax.persistence.ManyToOne) EntityReferenceImpl(org.hibernate.search.mapper.orm.common.impl.EntityReferenceImpl) SearchScope(org.hibernate.search.mapper.orm.scope.SearchScope) SlowerLoadingListener(org.hibernate.search.util.impl.integrationtest.mapper.orm.SlowerLoadingListener) OneToMany(javax.persistence.OneToMany) AggregationKey(org.hibernate.search.engine.search.aggregation.AggregationKey) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) StubSearchProjection(org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.projection.impl.StubSearchProjection) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Rule(org.junit.Rule) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) SearchTimeoutException(org.hibernate.search.util.common.SearchTimeoutException) StubBackendUtils(org.hibernate.search.util.impl.integrationtest.common.stub.backend.StubBackendUtils) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) OrmSetupHelper(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper) StubSearchAggregation(org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.aggregation.impl.StubSearchAggregation) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) Test(org.junit.Test)

Example 2 with StubBackendUtils.reference

use of org.hibernate.search.util.impl.integrationtest.common.stub.backend.StubBackendUtils.reference in project hibernate-search by hibernate.

the class SearchQueryBaseIT method select_lambda.

@Test
public void select_lambda() {
    setupHolder.runInTransaction(session -> {
        SearchSession searchSession = Search.session(session);
        SearchQuery<Book_Author_Score> query = searchSession.search(Book.class).select(f -> f.composite().from(f.composite().from(f.entity(), f.field("author.name", String.class)).as(Book_Author::new), f.score()).as(Book_Author_Score::new)).where(f -> f.matchAll()).toQuery();
        backendMock.expectSearchProjection(Book.NAME, StubSearchWorkBehavior.of(3L, Arrays.asList(Arrays.asList(StubBackendUtils.reference(Book.NAME, "1"), AUTHOR_4_3_2_1), 4.0F), Arrays.asList(Arrays.asList(StubBackendUtils.reference(Book.NAME, "2"), AUTHOR_CIDER_HOUSE), 5.0F), Arrays.asList(Arrays.asList(StubBackendUtils.reference(Book.NAME, "3"), AUTHOR_AVENUE_OF_MYSTERIES), 6.0F)));
        assertThat(query.fetchAllHits()).containsExactlyInAnyOrder(new Book_Author_Score(new Book_Author(session.get(Book.class, 1), AUTHOR_4_3_2_1), 4.0F), new Book_Author_Score(new Book_Author(session.get(Book.class, 2), AUTHOR_CIDER_HOUSE), 5.0F), new Book_Author_Score(new Book_Author(session.get(Book.class, 3), AUTHOR_AVENUE_OF_MYSTERIES), 6.0F));
    });
}
Also used : Arrays(java.util.Arrays) ReusableOrmSetupHolder(org.hibernate.search.util.impl.integrationtest.mapper.orm.ReusableOrmSetupHolder) Search(org.hibernate.search.mapper.orm.Search) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubBackendUtils.reference(org.hibernate.search.util.impl.integrationtest.common.stub.backend.StubBackendUtils.reference) MethodRule(org.junit.rules.MethodRule) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) SoftAssertions.assertSoftly(org.assertj.core.api.SoftAssertions.assertSoftly) SearchSort(org.hibernate.search.engine.search.sort.SearchSort) StubSearchPredicate(org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.predicate.impl.StubSearchPredicate) ArrayList(java.util.ArrayList) StubSearchSort(org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.sort.impl.StubSearchSort) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) EntityReference(org.hibernate.search.mapper.orm.common.EntityReference) TimeoutLoadingListener(org.hibernate.search.util.impl.integrationtest.mapper.orm.TimeoutLoadingListener) SearchMapping(org.hibernate.search.mapper.orm.mapping.SearchMapping) StubSearchWorkBehavior(org.hibernate.search.util.impl.integrationtest.common.rule.StubSearchWorkBehavior) ClassRule(org.junit.ClassRule) SearchAggregation(org.hibernate.search.engine.search.aggregation.SearchAggregation) Id(javax.persistence.Id) Before(org.junit.Before) Entity(javax.persistence.Entity) SearchProjection(org.hibernate.search.engine.search.projection.SearchProjection) ManyToOne(javax.persistence.ManyToOne) EntityReferenceImpl(org.hibernate.search.mapper.orm.common.impl.EntityReferenceImpl) SearchScope(org.hibernate.search.mapper.orm.scope.SearchScope) SlowerLoadingListener(org.hibernate.search.util.impl.integrationtest.mapper.orm.SlowerLoadingListener) OneToMany(javax.persistence.OneToMany) AggregationKey(org.hibernate.search.engine.search.aggregation.AggregationKey) Test(org.junit.Test) IndexedEmbedded(org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded) Indexed(org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed) StubSearchProjection(org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.projection.impl.StubSearchProjection) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TestForIssue(org.hibernate.search.util.impl.test.annotation.TestForIssue) Rule(org.junit.Rule) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) GenericField(org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField) SearchTimeoutException(org.hibernate.search.util.common.SearchTimeoutException) StubBackendUtils(org.hibernate.search.util.impl.integrationtest.common.stub.backend.StubBackendUtils) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) BackendMock(org.hibernate.search.util.impl.integrationtest.common.rule.BackendMock) OrmSetupHelper(org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmSetupHelper) StubSearchAggregation(org.hibernate.search.util.impl.integrationtest.common.stub.backend.search.aggregation.impl.StubSearchAggregation) SearchSession(org.hibernate.search.mapper.orm.session.SearchSession) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 TimeUnit (java.util.concurrent.TimeUnit)2 Entity (javax.persistence.Entity)2 Id (javax.persistence.Id)2 ManyToOne (javax.persistence.ManyToOne)2 OneToMany (javax.persistence.OneToMany)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 SoftAssertions.assertSoftly (org.assertj.core.api.SoftAssertions.assertSoftly)2 AggregationKey (org.hibernate.search.engine.search.aggregation.AggregationKey)2 SearchAggregation (org.hibernate.search.engine.search.aggregation.SearchAggregation)2 SearchPredicate (org.hibernate.search.engine.search.predicate.SearchPredicate)2 SearchProjection (org.hibernate.search.engine.search.projection.SearchProjection)2 SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)2 SearchSort (org.hibernate.search.engine.search.sort.SearchSort)2 Search (org.hibernate.search.mapper.orm.Search)2