Search in sources :

Example 36 with FacetValue

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));
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ListFilter(io.vertigo.dynamo.collections.ListFilter) ItemSearchLoader(io.vertigo.dynamo.search.data.domain.ItemSearchLoader) URLDecoder(java.net.URLDecoder) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) URI(io.vertigo.dynamo.domain.model.URI) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) Facet(io.vertigo.dynamo.collections.model.Facet) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Locale(java.util.Locale) Map(java.util.Map) SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) ItemDataBase(io.vertigo.dynamo.search.data.domain.ItemDataBase) Item(io.vertigo.dynamo.search.data.domain.Item) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) Set(java.util.Set) AbstractTestCaseJU4(io.vertigo.AbstractTestCaseJU4) Test(org.junit.Test) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) DtList(io.vertigo.dynamo.domain.model.DtList) SearchIndex(io.vertigo.dynamo.search.model.SearchIndex) Collectors(java.util.stream.Collectors) File(java.io.File) DtListState(io.vertigo.dynamo.domain.model.DtListState) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) VUserException(io.vertigo.lang.VUserException) List(java.util.List) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Logger(org.apache.logging.log4j.Logger) Entry(java.util.Map.Entry) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) ArrayList(java.util.ArrayList) DtList(io.vertigo.dynamo.domain.model.DtList) List(java.util.List) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 37 with FacetValue

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);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 38 with FacetValue

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;
}
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 39 with FacetValue

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);
}
Also used : ListFilter(io.vertigo.dynamo.collections.ListFilter) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) MessageText(io.vertigo.core.locale.MessageText)

Example 40 with FacetValue

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

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