use of io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition 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.FacetedQueryDefinition 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.FacetedQueryDefinition in project vertigo by KleeGroup.
the class SearchTestWebServices method testFacetedQueryResult.
@POST("/facetedResult")
public FacetedQueryResult<Contact, DtList<Contact>> testFacetedQueryResult(final SelectedFacetValues selectedFacetValues) {
final DtList<Contact> allContacts = asDtList(contactDao.getList(), Contact.class);
final FacetedQueryDefinition facetedQueryDefinition = Home.getApp().getDefinitionSpace().resolve("QRY_CONTACT_FACET", FacetedQueryDefinition.class);
final FacetedQuery facetedQuery = new FacetedQuery(facetedQueryDefinition, selectedFacetValues);
return collectionsManager.facetList(allContacts, facetedQuery);
}
use of io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition 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;
}
use of io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method appendFacetDefinition.
private static void appendFacetDefinition(final SearchQuery searchQuery, final SearchRequestBuilder searchRequestBuilder, final SearchIndexDefinition myIndexDefinition, final DtListState myListState, final boolean useHighlight) {
Assertion.checkNotNull(searchRequestBuilder);
// On ajoute le cluster, si présent
if (searchQuery.isClusteringFacet()) {
// si il y a un cluster on le place en premier
final FacetDefinition clusteringFacetDefinition = searchQuery.getClusteringFacetDefinition();
final AggregationBuilder aggregationBuilder = facetToAggregationBuilder(clusteringFacetDefinition);
final TopHitsAggregationBuilder topHitsBuilder = AggregationBuilders.topHits(TOPHITS_SUBAGGREGATION_NAME).size(myListState.getMaxRows().orElse(TOPHITS_SUBAGGREGATION_SIZE)).from(myListState.getSkipRows());
if (useHighlight) {
// .addHighlightedField("*"); HOW TO ?
topHitsBuilder.highlighter(new HighlightBuilder().numOfFragments(3));
}
if (myListState.getSortFieldName().isPresent()) {
topHitsBuilder.sort(getFieldSortBuilder(myIndexDefinition, myListState));
}
aggregationBuilder.subAggregation(topHitsBuilder);
// We fetch source, because it's our only source to create result list
searchRequestBuilder.addAggregation(aggregationBuilder);
}
// Puis les facettes liées à la query, si présent
if (searchQuery.getFacetedQuery().isPresent()) {
final FacetedQueryDefinition facetedQueryDefinition = searchQuery.getFacetedQuery().get().getDefinition();
final Collection<FacetDefinition> facetDefinitions = new ArrayList<>(facetedQueryDefinition.getFacetDefinitions());
if (searchQuery.isClusteringFacet() && facetDefinitions.contains(searchQuery.getClusteringFacetDefinition())) {
facetDefinitions.remove(searchQuery.getClusteringFacetDefinition());
}
for (final FacetDefinition facetDefinition : facetDefinitions) {
final AggregationBuilder aggregationBuilder = facetToAggregationBuilder(facetDefinition);
final BoolQueryBuilder aggsFilterBoolQueryBuilder = QueryBuilders.boolQuery();
for (final FacetDefinition filterFacetDefinition : searchQuery.getFacetedQuery().get().getDefinition().getFacetDefinitions()) {
if (filterFacetDefinition.isMultiSelectable() && !facetDefinition.equals(filterFacetDefinition)) {
// on ne doit refiltrer que les multiSelectable (les autres sont dans le filter de la request), sauf la facet qu'on est entrain de traiter
appendSelectedFacetValuesFilter(aggsFilterBoolQueryBuilder, searchQuery.getFacetedQuery().get().getSelectedFacetValues().getFacetValues(filterFacetDefinition));
}
}
if (aggsFilterBoolQueryBuilder.hasClauses()) {
final AggregationBuilder filterAggregationBuilder = AggregationBuilders.filter(facetDefinition.getName() + "_FILTER", aggsFilterBoolQueryBuilder);
filterAggregationBuilder.subAggregation(aggregationBuilder);
searchRequestBuilder.addAggregation(filterAggregationBuilder);
} else {
searchRequestBuilder.addAggregation(aggregationBuilder);
}
}
}
}
Aggregations