use of org.hibernate.search.engine.search.query.SearchQuery in project infinispan by infinispan.
the class ProtobufValueWrapperIndexingTest method testIndexingWithWrapper.
public void testIndexingWithWrapper() {
SearchMapping searchMapping = ComponentRegistryUtils.getSearchMapping(cache);
assertNotNull(searchMapping);
// Store some test data:
cache.put(new byte[] { 1, 2, 3 }, createUser("Adrian", "Nistor"));
cache.put(new byte[] { 4, 5, 6 }, createUser("John", "Batman"));
SearchSession session = searchMapping.getMappingSession();
SearchScope<byte[]> scope = session.scope(byte[].class, "sample_bank_account.User");
SearchQuery<Object> query = session.search(scope).select(f -> f.field("surname")).where(f -> f.match().field("name").matching("Adrian")).toQuery();
List<Object> result = query.fetchAllHits();
assertEquals(1, result.size());
assertEquals("Nistor", result.get(0));
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class FieldSearchSortTypeCheckingAndConversionIT method multiIndex_withCompatibleIndex_usingField.
@Test
public void multiIndex_withCompatibleIndex_usingField() {
StubMappingScope scope = mainIndex.createScope(compatibleIndex);
SearchQuery<DocumentReference> query;
String fieldPath = getFieldPath();
query = matchAllQuery(f -> f.field(fieldPath).asc().missing().use(getSingleValueForMissingUse(BEFORE_DOCUMENT_1_ORDINAL)), scope);
/*
* Not testing the ordering of results here because some documents have the same value.
* It's not what we want to test anyway: we just want to check that fields are correctly
* detected as compatible and that no exception is thrown.
*/
assertThatQuery(query).hasDocRefHitsAnyOrder(b -> {
b.doc(mainIndex.typeName(), EMPTY);
b.doc(mainIndex.typeName(), DOCUMENT_1);
b.doc(mainIndex.typeName(), DOCUMENT_2);
b.doc(mainIndex.typeName(), DOCUMENT_3);
b.doc(compatibleIndex.typeName(), COMPATIBLE_INDEX_DOCUMENT_1);
});
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class DistanceSearchSortTypeCheckingAndConversionIT method multiIndex_withMissingFieldIndex.
@Test
@TestForIssue(jiraKey = "HSEARCH-4173")
public void multiIndex_withMissingFieldIndex() {
assumeTrue("This backend doesn't support distance sorts on a field that is missing from some of the target indexes.", TckConfiguration.get().getBackendFeatures().supportsDistanceSortWhenFieldMissingInSomeTargetIndexes());
StubMappingScope scope = mainIndex.createScope(missingFieldIndex);
SearchQuery<DocumentReference> query;
String fieldPath = getFieldPath();
query = matchNonEmptyQuery(f -> f.distance(fieldPath, CENTER_POINT), scope);
/*
* Not testing the ordering of results here because it's not what we are interested in:
* we just want to check that fields are correctly detected as compatible,
* that no exception is thrown and that the query is correctly executed on all indexes
* with no silent error (HSEARCH-4173).
*/
assertThatQuery(query).hasDocRefHitsAnyOrder(b -> {
b.doc(missingFieldIndex.typeName(), MISSING_FIELD_INDEX_DOCUMENT_1);
b.doc(mainIndex.typeName(), DOCUMENT_1);
b.doc(mainIndex.typeName(), DOCUMENT_2);
b.doc(mainIndex.typeName(), DOCUMENT_3);
});
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class DistanceSearchSortTypeCheckingAndConversionIT method multiIndex_withMissingFieldIndex_nested.
/**
* Test the behavior when even the <strong>parent</strong> field of the field to sort on is missing,
* and that parent field is <strong>nested</strong> in the main index.
*/
@Test
@TestForIssue(jiraKey = "HSEARCH-4173")
public void multiIndex_withMissingFieldIndex_nested() {
assumeTrue("This backend doesn't support distance sorts on a nested field that is missing from some of the target indexes.", TckConfiguration.get().getBackendFeatures().supportsDistanceSortWhenNestedFieldMissingInSomeTargetIndexes());
StubMappingScope scope = mainIndex.createScope(missingFieldIndex);
SearchQuery<DocumentReference> query;
String fieldPath = getFieldInNestedPath();
query = matchNonEmptyQuery(f -> f.distance(fieldPath, CENTER_POINT), scope);
/*
* Not testing the ordering of results here because it's not what we are interested in:
* we just want to check that fields are correctly detected as compatible,
* that no exception is thrown and that the query is correctly executed on all indexes
* with no silent error (HSEARCH-4173).
*/
assertThatQuery(query).hasDocRefHitsAnyOrder(b -> {
b.doc(missingFieldIndex.typeName(), MISSING_FIELD_INDEX_DOCUMENT_1);
b.doc(mainIndex.typeName(), DOCUMENT_1);
b.doc(mainIndex.typeName(), DOCUMENT_2);
b.doc(mainIndex.typeName(), DOCUMENT_3);
});
}
use of org.hibernate.search.engine.search.query.SearchQuery in project hibernate-search by hibernate.
the class FieldSearchSortTypeCheckingAndConversionIT method multiIndex_withMissingFieldIndex_nested.
/**
* Test the behavior when even the <strong>parent</strong> field of the field to sort on is missing,
* and that parent field is <strong>nested</strong> in the main index.
*/
@Test
@TestForIssue(jiraKey = "HSEARCH-4173")
public void multiIndex_withMissingFieldIndex_nested() {
assumeTrue("This backend doesn't support sorts on a field of type '" + fieldTypeDescriptor + "' that is missing from some of the target indexes.", TckConfiguration.get().getBackendFeatures().supportsFieldSortWhenFieldMissingInSomeTargetIndexes(fieldTypeDescriptor.getJavaType()));
assumeTrue("This backend doesn't support field sorts on a nested field that is missing from some of the target indexes.", TckConfiguration.get().getBackendFeatures().supportsFieldSortWhenNestedFieldMissingInSomeTargetIndexes());
StubMappingScope scope = mainIndex.createScope(missingFieldIndex);
SearchQuery<DocumentReference> query;
String fieldPath = getFieldInNestedPath();
query = matchNonEmptyQuery(f -> f.field(fieldPath).asc().missing().use(getSingleValueForMissingUse(BEFORE_DOCUMENT_1_ORDINAL)), scope);
/*
* Not testing the ordering of results here because it's not what we are interested in:
* we just want to check that fields are correctly detected as compatible,
* that no exception is thrown and that the query is correctly executed on all indexes
* with no silent error (HSEARCH-4173).
*/
assertThatQuery(query).hasDocRefHitsAnyOrder(b -> {
b.doc(missingFieldIndex.typeName(), MISSING_FIELD_INDEX_DOCUMENT_1);
b.doc(mainIndex.typeName(), DOCUMENT_1);
b.doc(mainIndex.typeName(), DOCUMENT_2);
b.doc(mainIndex.typeName(), DOCUMENT_3);
});
}
Aggregations