use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method createCluster.
private Map<FacetValue, DtList<I>> createCluster(final Map<String, I> dtcIndex, final Map<I, Map<DtField, String>> resultHighlights) {
final Map<FacetValue, DtList<I>> resultCluster = new LinkedHashMap<>();
final FacetDefinition facetDefinition = searchQuery.getClusteringFacetDefinition();
final Aggregation facetAggregation = queryResponse.getAggregations().get(facetDefinition.getName());
if (facetDefinition.isRangeFacet()) {
// Cas des facettes par 'range'
final MultiBucketsAggregation multiBuckets = (MultiBucketsAggregation) facetAggregation;
for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
final Bucket value = getBucketByKey(multiBuckets, facetRange.getListFilter().getFilterValue());
populateCluster(value, facetRange, resultCluster, dtcIndex, resultHighlights);
}
} else {
// Cas des facettes par 'term'
final MultiBucketsAggregation multiBuckets = (MultiBucketsAggregation) facetAggregation;
FacetValue facetValue;
for (final Bucket bucket : multiBuckets.getBuckets()) {
final String term = bucket.getKeyAsString();
final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
final MessageText label = MessageText.of(term);
facetValue = new FacetValue(term, ListFilter.of(query), label);
populateCluster(bucket, facetValue, resultCluster, dtcIndex, resultHighlights);
}
}
return resultCluster;
}
use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method numberRangeFacetToAggregationBuilder.
private static AggregationBuilder numberRangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
final RangeAggregationBuilder rangeBuilder = //
AggregationBuilders.range(facetDefinition.getName()).field(dtField.getName());
for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
final String filterValue = facetRange.getListFilter().getFilterValue();
Assertion.checkState(filterValue.contains(dtField.getName()), "RangeFilter query ({1}) should use defined fieldName {0}", dtField.getName(), filterValue);
final String[] parsedFilter = DtListPatternFilterUtil.parseFilter(filterValue, RANGE_PATTERN).get();
final Optional<Double> minValue = convertToDouble(parsedFilter[3]);
final Optional<Double> maxValue = convertToDouble(parsedFilter[4]);
if (!minValue.isPresent()) {
rangeBuilder.addUnboundedTo(filterValue, maxValue.get());
} else if (!maxValue.isPresent()) {
rangeBuilder.addUnboundedFrom(filterValue, minValue.get());
} else {
// always min include and max exclude in ElasticSearch
rangeBuilder.addRange(filterValue, minValue.get(), maxValue.get());
}
}
return rangeBuilder;
}
use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method rangeFacetToAggregationBuilder.
private static AggregationBuilder rangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
// facette par range
final DataType dataType = dtField.getDomain().getDataType();
if (dataType == DataType.Date) {
return dateRangeFacetToAggregationBuilder(facetDefinition, dtField);
} else if (dataType.isNumber()) {
return numberRangeFacetToAggregationBuilder(facetDefinition, dtField);
}
final List<KeyedFilter> filters = new ArrayList<>();
for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
final String filterValue = facetRange.getListFilter().getFilterValue();
Assertion.checkState(filterValue.contains(dtField.getName()), "RangeFilter query ({1}) should use defined fieldName {0}", dtField.getName(), filterValue);
filters.add(new KeyedFilter(filterValue, QueryBuilders.queryStringQuery(filterValue)));
}
return AggregationBuilders.filters(facetDefinition.getName(), filters.toArray(new KeyedFilter[filters.size()]));
}
use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method dateRangeFacetToAggregationBuilder.
private static AggregationBuilder dateRangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
final DateRangeAggregationBuilder dateRangeBuilder = AggregationBuilders.dateRange(facetDefinition.getName()).field(dtField.getName()).format(DATE_PATTERN);
for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
final String filterValue = facetRange.getListFilter().getFilterValue();
Assertion.checkState(filterValue.contains(dtField.getName()), "RangeFilter query ({1}) should use defined fieldName {0}", dtField.getName(), filterValue);
final String[] parsedFilter = DtListPatternFilterUtil.parseFilter(filterValue, RANGE_PATTERN).get();
final String minValue = parsedFilter[3];
final String maxValue = parsedFilter[4];
if ("*".equals(minValue)) {
dateRangeBuilder.addUnboundedTo(filterValue, maxValue);
} else if ("*".equals(maxValue)) {
dateRangeBuilder.addUnboundedFrom(filterValue, minValue);
} else {
// always min include and max exclude in ElasticSearch
dateRangeBuilder.addRange(filterValue, minValue, maxValue);
}
}
return dateRangeBuilder;
}
use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class FacetManagerTest method testFacetResultByTerm.
private void testFacetResultByTerm(final FacetedQueryResult<SmartCar, ?> result) {
Assert.assertEquals(smartCarDataBase.size(), result.getCount());
// On vérifie qu'il y a le bon nombre de facettes.
Assert.assertEquals(3, result.getFacets().size());
// On recherche la facette constructeur
final Facet manufacturerFacet = getFacetByName(result, "FCT_MANUFACTURER_CAR");
// On vérifie que l'on est sur le champ Make
Assert.assertEquals("MANUFACTURER", manufacturerFacet.getDefinition().getDtField().getName());
Assert.assertFalse(manufacturerFacet.getDefinition().isRangeFacet());
// On vérifie qu'il existe une valeur pour peugeot et que le nombre d'occurrences est correct
boolean found = false;
final String manufacturer = "peugeot";
for (final Entry<FacetValue, Long> entry : manufacturerFacet.getFacetValues().entrySet()) {
if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).equals(manufacturer)) {
found = true;
// System.out.println("manufacturer" + entry.getKey().getLabel().getDisplay());
Assert.assertEquals(smartCarDataBase.getCarsByManufacturer(manufacturer).size(), entry.getValue().intValue());
}
}
Assert.assertTrue(found);
}
Aggregations