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