Search in sources :

Example 16 with FacetValue

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

the class AbstractSearchManagerTest method testSortedClusterByFacetTerm.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testSortedClusterByFacetTerm() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(manufacturerFacetDefinition).build();
    final DtListState listState = new DtListState(null, 0, itemIndexDefinition.getIndexDtDefinition().getField("YEAR").getName(), true);
    final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, listState);
    // On vérifie qu'il existe une valeur pour chaque marques et que la première est bien la plus ancienne
    final Map<String, Set<Item>> databaseCluster = new HashMap<>();
    for (final Item item : itemDataBase.getAllItems()) {
        databaseCluster.computeIfAbsent(item.getManufacturer().toLowerCase(Locale.FRENCH), k -> new TreeSet<>((e1, e2) -> e2.getYear().compareTo(e1.getYear()))).add(item);
    }
    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 Item firstClusterItem = entry.getValue().get(0);
        final Set<Item> itemsByManufacturer = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(itemsByManufacturer.iterator().next().getId(), firstClusterItem.getId());
        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) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) TreeSet(java.util.TreeSet) DtListState(io.vertigo.dynamo.domain.model.DtListState) DtList(io.vertigo.dynamo.domain.model.DtList) Test(org.junit.Test)

Example 17 with FacetValue

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

the class AbstractSearchManagerTest method testFacetResultByRange.

private void testFacetResultByRange(final FacetedQueryResult<Item, ?> result) {
    Assert.assertEquals(itemDataBase.size(), result.getCount());
    // On vérifie qu'il y a le bon nombre de facettes.
    Assert.assertEquals(4, result.getFacets().size());
    // On recherche la facette date
    final Facet yearFacet = getFacetByName(result, "FCT_YEAR_ITEM");
    Assert.assertTrue(yearFacet.getDefinition().isRangeFacet());
    boolean found = false;
    for (final Entry<FacetValue, Long> entry : yearFacet.getFacetValues().entrySet()) {
        if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).contains("avant")) {
            found = true;
            Assert.assertEquals(itemDataBase.before(2000), entry.getValue().longValue());
        }
    }
    Assert.assertTrue(found);
    // on vérifie l'ordre
    final List<FacetValue> facetValueDefinition = yearFacet.getDefinition().getFacetRanges();
    final List<FacetValue> facetValueResult = new ArrayList<>(yearFacet.getFacetValues().keySet());
    // equals vérifie aussi l'ordre
    Assert.assertEquals(facetValueDefinition, facetValueResult);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) ArrayList(java.util.ArrayList) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 18 with FacetValue

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

the class AbstractSearchManagerTest method testClusterByFacetRange.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testClusterByFacetRange() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(// "avant 2000", "2000-2005", "après 2005"
    yearFacetDefinition).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<>();
    databaseCluster.put(YearCluster.before2000.getLabel(), new ArrayList<>());
    databaseCluster.put(YearCluster.between2000and2005.getLabel(), new ArrayList<>());
    databaseCluster.put(YearCluster.after2005.getLabel(), new ArrayList<>());
    for (final Item item : itemDataBase.getAllItems()) {
        if (item.getYear() < 2000) {
            databaseCluster.get(YearCluster.before2000.getLabel()).add(item);
        } else if (item.getYear() < 2005) {
            databaseCluster.get(YearCluster.between2000and2005.getLabel()).add(item);
        } else {
            databaseCluster.get(YearCluster.after2005.getLabel()).add(item);
        }
    }
    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> itemsByYear = databaseCluster.get(searchFacetLabel);
        Assert.assertEquals(itemsByYear.size(), searchFacetCount);
        for (final Item item : entry.getValue()) {
            if (item.getYear() < 2000) {
                Assert.assertEquals(searchFacetLabel, YearCluster.before2000.getLabel());
            } else if (item.getYear() < 2005) {
                Assert.assertEquals(searchFacetLabel, YearCluster.between2000and2005.getLabel());
            } else {
                Assert.assertEquals(searchFacetLabel, YearCluster.after2005.getLabel());
            }
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) HashMap(java.util.HashMap) 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 19 with FacetValue

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

the class AbstractSearchManagerTest method testClusterByFacetRangeVerySmallMaxRows.

/**
 * Test le facettage par term d'une liste.
 */
@Test
public void testClusterByFacetRangeVerySmallMaxRows() {
    index(true);
    final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(// "avant 2000", "2000-2005", "après 2005"
    yearFacetDefinition).build();
    final FacetedQueryResult<Item, SearchQuery> result = searchManager.loadList(itemIndexDefinition, searchQuery, new DtListState(1, 0, null, 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<>();
    databaseCluster.put(YearCluster.before2000.getLabel(), new ArrayList<>());
    databaseCluster.put(YearCluster.between2000and2005.getLabel(), new ArrayList<>());
    databaseCluster.put(YearCluster.after2005.getLabel(), new ArrayList<>());
    for (final Item item : itemDataBase.getAllItems()) {
        if (item.getYear() < 2000) {
            databaseCluster.get(YearCluster.before2000.getLabel()).add(item);
        } else if (item.getYear() < 2005) {
            databaseCluster.get(YearCluster.between2000and2005.getLabel()).add(item);
        } else {
            databaseCluster.get(YearCluster.after2005.getLabel()).add(item);
        }
    }
    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();
        // result == listState.top (=1)
        Assert.assertEquals(1, searchFacetCount);
        for (final Item item : entry.getValue()) {
            if (item.getYear() < 2000) {
                Assert.assertEquals(searchFacetLabel, YearCluster.before2000.getLabel());
            } else if (item.getYear() < 2005) {
                Assert.assertEquals(searchFacetLabel, YearCluster.between2000and2005.getLabel());
            } else {
                Assert.assertEquals(searchFacetLabel, YearCluster.after2005.getLabel());
            }
        }
    }
}
Also used : SearchQuery(io.vertigo.dynamo.search.model.SearchQuery) HashMap(java.util.HashMap) Item(io.vertigo.dynamo.search.data.domain.Item) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DtListState(io.vertigo.dynamo.domain.model.DtListState) 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 20 with FacetValue

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

the class ESFacetedQueryResultBuilder method createFacetRange.

private static Facet createFacetRange(final FacetDefinition facetDefinition, final MultiBucketsAggregation rangeBuckets) {
    // Cas des facettes par range
    final Map<FacetValue, Long> rangeValues = new LinkedHashMap<>();
    for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
        final Bucket value = getBucketByKey(rangeBuckets, facetRange.getListFilter().getFilterValue());
        rangeValues.put(facetRange, value.getDocCount());
    }
    return new Facet(facetDefinition, rangeValues);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) LinkedHashMap(java.util.LinkedHashMap) 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