use of io.vertigo.dynamo.collections.metamodel.FacetDefinition in project vertigo by KleeGroup.
the class ESFacetedQueryResultBuilder method createCluster.
private Map<FacetValue, DtList<I>> createCluster(final Map<String, I> dtcIndex, final Map<I, Map<DtField, String>> resultHighlights) {
final Map<FacetValue, DtList<I>> resultCluster = new LinkedHashMap<>();
final FacetDefinition facetDefinition = searchQuery.getClusteringFacetDefinition();
final Aggregation facetAggregation = queryResponse.getAggregations().get(facetDefinition.getName());
if (facetDefinition.isRangeFacet()) {
// Cas des facettes par 'range'
final MultiBucketsAggregation multiBuckets = (MultiBucketsAggregation) facetAggregation;
for (final FacetValue facetRange : facetDefinition.getFacetRanges()) {
final Bucket value = getBucketByKey(multiBuckets, facetRange.getListFilter().getFilterValue());
populateCluster(value, facetRange, resultCluster, dtcIndex, resultHighlights);
}
} else {
// Cas des facettes par 'term'
final MultiBucketsAggregation multiBuckets = (MultiBucketsAggregation) facetAggregation;
FacetValue facetValue;
for (final Bucket bucket : multiBuckets.getBuckets()) {
final String term = bucket.getKeyAsString();
final String query = facetDefinition.getDtField().getName() + ":\"" + term + "\"";
final MessageText label = MessageText.of(term);
facetValue = new FacetValue(term, ListFilter.of(query), label);
populateCluster(bucket, facetValue, resultCluster, dtcIndex, resultHighlights);
}
}
return resultCluster;
}
use of io.vertigo.dynamo.collections.metamodel.FacetDefinition 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 = obtainAggregation(queryResponse, facetDefinition.getName());
if (aggregation != null) {
final Facet facet = createFacet(facetDefinition, (MultiBucketsAggregation) aggregation);
facets.add(facet);
}
}
}
return facets;
}
use of io.vertigo.dynamo.collections.metamodel.FacetDefinition in project vertigo by KleeGroup.
the class SearchDynamicRegistry method createFacetedQueryDefinition.
private static FacetedQueryDefinition createFacetedQueryDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdefinition) {
final String definitionName = xdefinition.getName();
final DtDefinition keyConceptDtDefinition = definitionSpace.resolve(xdefinition.getDefinitionLinkName("keyConcept"), DtDefinition.class);
final List<String> dynamicFacetDefinitionNames = xdefinition.getDefinitionLinkNames("facets");
final List<FacetDefinition> facetDefinitions = dynamicFacetDefinitionNames.stream().map(dynamicDefinitionName -> definitionSpace.resolve(dynamicDefinitionName, FacetDefinition.class)).collect(Collectors.toList());
final String listFilterBuilderQuery = (String) xdefinition.getPropertyValue(SearchGrammar.LIST_FILTER_BUILDER_QUERY);
final Class<? extends ListFilterBuilder> listFilterBuilderClass = getListFilterBuilderClass(xdefinition);
final String criteriaDomainName = xdefinition.getDefinitionLinkName("domainCriteria");
final Domain criteriaDomain = definitionSpace.resolve(criteriaDomainName, Domain.class);
return new FacetedQueryDefinition(definitionName, keyConceptDtDefinition, facetDefinitions, criteriaDomain, listFilterBuilderClass, listFilterBuilderQuery);
}
use of io.vertigo.dynamo.collections.metamodel.FacetDefinition in project vertigo by KleeGroup.
the class SearchQueryBuilder method withFacetClustering.
/**
* Add a clustering of result by Facet.
* @param clusteringFacetName facet used to cluster data
* @return this builder
*/
public SearchQueryBuilder withFacetClustering(final String clusteringFacetName) {
Assertion.checkArgNotEmpty(clusteringFacetName);
// -----
final FacetDefinition clusteringFacetDefinition = Home.getApp().getDefinitionSpace().resolve(clusteringFacetName, FacetDefinition.class);
withFacetClustering(clusteringFacetDefinition);
return this;
}
use of io.vertigo.dynamo.collections.metamodel.FacetDefinition in project vertigo by KleeGroup.
the class SearchTestWebServices method testSelectedFacetValues.
@POST("/selectedFacetValues")
public UiContext testSelectedFacetValues(final SelectedFacetValues selectedFacetValues) {
final FacetedQueryDefinition facetedQueryDefinition = Home.getApp().getDefinitionSpace().resolve("QRY_CONTACT_FACET", FacetedQueryDefinition.class);
final UiContext uiContext = new UiContext();
for (final FacetDefinition facetDefinition : facetedQueryDefinition.getFacetDefinitions()) {
if (!selectedFacetValues.getFacetValues(facetDefinition).isEmpty()) {
uiContext.put(facetDefinition.getName(), selectedFacetValues.getFacetValues(facetDefinition).stream().map(FacetValue::getCode).collect(Collectors.joining(",")));
}
}
return uiContext;
}
Aggregations