use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class FacetManagerTest method testFacetResultByRange.
private void testFacetResultByRange(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 date
final Facet yearFacet = getFacetByName(result, "FCT_YEAR_CAR");
Assert.assertTrue(yearFacet.getDefinition().isRangeFacet());
boolean found = false;
for (final Entry<FacetValue, Long> entry : yearFacet.getFacetValues().entrySet()) {
if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).contains("avant")) {
found = true;
Assert.assertEquals(smartCarDataBase.getCarsBefore(2000), entry.getValue().longValue());
}
}
Assert.assertTrue(found);
}
use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method createFacetRange.
private static Facet createFacetRange(final FacetDefinition facetDefinition, final MultiBucketsAggregation rangeBuckets) {
// Cas des facettes par range
final Map<FacetValue, Long> rangeValues = new LinkedHashMap<>();
for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
final Bucket value = getBucketByKey(rangeBuckets, facetRange.getListFilter().getFilterValue());
rangeValues.put(facetRange, value.getDocCount());
}
return new Facet(facetDefinition, rangeValues);
}
use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method build.
/**
* {@inheritDoc}
*/
@Override
public FacetedQueryResult<I, SearchQuery> build() {
final Map<I, Map<DtField, String>> resultHighlights = new HashMap<>();
final Map<FacetValue, DtList<I>> resultCluster;
final DtList<I> dtc = new DtList<>(indexDefinition.getIndexDtDefinition());
if (searchQuery.isClusteringFacet()) {
final Map<String, I> dtcIndex = new LinkedHashMap<>();
resultCluster = createCluster(dtcIndex, resultHighlights);
dtc.addAll(dtcIndex.values());
} else {
for (final SearchHit searchHit : queryResponse.getHits()) {
final SearchIndex<?, I> index = esDocumentCodec.searchHit2Index(indexDefinition, searchHit);
final I result = index.getIndexDtObject();
dtc.add(result);
final Map<DtField, String> highlights = createHighlight(searchHit, indexDefinition.getIndexDtDefinition());
resultHighlights.put(result, highlights);
}
resultCluster = Collections.emptyMap();
}
// On fabrique à la volée le résultat.
final List<Facet> facets = createFacetList(searchQuery, queryResponse);
final long count = queryResponse.getHits().getTotalHits();
return new FacetedQueryResult<>(searchQuery.getFacetedQuery(), count, dtc, facets, searchQuery.isClusteringFacet() ? Optional.of(searchQuery.getClusteringFacetDefinition()) : Optional.empty(), resultCluster, resultHighlights, searchQuery);
}
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 FiltersAggregationBuilder filters = AggregationBuilders.filters(facetDefinition.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);
filters.filter(filterValue, QueryBuilders.queryStringQuery(filterValue));
}
return filters;
}
use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method numberRangeFacetToAggregationBuilder.
private static AggregationBuilder<RangeBuilder> numberRangeFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
final RangeBuilder 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;
}
Aggregations