Search in sources :

Example 11 with Facet

use of io.vertigo.dynamo.collections.model.Facet 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 12 with Facet

use of io.vertigo.dynamo.collections.model.Facet 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)

Example 13 with Facet

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

the class FacetManagerTest method testFacetResultByTerm.

private void testFacetResultByTerm(final FacetedQueryResult<SmartCar, ?> result) {
    Assert.assertEquals(smartCarDataBase.size(), result.getCount());
    // On vérifie qu'il y a le bon nombre de facettes.
    Assert.assertEquals(3, result.getFacets().size());
    // On recherche la facette constructeur
    final Facet manufacturerFacet = getFacetByName(result, "FCT_MANUFACTURER_CAR");
    // On vérifie que l'on est sur le champ Make
    Assert.assertEquals("MANUFACTURER", manufacturerFacet.getDefinition().getDtField().getName());
    Assert.assertFalse(manufacturerFacet.getDefinition().isRangeFacet());
    // On vérifie qu'il existe une valeur pour peugeot et que le nombre d'occurrences est correct
    boolean found = false;
    final String manufacturer = "peugeot";
    for (final Entry<FacetValue, Long> entry : manufacturerFacet.getFacetValues().entrySet()) {
        if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).equals(manufacturer)) {
            found = true;
            // System.out.println("manufacturer" + entry.getKey().getLabel().getDisplay());
            Assert.assertEquals(smartCarDataBase.getCarsByManufacturer(manufacturer).size(), entry.getValue().intValue());
        }
    }
    Assert.assertTrue(found);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 14 with Facet

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

the class FacetManagerTest method testFacetResultByRange.

private void testFacetResultByRange(final FacetedQueryResult<SmartCar, ?> result) {
    Assert.assertEquals(smartCarDataBase.size(), result.getCount());
    // On vérifie qu'il y a le bon nombre de facettes.
    Assert.assertEquals(3, result.getFacets().size());
    // On recherche la facette date
    final Facet yearFacet = getFacetByName(result, "FCT_YEAR_CAR");
    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(smartCarDataBase.getCarsBefore(2000), entry.getValue().longValue());
        }
    }
    Assert.assertTrue(found);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 15 with Facet

use of io.vertigo.dynamo.collections.model.Facet 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

Facet (io.vertigo.dynamo.collections.model.Facet)21 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)19 LinkedHashMap (java.util.LinkedHashMap)6 JsonArray (com.google.gson.JsonArray)4 JsonObject (com.google.gson.JsonObject)4 DtList (io.vertigo.dynamo.domain.model.DtList)4 ArrayList (java.util.ArrayList)4 Bucket (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket)4 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)3 FacetedQueryResult (io.vertigo.dynamo.collections.model.FacetedQueryResult)3 SelectedFacetValues (io.vertigo.dynamo.collections.model.SelectedFacetValues)3 MessageText (io.vertigo.core.locale.MessageText)2 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)2 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SearchHit (org.elasticsearch.search.SearchHit)2 Aggregation (org.elasticsearch.search.aggregations.Aggregation)2 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)2