Search in sources :

Example 11 with FacetDefinition

use of io.vertigo.dynamo.collections.metamodel.FacetDefinition in project vertigo by KleeGroup.

the class SearchDynamicRegistry method createFacetDefinition.

private static FacetDefinition createFacetDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdefinition) {
    final String definitionName = xdefinition.getName();
    final DtDefinition indexDtDefinition = definitionSpace.resolve(xdefinition.getDefinitionLinkName("dtDefinition"), DtDefinition.class);
    final String dtFieldName = (String) xdefinition.getPropertyValue(SearchGrammar.FIELD_NAME);
    final DtField dtField = indexDtDefinition.getField(dtFieldName);
    final String label = (String) xdefinition.getPropertyValue(KspProperty.LABEL);
    // Déclaration des ranges
    final List<DslDefinition> rangeDefinitions = xdefinition.getChildDefinitions("range");
    final MessageText labelMsg = MessageText.of(label);
    final FacetDefinition facetDefinition;
    if (rangeDefinitions.isEmpty()) {
        facetDefinition = FacetDefinition.createFacetDefinitionByTerm(definitionName, dtField, labelMsg, isMultiSelectable(xdefinition, false), getFacetOrder(xdefinition, FacetOrder.count));
    } else {
        final List<FacetValue> facetValues = rangeDefinitions.stream().map(SearchDynamicRegistry::createFacetValue).collect(Collectors.toList());
        facetDefinition = FacetDefinition.createFacetDefinitionByRange(definitionName, dtField, labelMsg, facetValues, isMultiSelectable(xdefinition, false), getFacetOrder(xdefinition, FacetOrder.definition));
    }
    return facetDefinition;
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) MessageText(io.vertigo.core.locale.MessageText) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 12 with FacetDefinition

use of io.vertigo.dynamo.collections.metamodel.FacetDefinition in project vertigo by KleeGroup.

the class CollectionsManagerImpl method filter.

// =========================================================================
// =======================Filtrage==========================================
// =========================================================================
private <D extends DtObject> Predicate<D> filter(final FacetedQuery facetedQuery) {
    final SelectedFacetValues selectedFacetValues = facetedQuery.getSelectedFacetValues();
    Predicate<D> predicate = list -> true;
    for (final FacetDefinition facetDefinition : facetedQuery.getDefinition().getFacetDefinitions()) {
        if (!selectedFacetValues.getFacetValues(facetDefinition).isEmpty()) {
            Predicate<D> predicateValue = list -> false;
            for (final FacetValue facetValue : selectedFacetValues.getFacetValues(facetDefinition)) {
                predicateValue = predicateValue.or(this.filter(facetValue.getListFilter()));
            }
            predicate = predicate.and(predicateValue);
        }
    }
    return predicate;
}
Also used : ListFilter(io.vertigo.dynamo.collections.ListFilter) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Facet(io.vertigo.dynamo.collections.model.Facet) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) DtListPatternFilter(io.vertigo.dynamo.impl.collections.functions.filter.DtListPatternFilter) Predicate(java.util.function.Predicate) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) FacetFactory(io.vertigo.dynamo.impl.collections.facet.model.FacetFactory) DtList(io.vertigo.dynamo.domain.model.DtList) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) List(java.util.List) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) DtObject(io.vertigo.dynamo.domain.model.DtObject) Optional(java.util.Optional) IndexDtListFunctionBuilder(io.vertigo.dynamo.collections.IndexDtListFunctionBuilder) VCollectors(io.vertigo.dynamo.domain.util.VCollectors) Comparator(java.util.Comparator) Collections(java.util.Collections) CollectionsManager(io.vertigo.dynamo.collections.CollectionsManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition)

Example 13 with FacetDefinition

use of io.vertigo.dynamo.collections.metamodel.FacetDefinition 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 14 with FacetDefinition

use of io.vertigo.dynamo.collections.metamodel.FacetDefinition 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 15 with FacetDefinition

use of io.vertigo.dynamo.collections.metamodel.FacetDefinition in project vertigo by KleeGroup.

the class SelectedFacetValuesDeserializer method deserialize.

@Override
public SelectedFacetValues deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) {
    final SelectedFacetValuesBuilder selectedFacetValuesBuilder = SelectedFacetValues.empty();
    final JsonObject jsonObject = json.getAsJsonObject();
    for (final Entry<String, JsonElement> entry : jsonObject.entrySet()) {
        final FacetDefinition facetDefinition = Home.getApp().getDefinitionSpace().resolve(entry.getKey(), FacetDefinition.class);
        if (facetDefinition.isRangeFacet()) {
            appendRangeFacetValues(entry.getValue(), facetDefinition, selectedFacetValuesBuilder);
        } else {
            appendTermFacetValues(entry.getValue(), facetDefinition, selectedFacetValuesBuilder);
        }
    }
    return selectedFacetValuesBuilder.build();
}
Also used : SelectedFacetValuesBuilder(io.vertigo.dynamo.collections.model.SelectedFacetValues.SelectedFacetValuesBuilder) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition)

Aggregations

FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)15 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)8 ArrayList (java.util.ArrayList)7 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)6 MessageText (io.vertigo.core.locale.MessageText)5 Map (java.util.Map)5 DtList (io.vertigo.dynamo.domain.model.DtList)4 HashMap (java.util.HashMap)4 Aggregation (org.elasticsearch.search.aggregations.Aggregation)4 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)4 ListFilter (io.vertigo.dynamo.collections.ListFilter)3 Facet (io.vertigo.dynamo.collections.model.Facet)3 DtField (io.vertigo.dynamo.domain.metamodel.DtField)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 SelectedFacetValuesBuilder (io.vertigo.dynamo.collections.model.SelectedFacetValues.SelectedFacetValuesBuilder)2 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)2 DslDefinition (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition)2 Assertion (io.vertigo.lang.Assertion)2 Bucket (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket)2