use of io.vertigo.dynamo.collections.model.FacetedQueryResult 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);
}
use of io.vertigo.dynamo.collections.model.FacetedQueryResult in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testClusterByFacetTerm.
/**
* Test le facettage par term d'une liste.
*/
@Test
public void testClusterByFacetTerm() {
index(true);
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(makeFacetDefinition).build();
final FacetedQueryResult<Car, SearchQuery> result = searchManager.loadList(carIndexDefinition, 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<Car>> databaseCluster = new HashMap<>();
for (final Car car : carDataBase.getAllCars()) {
databaseCluster.computeIfAbsent(car.getMake().toLowerCase(Locale.FRENCH), k -> new ArrayList<>()).add(car);
}
int previousCount = Integer.MAX_VALUE;
Assert.assertEquals(databaseCluster.size(), result.getClusters().size());
for (final Entry<FacetValue, DtList<Car>> entry : result.getClusters().entrySet()) {
final String searchFacetLabel = entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH);
final int searchFacetCount = entry.getValue().size();
final List<Car> carsByMake = databaseCluster.get(searchFacetLabel);
Assert.assertEquals(carsByMake.size(), searchFacetCount);
Assert.assertTrue("Group order invalid", previousCount >= searchFacetCount);
previousCount = searchFacetCount;
for (final Car car : entry.getValue()) {
Assert.assertEquals(searchFacetLabel, car.getMake().toLowerCase(Locale.FRENCH));
}
}
}
use of io.vertigo.dynamo.collections.model.FacetedQueryResult in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testClusterByFacetTerm.
/**
* Test le facettage par term d'une liste.
*/
@Test
public void testClusterByFacetTerm() {
index(true);
final SearchQuery searchQuery = SearchQuery.builder(ListFilter.of("*:*")).withFacetClustering(manufacturerFacetDefinition).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<>();
for (final Item item : itemDataBase.getAllItems()) {
databaseCluster.computeIfAbsent(item.getManufacturer().toLowerCase(Locale.FRENCH), k -> new ArrayList<>()).add(item);
}
int previousCount = Integer.MAX_VALUE;
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> itemsByManufacturer = databaseCluster.get(searchFacetLabel);
Assert.assertEquals(itemsByManufacturer.size(), searchFacetCount);
Assert.assertTrue("Group order invalid", previousCount >= searchFacetCount);
previousCount = searchFacetCount;
for (final Item item : entry.getValue()) {
Assert.assertEquals(searchFacetLabel, item.getManufacturer().toLowerCase(Locale.FRENCH));
}
}
}
Aggregations