use of org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel in project hibernate-search by hibernate.
the class IndexingFieldTypesIT method withReference.
@Test
public void withReference() {
List<F> values = new ArrayList<>(this.typeDescriptor.getIndexableValues().getSingle());
// Also test null
values.add(null);
List<IdAndValue<F>> expectedDocuments = new ArrayList<>();
SimpleFieldModel<F> fieldModel = index.binding().fieldModel;
// Index all values, each in its own document
IndexIndexingPlan plan = index.createIndexingPlan();
for (int i = 0; i < values.size(); i++) {
String documentId = "document_" + i;
F value = values.get(i);
plan.add(referenceProvider(documentId), document -> {
document.addValue(fieldModel.reference, value);
});
expectedDocuments.add(new IdAndValue<>(documentId, value));
}
plan.execute().join();
// If we get here, indexing went well.
// However, it may have failed silently... Let's check the documents are there, with the right value.
StubMappingScope scope = index.createScope();
String absoluteFieldPath = fieldModel.relativeFieldName;
for (int i = 0; i < values.size(); i++) {
SearchQuery<IdAndValue<F>> query = scope.query().select(f -> f.composite().from(f.id(String.class), f.field(absoluteFieldPath, typeDescriptor.getJavaType())).as((id, val) -> new IdAndValue<>(id, val))).where(f -> f.matchAll()).toQuery();
assertThatQuery(query).hasHitsAnyOrder(expectedDocuments);
}
}
use of org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel 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);
}
use of org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel 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);
}
use of org.hibernate.search.integrationtest.backend.tck.testsupport.util.SimpleFieldModel in project hibernate-search by hibernate.
the class IndexingFieldTypesIT method withPath.
@Test
public void withPath() {
List<F> values = new ArrayList<>(this.typeDescriptor.getIndexableValues().getSingle());
// Also test null
values.add(null);
List<IdAndValue<F>> expectedDocuments = new ArrayList<>();
SimpleFieldModel<F> fieldModel = index.binding().fieldModel;
// Index all values, each in its own document
IndexIndexingPlan plan = index.createIndexingPlan();
for (int i = 0; i < values.size(); i++) {
String documentId = "document_" + i;
F value = values.get(i);
plan.add(referenceProvider(documentId), document -> {
document.addValue(fieldModel.relativeFieldName, value);
});
expectedDocuments.add(new IdAndValue<>(documentId, value));
}
plan.execute().join();
// If we get here, indexing went well.
// However, it may have failed silently... Let's check the documents are there, with the right value.
StubMappingScope scope = index.createScope();
String absoluteFieldPath = fieldModel.relativeFieldName;
for (int i = 0; i < values.size(); i++) {
SearchQuery<IdAndValue<F>> query = scope.query().select(f -> f.composite().from(f.entityReference(), f.field(absoluteFieldPath, typeDescriptor.getJavaType())).as((ref, val) -> new IdAndValue<>(ref.id(), val))).where(f -> f.matchAll()).toQuery();
assertThatQuery(query).hasHitsAnyOrder(expectedDocuments);
}
}
Aggregations