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);
}
use of io.vertigo.dynamo.collections.model.Facet in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method createFacetList.
private static List<Facet> createFacetList(final SearchQuery searchQuery, final SearchResponse queryResponse) {
final List<Facet> facets = new ArrayList<>();
if (searchQuery.getFacetedQuery().isPresent() && queryResponse.getAggregations() != null) {
final FacetedQueryDefinition queryDefinition = searchQuery.getFacetedQuery().get().getDefinition();
for (final FacetDefinition facetDefinition : queryDefinition.getFacetDefinitions()) {
final Aggregation aggregation = queryResponse.getAggregations().get(facetDefinition.getName());
if (aggregation != null) {
final Facet facet = createFacet(facetDefinition, (MultiBucketsAggregation) aggregation);
facets.add(facet);
}
}
}
return facets;
}
use of io.vertigo.dynamo.collections.model.Facet in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method createFacetQuery.
private static FacetedQuery createFacetQuery(final String facetName, final String facetValueLabel, final FacetedQueryResult<Car, ?> result) {
// pb d'initialisation, et assert.notNull ne suffit pas
FacetValue facetValue = null;
final Facet facet = getFacetByName(result, facetName);
for (final Entry<FacetValue, Long> entry : facet.getFacetValues().entrySet()) {
if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).contains(facetValueLabel)) {
facetValue = entry.getKey();
break;
}
}
if (facetValue == null) {
throw new IllegalArgumentException("Pas de FacetValue contenant " + facetValueLabel + " dans la facette " + facetName);
}
final FacetedQuery previousQuery = result.getFacetedQuery().get();
final SelectedFacetValues queryFilters = SelectedFacetValues.of(previousQuery.getSelectedFacetValues()).add(facet.getDefinition(), facetValue).build();
return new FacetedQuery(previousQuery.getDefinition(), queryFilters);
}
use of io.vertigo.dynamo.collections.model.Facet in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method testFacetResultByTerm.
private void testFacetResultByTerm(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 constructeur
final Facet manufacturerFacet = getFacetByName(result, "FCT_MANUFACTURER_ITEM");
// On vérifie que l'on est sur le champ Manufacturer
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;
Assert.assertEquals(itemDataBase.getItemsByManufacturer(manufacturer).size(), entry.getValue().intValue());
}
}
Assert.assertTrue(found);
checkOrderByCount(manufacturerFacet);
checkOrderByAlpha(getFacetByName(result, "FCT_MANUFACTURER_ITEM_ALPHA"));
checkOrderByCount(getFacetByName(result, "FCT_DESCRIPTION_ITEM"));
}
use of io.vertigo.dynamo.collections.model.Facet in project vertigo by KleeGroup.
the class AbstractSearchManagerTest method createFacetQuery.
private static FacetedQuery createFacetQuery(final String facetName, final String facetValueLabel, final FacetedQueryResult<Item, ?> result) {
// pb d'initialisation, et assert.notNull ne suffit pas
FacetValue facetValue = null;
final Facet facet = getFacetByName(result, facetName);
for (final Entry<FacetValue, Long> entry : facet.getFacetValues().entrySet()) {
if (entry.getKey().getLabel().getDisplay().toLowerCase(Locale.FRENCH).contains(facetValueLabel)) {
facetValue = entry.getKey();
break;
}
}
if (facetValue == null) {
throw new IllegalArgumentException("Pas de FacetValue contenant " + facetValueLabel + " dans la facette " + facetName);
}
final FacetedQuery previousQuery = result.getFacetedQuery().get();
final SelectedFacetValues queryFilters = SelectedFacetValues.of(previousQuery.getSelectedFacetValues()).add(facet.getDefinition(), facetValue).build();
return new FacetedQuery(previousQuery.getDefinition(), queryFilters);
}
Aggregations