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;
}
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;
}
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();
}
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;
}
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();
}
Aggregations