Search in sources :

Example 11 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class IdentifierSearchProjectionBaseIT method validSuperClass.

@Test
public void validSuperClass() {
    StubMappingScope scope = index.createScope();
    SearchQuery<CharSequence> query = scope.query().select(f -> f.id(CharSequence.class)).where(f -> f.matchAll()).toQuery();
    List<CharSequence> result = query.fetchHits(30);
    assertThat(result).containsExactlyInAnyOrder(ids);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FromDocumentValueConvertContext(org.hibernate.search.engine.backend.types.converter.runtime.FromDocumentValueConvertContext) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) Test(org.junit.Test) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) StubMapperUtils.documentProvider(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapperUtils.documentProvider) StubMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappedIndex) ArrayList(java.util.ArrayList) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) FromDocumentValueConverter(org.hibernate.search.engine.backend.types.converter.FromDocumentValueConverter) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test)

Example 12 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class IdentifierSearchProjectionBaseIT method simple.

@Test
public void simple() {
    StubMappingScope scope = index.createScope();
    SearchQuery<String> query = scope.query().select(f -> f.id(String.class)).where(f -> f.matchAll()).toQuery();
    List<String> result = query.fetchHits(30);
    assertThat(result).containsExactlyInAnyOrder(ids);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FromDocumentValueConvertContext(org.hibernate.search.engine.backend.types.converter.runtime.FromDocumentValueConvertContext) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) Test(org.junit.Test) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) StubMapperUtils.documentProvider(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapperUtils.documentProvider) StubMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappedIndex) ArrayList(java.util.ArrayList) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) FromDocumentValueConverter(org.hibernate.search.engine.backend.types.converter.FromDocumentValueConverter) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test)

Example 13 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class IdentifierSearchProjectionBaseIT method multiIndex_withCompatibleIndex.

@Test
public void multiIndex_withCompatibleIndex() {
    StubMappingScope scope = index.createScope(compatibleIndex);
    SearchQuery<String> query = scope.query().select(f -> f.id(String.class)).where(f -> f.matchAll()).toQuery();
    List<String> result = query.fetchHits(30);
    String[] allIds = Stream.concat(Arrays.stream(ids), Arrays.stream(compatibleIndexIds)).toArray(String[]::new);
    assertThat(result).containsExactlyInAnyOrder(allIds);
}
Also used : SearchException(org.hibernate.search.util.common.SearchException) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FromDocumentValueConvertContext(org.hibernate.search.engine.backend.types.converter.runtime.FromDocumentValueConvertContext) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) Test(org.junit.Test) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) StubMapperUtils.documentProvider(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMapperUtils.documentProvider) StubMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappedIndex) ArrayList(java.util.ArrayList) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) FromDocumentValueConverter(org.hibernate.search.engine.backend.types.converter.FromDocumentValueConverter) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test)

Example 14 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class CompositeSearchProjectionIT method compositeTriFunction_fromSearchProjectionObjects.

@Test
public void compositeTriFunction_fromSearchProjectionObjects() {
    StubMappingScope scope = index.createScope();
    SearchQuery<Book_Tri> query = scope.query().select(f -> f.composite(Book_Tri::new, f.field(index.binding().author.relativeFieldName, String.class).toProjection(), f.field(index.binding().title.relativeFieldName, String.class).toProjection(), f.field(index.binding().releaseDate.relativeFieldName, LocalDate.class).toProjection())).where(f -> f.matchAll()).toQuery();
    assertThatQuery(query).hasHitsAnyOrder(new Book_Tri(index.binding().author.document1Value.indexedValue, index.binding().title.document1Value.indexedValue, index.binding().releaseDate.document1Value.indexedValue), new Book_Tri(index.binding().author.document2Value.indexedValue, index.binding().title.document2Value.indexedValue, index.binding().releaseDate.document2Value.indexedValue), new Book_Tri(index.binding().author.document3Value.indexedValue, index.binding().title.document3Value.indexedValue, index.binding().releaseDate.document3Value.indexedValue));
}
Also used : Arrays(java.util.Arrays) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) Test(org.junit.Test) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) Function(java.util.function.Function) Objects(java.util.Objects) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) Rule(org.junit.Rule) LocalDate(java.time.LocalDate) StandardIndexFieldTypeOptionsStep(org.hibernate.search.engine.backend.types.dsl.StandardIndexFieldTypeOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) StandardFieldMapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.StandardFieldMapper) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) Projectable(org.hibernate.search.engine.backend.types.Projectable) IndexFieldTypeFactory(org.hibernate.search.engine.backend.types.dsl.IndexFieldTypeFactory) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 15 with SearchQuery

use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.

the class CompositeSearchProjectionIT method compositeBiFunction_fromSearchProjectionObjects.

@Test
public void compositeBiFunction_fromSearchProjectionObjects() {
    StubMappingScope scope = index.createScope();
    SearchQuery<Book_Bi> query = scope.query().select(f -> f.composite(Book_Bi::new, f.field(index.binding().author.relativeFieldName, String.class).toProjection(), f.field(index.binding().title.relativeFieldName, String.class).toProjection())).where(f -> f.matchAll()).toQuery();
    assertThatQuery(query).hasHitsAnyOrder(new Book_Bi(index.binding().author.document1Value.indexedValue, index.binding().title.document1Value.indexedValue), new Book_Bi(index.binding().author.document2Value.indexedValue, index.binding().title.document2Value.indexedValue), new Book_Bi(index.binding().author.document3Value.indexedValue, index.binding().title.document3Value.indexedValue));
}
Also used : Arrays(java.util.Arrays) SearchSetupHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper) Test(org.junit.Test) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) IndexSchemaElement(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement) Function(java.util.function.Function) Objects(java.util.Objects) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) List(java.util.List) Rule(org.junit.Rule) LocalDate(java.time.LocalDate) StandardIndexFieldTypeOptionsStep(org.hibernate.search.engine.backend.types.dsl.StandardIndexFieldTypeOptionsStep) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) StandardFieldMapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.StandardFieldMapper) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) Projectable(org.hibernate.search.engine.backend.types.Projectable) IndexFieldTypeFactory(org.hibernate.search.engine.backend.types.dsl.IndexFieldTypeFactory) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) Test(org.junit.Test)

Aggregations

SearchQuery (org.hibernate.search.engine.search.query.SearchQuery)229 Test (org.junit.Test)222 Rule (org.junit.Rule)197 SearchSetupHelper (org.hibernate.search.integrationtest.backend.tck.testsupport.util.rule.SearchSetupHelper)186 IndexSchemaElement (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaElement)185 SimpleMappedIndex (org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex)185 StubMappingScope (org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope)179 Before (org.junit.Before)177 SearchResultAssert.assertThatQuery (org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery)164 List (java.util.List)158 IndexFieldReference (org.hibernate.search.engine.backend.document.IndexFieldReference)153 DocumentReference (org.hibernate.search.engine.backend.common.DocumentReference)151 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)135 TestForIssue (org.hibernate.search.util.impl.test.annotation.TestForIssue)129 Projectable (org.hibernate.search.engine.backend.types.Projectable)127 SearchException (org.hibernate.search.util.common.SearchException)119 DocumentElement (org.hibernate.search.engine.backend.document.DocumentElement)113 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)110 IndexObjectFieldReference (org.hibernate.search.engine.backend.document.IndexObjectFieldReference)102 IndexSchemaObjectField (org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField)102