Search in sources :

Example 41 with FacetValue

use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.

the class FacetFactory method createRangeCluster.

private <D extends DtObject> Map<FacetValue, DtList<D>> createRangeCluster(final FacetDefinition facetDefinition, final DtList<D> dtList) {
    // map résultat avec les docs par FacetFilter
    final Map<FacetValue, DtList<D>> clusterValues = new LinkedHashMap<>();
    for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
        // Pour chaque Valeur de facette on trouve les élements.
        final DtList<D> facetFilteredList = apply(facetRange.getListFilter(), dtList);
        clusterValues.put(facetRange, facetFilteredList);
    }
    return clusterValues;
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DtList(io.vertigo.dynamo.domain.model.DtList) LinkedHashMap(java.util.LinkedHashMap)

Example 42 with FacetValue

use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.

the class UiSelectedFacets method toSelectedFacetValues.

/**
 * Convert this Ui Selected Facets to a SelectedFacetValues.
 * @return ListFilter for these Facets
 */
public SelectedFacetValues toSelectedFacetValues() {
    final SelectedFacetValuesBuilder selectedFacetValuesBuilder = SelectedFacetValues.empty();
    // facet selection list.
    for (final Map.Entry<String, String> entry : entrySet()) {
        final FacetDefinition facetDefinition = Home.getApp().getDefinitionSpace().resolve(entry.getKey(), FacetDefinition.class);
        if (facetDefinition.isRangeFacet()) {
            final String label = entry.getValue();
            for (final FacetValue facet : facetDefinition.getFacetRanges()) {
                if (facet.getLabel().getDisplay().equals(label)) {
                    selectedFacetValuesBuilder.add(facetDefinition, facet);
                    break;
                }
            }
        } else {
            final String term = entry.getValue();
            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);
        }
    }
    return selectedFacetValuesBuilder.build();
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) SelectedFacetValuesBuilder(io.vertigo.dynamo.collections.model.SelectedFacetValues.SelectedFacetValuesBuilder) MessageText(io.vertigo.core.locale.MessageText) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 43 with FacetValue

use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.

the class UiSelectedFacets method toListFilters.

/**
 * Convert this Selected Facets to a list of ListFilter.
 * @return ListFilter for these Facets
 */
public List<ListFilter> toListFilters() {
    final List<ListFilter> listFilters = new ArrayList<>(size());
    // facet selection list.
    for (final Map.Entry<String, String> entry : entrySet()) {
        final FacetDefinition facetDefinition = Home.getApp().getDefinitionSpace().resolve(entry.getKey(), FacetDefinition.class);
        if (facetDefinition.isRangeFacet()) {
            for (final FacetValue facet : facetDefinition.getFacetRanges()) {
                if (facet.getCode().equals(entry.getValue())) {
                    listFilters.add(facet.getListFilter());
                    break;
                }
            }
        } else {
            final ListFilter filter = ListFilter.of(facetDefinition.getDtField().getName() + ":\"" + entry.getValue() + "\"");
            listFilters.add(filter);
        }
    }
    return listFilters;
}
Also used : ListFilter(io.vertigo.dynamo.collections.ListFilter) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) ArrayList(java.util.ArrayList) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Map(java.util.Map) HashMap(java.util.HashMap)

Example 44 with FacetValue

use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.

the class FacetedQueryResultJsonSerializerV2 method serialize.

/**
 * {@inheritDoc}
 */
@Override
public JsonElement serialize(final FacetedQueryResult<?, ?> facetedQueryResult, final Type typeOfSrc, final JsonSerializationContext context) {
    final JsonObject jsonObject = new JsonObject();
    // 1- add result list as data
    if (facetedQueryResult.getClusters().isEmpty()) {
        final JsonArray jsonList = (JsonArray) context.serialize(facetedQueryResult.getDtList());
        jsonObject.add("list", jsonList);
    } else {
        // if it's a cluster add data's cluster
        final JsonArray jsonCluster = new JsonArray();
        for (final Entry<FacetValue, ?> cluster : facetedQueryResult.getClusters().entrySet()) {
            final JsonArray jsonList = (JsonArray) context.serialize(cluster.getValue());
            final JsonObject jsonClusterElement = new JsonObject();
            jsonClusterElement.add(cluster.getKey().getLabel().getDisplay(), jsonList);
            jsonCluster.add(jsonClusterElement);
        }
        jsonObject.add("groups", jsonCluster);
    }
    // 2- add facet list as facets
    final List<Facet> facets = facetedQueryResult.getFacets();
    final JsonArray jsonFacet = new JsonArray();
    for (final Facet facet : facets) {
        final JsonArray jsonFacetValues = new JsonArray();
        for (final Entry<FacetValue, Long> entry : facet.getFacetValues().entrySet()) {
            final JsonObject jsonFacetValuesElement = new JsonObject();
            jsonFacetValuesElement.addProperty(entry.getKey().getLabel().getDisplay(), entry.getValue());
            jsonFacetValues.add(jsonFacetValuesElement);
        }
        final String facetName = facet.getDefinition().getName();
        final JsonObject jsonFacetElement = new JsonObject();
        jsonFacetElement.add(facetName, jsonFacetValues);
        jsonFacet.add(jsonFacetElement);
    }
    jsonObject.add("facets", jsonFacet);
    // 3 -add totalCount
    jsonObject.addProperty(DtList.TOTAL_COUNT_META, facetedQueryResult.getCount());
    return jsonObject;
}
Also used : JsonArray(com.google.gson.JsonArray) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) JsonObject(com.google.gson.JsonObject) Facet(io.vertigo.dynamo.collections.model.Facet)

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