Search in sources :

Example 1 with Facet

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

the class AbstractSearchManagerTest method testFacetResultByTerm.

private void testFacetResultByTerm(final FacetedQueryResult<Car, ?> result) {
    Assert.assertEquals(carDataBase.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 constructeur
    final Facet makeFacet = getFacetByName(result, "FCT_MAKE_CAR");
    Assert.assertNotNull(makeFacet);
    // On vérifie que l'on est sur le champ Make
    Assert.assertEquals("MAKE", makeFacet.getDefinition().getDtField().getName());
    Assert.assertFalse(makeFacet.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 make = "peugeot";
    for (final Entry<FacetValue, Long> entry : makeFacet.getFacetValues().entrySet()) {
        if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).equals(make)) {
            found = true;
            Assert.assertEquals(carDataBase.getCarsByMaker(make).size(), entry.getValue().intValue());
        }
    }
    Assert.assertTrue(found);
    checkOrderByCount(makeFacet);
    checkOrderByAlpha(getFacetByName(result, "FCT_MAKE_CAR_ALPHA"));
    checkOrderByCount(getFacetByName(result, "FCT_DESCRIPTION_CAR"));
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 2 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<Car, ?> result) {
    Assert.assertEquals(carDataBase.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_CAR");
    Assert.assertNotNull(yearFacet);
    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(carDataBase.getCarsBefore(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 3 with Facet

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

the class ESFacetedQueryResultBuilder method createTermFacet.

private static Facet createTermFacet(final FacetDefinition facetDefinition, final MultiBucketsAggregation multiBuckets) {
    final Map<FacetValue, Long> facetValues = new LinkedHashMap<>();
    FacetValue facetValue;
    for (final Bucket value : multiBuckets.getBuckets()) {
        final String term = value.getKeyAsString();
        final MessageText label = MessageText.of(term);
        final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
        facetValue = new FacetValue(term, ListFilter.of(query), label);
        facetValues.put(facetValue, value.getDocCount());
    }
    return new Facet(facetDefinition, facetValues);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) MessageText(io.vertigo.core.locale.MessageText) LinkedHashMap(java.util.LinkedHashMap) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 4 with Facet

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

the class ESFacetedQueryResultBuilder method createTermFacet.

private static Facet createTermFacet(final FacetDefinition facetDefinition, final MultiBucketsAggregation multiBuckets) {
    final Map<FacetValue, Long> facetValues = new LinkedHashMap<>();
    FacetValue facetValue;
    for (final Bucket value : multiBuckets.getBuckets()) {
        final String term = value.getKeyAsString();
        final MessageText label = MessageText.of(term);
        final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
        facetValue = new FacetValue(term, ListFilter.of(query), label);
        facetValues.put(facetValue, value.getDocCount());
    }
    return new Facet(facetDefinition, facetValues);
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) Bucket(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket) MessageText(io.vertigo.core.locale.MessageText) LinkedHashMap(java.util.LinkedHashMap) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 5 with Facet

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

the class ESFacetedQueryResultBuilder method build.

/**
 * {@inheritDoc}
 */
@Override
public FacetedQueryResult<I, SearchQuery> build() {
    final Map<I, Map<DtField, String>> resultHighlights = new HashMap<>();
    final Map<FacetValue, DtList<I>> resultCluster;
    final DtList<I> dtc = new DtList<>(indexDefinition.getIndexDtDefinition());
    if (searchQuery.isClusteringFacet()) {
        final Map<String, I> dtcIndex = new LinkedHashMap<>();
        resultCluster = createCluster(dtcIndex, resultHighlights);
        dtc.addAll(dtcIndex.values());
    } else {
        for (final SearchHit searchHit : queryResponse.getHits()) {
            final SearchIndex<?, I> index = esDocumentCodec.searchHit2Index(indexDefinition, searchHit);
            final I result = index.getIndexDtObject();
            dtc.add(result);
            final Map<DtField, String> highlights = createHighlight(searchHit, indexDefinition.getIndexDtDefinition());
            resultHighlights.put(result, highlights);
        }
        resultCluster = Collections.emptyMap();
    }
    // On fabrique à la volée le résultat.
    final List<Facet> facets = createFacetList(searchQuery, queryResponse);
    final long count = queryResponse.getHits().getTotalHits();
    return new FacetedQueryResult<>(searchQuery.getFacetedQuery(), count, dtc, facets, searchQuery.isClusteringFacet() ? Optional.of(searchQuery.getClusteringFacetDefinition()) : Optional.empty(), resultCluster, resultHighlights, searchQuery);
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) LinkedHashMap(java.util.LinkedHashMap) DtField(io.vertigo.dynamo.domain.metamodel.DtField) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DtList(io.vertigo.dynamo.domain.model.DtList) 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