Search in sources :

Example 1 with MessageText

use of io.vertigo.core.locale.MessageText in project vertigo by KleeGroup.

the class ESFacetedQueryResultBuilder method createTermFacet.

private static Facet createTermFacet(final FacetDefinition facetDefinition, final MultiBucketsAggregation multiBuckets) {
    final Map<FacetValue, Long> facetValues = new LinkedHashMap<>();
    FacetValue facetValue;
    for (final Bucket value : multiBuckets.getBuckets()) {
        final String term = value.getKeyAsString();
        final MessageText label = MessageText.of(term);
        final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
        facetValue = new FacetValue(term, ListFilter.of(query), label);
        facetValues.put(facetValue, value.getDocCount());
    }
    return new Facet(facetDefinition, facetValues);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) MessageText(io.vertigo.core.locale.MessageText) LinkedHashMap(java.util.LinkedHashMap) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 2 with MessageText

use of io.vertigo.core.locale.MessageText 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;
}
Also used : Aggregation(org.elasticsearch.search.aggregations.Aggregation) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) MessageText(io.vertigo.core.locale.MessageText) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) DtList(io.vertigo.dynamo.domain.model.DtList) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with MessageText

use of io.vertigo.core.locale.MessageText in project vertigo by KleeGroup.

the class ESFacetedQueryResultBuilder method createTermFacet.

private static Facet createTermFacet(final FacetDefinition facetDefinition, final MultiBucketsAggregation multiBuckets) {
    final Map<FacetValue, Long> facetValues = new LinkedHashMap<>();
    FacetValue facetValue;
    for (final Bucket value : multiBuckets.getBuckets()) {
        final String term = value.getKeyAsString();
        final MessageText label = MessageText.of(term);
        final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
        facetValue = new FacetValue(term, ListFilter.of(query), label);
        facetValues.put(facetValue, value.getDocCount());
    }
    return new Facet(facetDefinition, facetValues);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) MessageText(io.vertigo.core.locale.MessageText) LinkedHashMap(java.util.LinkedHashMap) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 4 with MessageText

use of io.vertigo.core.locale.MessageText in project vertigo by KleeGroup.

the class FacetFactory method createTermCluster.

private static <D extends DtObject> Map<FacetValue, DtList<D>> createTermCluster(final FacetDefinition facetDefinition, final DtList<D> dtList) {
    // map résultat avec les docs par FacetFilter
    final Map<FacetValue, DtList<D>> clusterValues = new LinkedHashMap<>();
    // Cas des facettes par Term
    final DtField dtField = facetDefinition.getDtField();
    // on garde un index pour incrémenter le facetFilter pour chaque Term
    final Map<Object, FacetValue> facetFilterIndex = new HashMap<>();
    FacetValue facetValue;
    for (final D dto : dtList) {
        final Object value = dtField.getDataAccessor().getValue(dto);
        facetValue = facetFilterIndex.get(value);
        if (facetValue == null) {
            final String valueAsString = dtField.getDomain().valueToString(value);
            final String label;
            if (StringUtil.isEmpty(valueAsString)) {
                label = "<==no label==>";
            } else {
                label = valueAsString;
            }
            final MessageText labelMsg = MessageText.of(label);
            // on garde la syntaxe Solr pour l'instant
            final ListFilter listFilter = ListFilter.of(dtField.getName() + ":\"" + valueAsString + "\"");
            facetValue = new FacetValue(label, listFilter, labelMsg);
            facetFilterIndex.put(value, facetValue);
            clusterValues.put(facetValue, new DtList<D>(dtList.getDefinition()));
        }
        clusterValues.get(facetValue).add(dto);
    }
    // tri des facettes
    final Comparator<FacetValue> facetComparator = new FacetComparator<>(clusterValues);
    final Map<FacetValue, DtList<D>> sortedFacetValues = new TreeMap<>(facetComparator);
    sortedFacetValues.putAll(clusterValues);
    return sortedFacetValues;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MessageText(io.vertigo.core.locale.MessageText) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) DtField(io.vertigo.dynamo.domain.metamodel.DtField) ListFilter(io.vertigo.dynamo.collections.ListFilter) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DtObject(io.vertigo.dynamo.domain.model.DtObject) DtList(io.vertigo.dynamo.domain.model.DtList)

Example 5 with MessageText

use of io.vertigo.core.locale.MessageText in project vertigo by KleeGroup.

the class SelectedFacetValuesDeserializer method appendTermFacetValue.

private static void appendTermFacetValue(final JsonElement value, final FacetDefinition facetDefinition, final SelectedFacetValuesBuilder selectedFacetValuesBuilder) {
    final String term = value.getAsString();
    final MessageText label = MessageText.of(term);
    final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
    final FacetValue facetValue = new FacetValue(term, ListFilter.of(query), label);
    selectedFacetValuesBuilder.add(facetDefinition, facetValue);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) MessageText(io.vertigo.core.locale.MessageText)

Aggregations

MessageText (io.vertigo.core.locale.MessageText)11 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)9 LinkedHashMap (java.util.LinkedHashMap)5 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)4 Bucket (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket)4 DtList (io.vertigo.dynamo.domain.model.DtList)3 ListFilter (io.vertigo.dynamo.collections.ListFilter)2 Facet (io.vertigo.dynamo.collections.model.Facet)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2 HashMap (java.util.HashMap)2 Aggregation (org.elasticsearch.search.aggregations.Aggregation)2 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)2 MessageKey (io.vertigo.core.locale.MessageKey)1 SelectedFacetValuesBuilder (io.vertigo.dynamo.collections.model.SelectedFacetValues.SelectedFacetValuesBuilder)1 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)1 DtObject (io.vertigo.dynamo.domain.model.DtObject)1 DslDefinition (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition)1 VUserException (io.vertigo.lang.VUserException)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1