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