Search in sources :

Example 6 with FacetedQueryDefinition

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 = queryResponse.getAggregations().get(facetDefinition.getName());
            if (aggregation != null) {
                final Facet facet = createFacet(facetDefinition, (MultiBucketsAggregation) aggregation);
                facets.add(facet);
            }
        }
    }
    return facets;
}
Also used : Aggregation(org.elasticsearch.search.aggregations.Aggregation) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) ArrayList(java.util.ArrayList) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) Facet(io.vertigo.dynamo.collections.model.Facet)

Example 7 with FacetedQueryDefinition

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) {
    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 TopHitsBuilder topHitsBuilder = AggregationBuilders.topHits(TOPHITS_SUBAGGREGATION_NAME).setSize(myListState.getMaxRows().orElse(TOPHITS_SUBAGGREGATION_SIZE)).setFrom(myListState.getSkipRows()).setHighlighterNumOfFragments(3).addHighlightedField("*");
        if (myListState.getSortFieldName().isPresent()) {
            topHitsBuilder.addSort(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);
            searchRequestBuilder.addAggregation(aggregationBuilder);
        }
    }
}
Also used : TopHitsBuilder(org.elasticsearch.search.aggregations.metrics.tophits.TopHitsBuilder) ArrayList(java.util.ArrayList) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)

Aggregations

FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)7 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)6 ArrayList (java.util.ArrayList)5 Facet (io.vertigo.dynamo.collections.model.Facet)2 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)2 POST (io.vertigo.vega.webservice.stereotype.POST)2 Aggregation (org.elasticsearch.search.aggregations.Aggregation)2 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)2 Definition (io.vertigo.core.definition.Definition)1 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)1 DefinitionSupplier (io.vertigo.core.definition.DefinitionSupplier)1 MessageText (io.vertigo.core.locale.MessageText)1 ListFilter (io.vertigo.dynamo.collections.ListFilter)1 FacetOrder (io.vertigo.dynamo.collections.metamodel.FacetDefinition.FacetOrder)1 ListFilterBuilder (io.vertigo.dynamo.collections.metamodel.ListFilterBuilder)1 FacetedQuery (io.vertigo.dynamo.collections.model.FacetedQuery)1 Domain (io.vertigo.dynamo.domain.metamodel.Domain)1 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)1 DtField (io.vertigo.dynamo.domain.metamodel.DtField)1 KspProperty (io.vertigo.dynamo.plugins.environment.KspProperty)1