Search in sources :

Example 96 with SearchQuery

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

the class IndexNullAsValueIT method indexNullAsValue_match.

@Test
public void indexNullAsValue_match() {
    setUp();
    StubMappingScope scope = index.createScope();
    for (ByTypeFieldModel<?> fieldModel : index.binding().matchFieldModels) {
        String absoluteFieldPath = fieldModel.relativeFieldName;
        Object valueToMatch = fieldModel.indexNullAsValue.indexedValue;
        SearchQuery<DocumentReference> query = scope.query().where(f -> f.match().field(absoluteFieldPath).matching(valueToMatch)).toQuery();
        assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), DOCUMENT_WITH_INDEX_NULL_AS_VALUES, DOCUMENT_WITH_NULL_VALUES);
    }
}
Also used : FieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.FieldTypeDescriptor) SearchException(org.hibernate.search.util.common.SearchException) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) 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) Collectors(java.util.stream.Collectors) StubMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappedIndex) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) IndexNullAsMatchPredicateExpectactions(org.hibernate.search.integrationtest.backend.tck.testsupport.types.expectations.IndexNullAsMatchPredicateExpectactions) List(java.util.List) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) 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) Assume.assumeTrue(org.junit.Assume.assumeTrue) StandardFieldMapper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.StandardFieldMapper) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DefaultAnalysisDefinitions(org.hibernate.search.integrationtest.backend.tck.testsupport.configuration.DefaultAnalysisDefinitions) TckConfiguration(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckConfiguration) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 97 with SearchQuery

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

the class SmokeIT method where_searchPredicate.

@Test
public void where_searchPredicate() {
    StubMappingScope scope = index.createScope();
    SearchPredicate predicate = scope.predicate().match().field("string").matching("text 1").toPredicate();
    SearchQuery<DocumentReference> query = scope.query().where(predicate).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), "1").hasTotalHitCount(1);
    predicate = scope.predicate().range().field("integer").between(1, 2).toPredicate();
    query = scope.query().where(predicate).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), "1", "2").hasTotalHitCount(2);
    predicate = scope.predicate().bool().should(f -> f.match().field("integer").matching(1)).should(f -> f.match().field("integer").matching(2)).toPredicate();
    query = scope.query().where(predicate).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), "1", "2").hasTotalHitCount(2);
}
Also used : IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) 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) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) Rule(org.junit.Rule) LocalDate(java.time.LocalDate) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) DefaultAnalysisDefinitions(org.hibernate.search.integrationtest.backend.tck.testsupport.configuration.DefaultAnalysisDefinitions) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 98 with SearchQuery

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

the class SmokeIT method where_boolean.

@Test
public void where_boolean() {
    StubMappingScope scope = index.createScope();
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.bool().should(f.match().field("integer").matching(1)).should(f.match().field("integer").matching(2))).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), "1", "2").hasTotalHitCount(2);
    query = scope.query().where(f -> f.bool().must(f.match().field("string_analyzed").matching("text")).filter(f.match().field("integer").matching(1))).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), "1").hasTotalHitCount(1);
    query = scope.query().where(f -> f.bool().must(f.match().field("string_analyzed").matching("text")).mustNot(f.match().field("integer").matching(2))).toQuery();
    assertThatQuery(query).hasDocRefHitsAnyOrder(index.typeName(), "1", "3").hasTotalHitCount(2);
}
Also used : IndexObjectFieldReference(org.hibernate.search.engine.backend.document.IndexObjectFieldReference) GeoPoint(org.hibernate.search.engine.spatial.GeoPoint) SearchPredicate(org.hibernate.search.engine.search.predicate.SearchPredicate) 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) IndexSchemaObjectField(org.hibernate.search.engine.backend.document.model.dsl.IndexSchemaObjectField) SearchResultAssert.assertThatQuery(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery) ObjectStructure(org.hibernate.search.engine.backend.types.ObjectStructure) IndexFieldReference(org.hibernate.search.engine.backend.document.IndexFieldReference) Rule(org.junit.Rule) LocalDate(java.time.LocalDate) SimpleMappedIndex(org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) SearchQuery(org.hibernate.search.engine.search.query.SearchQuery) DocumentElement(org.hibernate.search.engine.backend.document.DocumentElement) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) DefaultAnalysisDefinitions(org.hibernate.search.integrationtest.backend.tck.testsupport.configuration.DefaultAnalysisDefinitions) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) Test(org.junit.Test)

Example 99 with SearchQuery

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

the class AnalysisBuiltinIT method assertMatchQuery.

private SearchResultAssert<DocumentReference> assertMatchQuery(SimpleFieldModel<String> fieldModel, String valueToMatch) {
    StubMappingScope scope = index.createScope();
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.match().field(fieldModel.relativeFieldName).matching(valueToMatch)).toQuery();
    return assertThatQuery(query);
}
Also used : Arrays(java.util.Arrays) KeywordStringFieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.KeywordStringFieldTypeDescriptor) SimpleFieldModel(org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel) RunWith(org.junit.runner.RunWith) 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) List(java.util.List) Rule(org.junit.Rule) AnalyzerNames(org.hibernate.search.engine.backend.analysis.AnalyzerNames) 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) TckBackendHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckBackendHelper) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) SingleFieldDocumentBuilder(org.hibernate.search.util.impl.integrationtest.mapper.stub.SingleFieldDocumentBuilder) SearchResultAssert(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference)

Example 100 with SearchQuery

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

the class AnalysisBuiltinOverrideIT method assertMatchQuery.

private SearchResultAssert<DocumentReference> assertMatchQuery(SimpleFieldModel<String> fieldModel, String valueToMatch) {
    StubMappingScope scope = index.createScope();
    SearchQuery<DocumentReference> query = scope.query().where(f -> f.match().field(fieldModel.relativeFieldName).matching(valueToMatch)).toQuery();
    return assertThatQuery(query);
}
Also used : KeywordStringFieldTypeDescriptor(org.hibernate.search.integrationtest.backend.tck.testsupport.types.KeywordStringFieldTypeDescriptor) SimpleFieldModel(org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel) 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) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) AnalyzerNames(org.hibernate.search.engine.backend.analysis.AnalyzerNames) 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) TckBackendHelper(org.hibernate.search.integrationtest.backend.tck.testsupport.util.TckBackendHelper) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference) SingleFieldDocumentBuilder(org.hibernate.search.util.impl.integrationtest.mapper.stub.SingleFieldDocumentBuilder) SearchResultAssert(org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert) Before(org.junit.Before) StubMappingScope(org.hibernate.search.util.impl.integrationtest.mapper.stub.StubMappingScope) DocumentReference(org.hibernate.search.engine.backend.common.DocumentReference)

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