Search in sources :

Example 1 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 = obtainAggregation(queryResponse, 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 2 with FacetedQueryDefinition

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);
}
Also used : Arrays(java.util.Arrays) ListFilter(io.vertigo.dynamo.collections.ListFilter) DtField(io.vertigo.dynamo.domain.metamodel.DtField) HashMap(java.util.HashMap) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) ArrayList(java.util.ArrayList) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) KspProperty(io.vertigo.dynamo.plugins.environment.KspProperty) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslGrammar(io.vertigo.dynamo.plugins.environment.dsl.entity.DslGrammar) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) ClassUtil(io.vertigo.util.ClassUtil) Collectors(java.util.stream.Collectors) Definition(io.vertigo.core.definition.Definition) MessageText(io.vertigo.core.locale.MessageText) List(java.util.List) ListFilterBuilder(io.vertigo.dynamo.collections.metamodel.ListFilterBuilder) DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) DefinitionSupplier(io.vertigo.core.definition.DefinitionSupplier) FacetOrder(io.vertigo.dynamo.collections.metamodel.FacetDefinition.FacetOrder) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DynamicRegistry(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DynamicRegistry) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)

Example 3 with FacetedQueryDefinition

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);
}
Also used : FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) Contact(io.vertigo.vega.webservice.data.domain.Contact) POST(io.vertigo.vega.webservice.stereotype.POST)

Example 4 with FacetedQueryDefinition

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;
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) UiContext(io.vertigo.vega.engines.webservice.json.UiContext) POST(io.vertigo.vega.webservice.stereotype.POST)

Example 5 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, 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);
            }
        }
    }
}
Also used : AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) RangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder) DateRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder) TopHitsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregationBuilder) TopHitsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregationBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ArrayList(java.util.ArrayList) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) HighlightBuilder(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder)

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