Search in sources :

Example 26 with FacetValue

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);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 27 with FacetValue

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);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) LinkedHashMap(java.util.LinkedHashMap) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 28 with FacetValue

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);
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) LinkedHashMap(java.util.LinkedHashMap) DtField(io.vertigo.dynamo.domain.metamodel.DtField) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DtList(io.vertigo.dynamo.domain.model.DtList) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 29 with FacetValue

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;
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) FiltersAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder) DataType(io.vertigo.dynamo.domain.metamodel.DataType)

Example 30 with FacetValue

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;
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) RangeBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeBuilder) DateRangeBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeBuilder)

Aggregations

FacetValue (io.vertigo.dynamo.collections.model.FacetValue)44 Facet (io.vertigo.dynamo.collections.model.Facet)24 DtList (io.vertigo.dynamo.domain.model.DtList)17 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)11 LinkedHashMap (java.util.LinkedHashMap)10 MessageText (io.vertigo.core.locale.MessageText)9 List (java.util.List)9 Map (java.util.Map)9 ListFilter (io.vertigo.dynamo.collections.ListFilter)8 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)8 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)8 SelectedFacetValues (io.vertigo.dynamo.collections.model.SelectedFacetValues)8 SearchQuery (io.vertigo.dynamo.search.model.SearchQuery)8 Test (org.junit.Test)8 DtListState (io.vertigo.dynamo.domain.model.DtListState)6 Bucket (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket)6 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)5 DtField (io.vertigo.dynamo.domain.metamodel.DtField)5