use of org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex in project hibernate-search by hibernate.
the class LuceneExtensionIT method indexDataSet.
private static void indexDataSet(SimpleMappedIndex<IndexBinding> index) {
index.bulkIndexer().add(FIRST_ID, document -> {
document.addValue(index.binding().string, "text 1");
document.addValue(index.binding().nativeField, 37);
document.addValue(index.binding().nativeField_converted, 37);
document.addValue(index.binding().nativeField_unsupportedProjection, 37);
document.addValue(index.binding().sort1, "a");
document.addValue(index.binding().sort2, "z");
document.addValue(index.binding().sort3, "z");
DocumentElement nestedObject1 = document.addObject(index.binding().nestedObject.self);
nestedObject1.addValue(index.binding().nestedObject.discriminator, "included");
nestedObject1.addValue(index.binding().nestedObject.sort1, "a");
nestedObject1.addValue(index.binding().nestedObject.aggregation1, "one");
DocumentElement nestedObject2 = document.addObject(index.binding().nestedObject.self);
nestedObject2.addValue(index.binding().nestedObject.discriminator, "excluded");
nestedObject2.addValue(index.binding().nestedObject.sort1, "b");
nestedObject2.addValue(index.binding().nestedObject.aggregation1, "fifty-one");
DocumentElement flattenedObject1 = document.addObject(index.binding().flattenedObject.self);
flattenedObject1.addValue(index.binding().flattenedObject.stringInObject, "text 2");
flattenedObject1.addValue(index.binding().flattenedObject.sortInObject, "1");
}).add(SECOND_ID, document -> {
document.addValue(index.binding().integer, 2);
document.addValue(index.binding().nativeField, 78);
document.addValue(index.binding().nativeField_converted, 78);
document.addValue(index.binding().nativeField_unsupportedProjection, 78);
document.addValue(index.binding().sort1, "z");
document.addValue(index.binding().sort2, "a");
document.addValue(index.binding().sort3, "z");
DocumentElement nestedObject1 = document.addObject(index.binding().nestedObject.self);
nestedObject1.addValue(index.binding().nestedObject.discriminator, "included");
nestedObject1.addValue(index.binding().nestedObject.sort1, "b");
nestedObject1.addValue(index.binding().nestedObject.aggregation1, "two");
DocumentElement nestedObject2 = document.addObject(index.binding().nestedObject.self);
nestedObject2.addValue(index.binding().nestedObject.discriminator, "excluded");
nestedObject2.addValue(index.binding().nestedObject.sort1, "a");
nestedObject2.addValue(index.binding().nestedObject.aggregation1, "fifty-two");
DocumentElement flattenedObject1 = document.addObject(index.binding().flattenedObject.self);
flattenedObject1.addValue(index.binding().flattenedObject.integerInObject, 3);
flattenedObject1.addValue(index.binding().flattenedObject.sortInObject, "2");
}).add(THIRD_ID, document -> {
document.addValue(index.binding().geoPoint, GeoPoint.of(40.12, -71.34));
document.addValue(index.binding().nativeField, 13);
document.addValue(index.binding().nativeField_converted, 13);
document.addValue(index.binding().nativeField_unsupportedProjection, 13);
document.addValue(index.binding().sort1, "z");
document.addValue(index.binding().sort2, "z");
document.addValue(index.binding().sort3, "a");
DocumentElement nestedObject1 = document.addObject(index.binding().nestedObject.self);
nestedObject1.addValue(index.binding().nestedObject.discriminator, "included");
nestedObject1.addValue(index.binding().nestedObject.sort1, "c");
nestedObject1.addValue(index.binding().nestedObject.aggregation1, "three");
DocumentElement nestedObject2 = document.addObject(index.binding().nestedObject.self);
nestedObject2.addValue(index.binding().nestedObject.discriminator, "excluded");
nestedObject2.addValue(index.binding().nestedObject.sort1, "b");
nestedObject2.addValue(index.binding().nestedObject.aggregation1, "fifty-three");
DocumentElement flattenedObject1 = document.addObject(index.binding().flattenedObject.self);
flattenedObject1.addValue(index.binding().flattenedObject.sortInObject, "3");
}).add(FOURTH_ID, document -> {
document.addValue(index.binding().nativeField, 89);
document.addValue(index.binding().nativeField_converted, 89);
document.addValue(index.binding().nativeField_unsupportedProjection, 89);
document.addValue(index.binding().sort1, "z");
document.addValue(index.binding().sort2, "z");
document.addValue(index.binding().sort3, "z");
DocumentElement nestedObject1 = document.addObject(index.binding().nestedObject.self);
nestedObject1.addValue(index.binding().nestedObject.discriminator, "included");
nestedObject1.addValue(index.binding().nestedObject.sort1, "d");
nestedObject1.addValue(index.binding().nestedObject.aggregation1, "four");
DocumentElement nestedObject2 = document.addObject(index.binding().nestedObject.self);
nestedObject2.addValue(index.binding().nestedObject.discriminator, "excluded");
nestedObject2.addValue(index.binding().nestedObject.sort1, "c");
nestedObject2.addValue(index.binding().nestedObject.aggregation1, "fifty-four");
DocumentElement flattenedObject1 = document.addObject(index.binding().flattenedObject.self);
flattenedObject1.addValue(index.binding().flattenedObject.sortInObject, "4");
}).add(FIFTH_ID, document -> {
// This document should not match any query
document.addValue(index.binding().string, "text 2");
document.addValue(index.binding().integer, 1);
document.addValue(index.binding().geoPoint, GeoPoint.of(45.12, -75.34));
document.addValue(index.binding().sort1, "zz");
document.addValue(index.binding().sort2, "zz");
document.addValue(index.binding().sort3, "zz");
DocumentElement nestedObject1 = document.addObject(index.binding().nestedObject.self);
nestedObject1.addValue(index.binding().nestedObject.discriminator, "included");
nestedObject1.addValue(index.binding().nestedObject.sort1, "e");
nestedObject1.addValue(index.binding().nestedObject.aggregation1, "five");
DocumentElement nestedObject2 = document.addObject(index.binding().nestedObject.self);
nestedObject2.addValue(index.binding().nestedObject.discriminator, "excluded");
nestedObject2.addValue(index.binding().nestedObject.sort1, "a");
nestedObject2.addValue(index.binding().nestedObject.aggregation1, "fifty-five");
DocumentElement flattenedObject1 = document.addObject(index.binding().flattenedObject.self);
flattenedObject1.addValue(index.binding().flattenedObject.sortInObject, "5");
}).join();
}
use of org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex in project hibernate-search by hibernate.
the class DecimalScaleIT method decimalScale_tooLargeDecimal_scale2_bigDecimal_lowerBound_queryPredicateBuildTime.
@Test
public void decimalScale_tooLargeDecimal_scale2_bigDecimal_lowerBound_queryPredicateBuildTime() {
SimpleMappedIndex<DecimalScaleIndexBinding> index = SimpleMappedIndex.of(root -> new DecimalScaleIndexBinding(root, 2));
setupHelper.start().withIndex(index).setup();
// Provide a value that if it were divided by 10, could not be represented as a long, because the scale of 2
BigDecimal tooLargeDecimal = BigDecimal.valueOf(Long.MIN_VALUE).divide(BigDecimal.TEN);
BigDecimal veryLargeDecimal = tooLargeDecimal.divide(BigDecimal.TEN);
index.index("1", doc -> doc.addValue(index.binding().scaled, veryLargeDecimal));
assertThatThrownBy(() -> index.createScope().query().selectEntityReference().where(p -> p.range().field("scaled").atLeast(tooLargeDecimal))).isInstanceOf(SearchException.class).hasMessageContainingAll("Unable to encode value '" + tooLargeDecimal.toString() + "'", "this field type only supports values ranging from ", "If you want to encode values that are outside this range," + " change the decimal scale for this field");
}
use of org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex in project hibernate-search by hibernate.
the class DecimalScaleIT method decimalScale_tooLargeDecimal_scale2_bigDecimal.
@Test
public void decimalScale_tooLargeDecimal_scale2_bigDecimal() {
SimpleMappedIndex<DecimalScaleIndexBinding> index = SimpleMappedIndex.of(root -> new DecimalScaleIndexBinding(root, 2));
setupHelper.start().withIndex(index).setup();
// Provide a value that if it were divided by 10, could not be represented as a long, because the scale of 2
BigDecimal tooLargeDecimal = BigDecimal.valueOf(Long.MAX_VALUE).divide(BigDecimal.TEN);
assertThatThrownBy(() -> index.index("1", doc -> doc.addValue(index.binding().scaled, tooLargeDecimal))).isInstanceOf(SearchException.class).hasMessageContainingAll("Unable to encode value '" + tooLargeDecimal.toString() + "'", "this field type only supports values ranging from ", "If you want to encode values that are outside this range," + " change the decimal scale for this field");
}
use of org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex in project hibernate-search by hibernate.
the class DecimalScaleIT method decimalScale_rounding_bigDecimal.
@Test
public void decimalScale_rounding_bigDecimal() {
SimpleMappedIndex<DecimalScaleIndexBinding> index = SimpleMappedIndex.of(root -> new DecimalScaleIndexBinding(root, 2));
setupHelper.start().withIndex(index).setup();
index.bulkIndexer().add("1", doc -> doc.addValue(index.binding().scaled, new BigDecimal("739.114999"))).add("2", doc -> doc.addValue(index.binding().scaled, new BigDecimal("739.115"))).add("3", doc -> doc.addValue(index.binding().scaled, new BigDecimal("739.11"))).add("4", doc -> doc.addValue(index.binding().scaled, new BigDecimal("739.12"))).join();
// RoundingMode.HALF_UP expected on both values:
match(index, new BigDecimal("739.11"), "1", "3");
match(index, new BigDecimal("739.12"), "2", "4");
// and parameters:
match(index, new BigDecimal("739.114999"), "1", "3");
match(index, new BigDecimal("739.115"), "2", "4");
}
use of org.hibernate.search.util.impl.integrationtest.mapper.stub.SimpleMappedIndex in project hibernate-search by hibernate.
the class DecimalScaleIT method decimalScale_tooLargeDecimal_scale0_bigInteger.
@Test
public void decimalScale_tooLargeDecimal_scale0_bigInteger() {
SimpleMappedIndex<IntegerScaleIndexBinding> index = SimpleMappedIndex.of(root -> new IntegerScaleIndexBinding(root, 0));
setupHelper.start().withIndex(index).setup();
// Provide a value that cannot be represented as a long
BigInteger tooLargeInteger = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.TEN);
assertThatThrownBy(() -> index.index("1", doc -> doc.addValue(index.binding().scaled, tooLargeInteger))).isInstanceOf(SearchException.class).hasMessageContainingAll("Unable to encode value '" + tooLargeInteger.toString() + "'", "this field type only supports values ranging from ", "If you want to encode values that are outside this range," + " change the decimal scale for this field");
}
Aggregations