use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testClusterByFacetTerm.
/**
* Test le facettage par term d'une liste.
*/
@Test
public void testClusterByFacetTerm() {
index(true);
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(manufacturerFacetDefinition).build();
final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, null);
// On vérifie qu'il existe une valeur pour chaque marques et que le nombre d'occurrences est correct
final Map<String, List<Item>> databaseCluster = new HashMap<>();
for (final Item item : itemDataBase.getAllItems()) {
databaseCluster.computeIfAbsent(item.getManufacturer().toLowerCase(Locale.FRENCH), k -> new ArrayList<>()).add(item);
}
int previousCount = Integer.MAX_VALUE;
Assert.assertEquals(databaseCluster.size(), result.getClusters().size());
for (final Entry<FacetValue, DtList<Item>> entry : result.getClusters().entrySet()) {
final String searchFacetLabel = entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH);
final int searchFacetCount = entry.getValue().size();
final List<Item> itemsByManufacturer = databaseCluster.get(searchFacetLabel);
Assert.assertEquals(itemsByManufacturer.size(), searchFacetCount);
Assert.assertTrue("Group order invalid", previousCount >= searchFacetCount);
previousCount = searchFacetCount;
for (final Item item : entry.getValue()) {
Assert.assertEquals(searchFacetLabel, item.getManufacturer().toLowerCase(Locale.FRENCH));
}
}
}
use of io.vertigo.dynamo.collections.model.FacetValue in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method createFacetQuery.
private static FacetedQuery createFacetQuery(final String facetName, final String facetValueLabel, final FacetedQueryResult<Item, ?> result) {
// pb d'initialisation, et assert.notNull ne suffit pas
FacetValue facetValue = null;
final Facet facet = getFacetByName(result, facetName);
for (final Entry<FacetValue, Long> entry : facet.getFacetValues().entrySet()) {
if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).contains(facetValueLabel)) {
facetValue = entry.getKey();
break;
}
}
if (facetValue == null) {
throw new IllegalArgumentException("Pas de FacetValue contenant " + facetValueLabel + " dans la facette " + facetName);
}
final FacetedQuery previousQuery = result.getFacetedQuery().get();
final SelectedFacetValues queryFilters = SelectedFacetValues.of(previousQuery.getSelectedFacetValues()).add(facet.getDefinition(), facetValue).build();
return new FacetedQuery(previousQuery.getDefinition(), queryFilters);
}
use of io.vertigo.dynamo.collections.model.FacetValue 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.model.FacetValue in project vertigo by KleeGroup.
the class SearchDynamicRegistry method createFacetValue.
private static FacetValue createFacetValue(final DslDefinition rangeDefinition) {
final String listFilterString = (String) rangeDefinition.getPropertyValue(SearchGrammar.RANGE_FILTER_PROPERTY);
final ListFilter listFilter = ListFilter.of(listFilterString);
final String label = (String) rangeDefinition.getPropertyValue(KspProperty.LABEL);
final MessageText labelMsg = MessageText.of(label);
final String code = rangeDefinition.getName();
return new FacetValue(code, listFilter, labelMsg);
}
use of io.vertigo.dynamo.collections.model.FacetValue 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;
}
Aggregations