Search in sources :

Example 1 with TermFacetProperties

use of ddf.catalog.operation.TermFacetProperties in project ddf by codice.

the class SolrMetacardClientImpl method handleFacetRequest.

private boolean handleFacetRequest(SolrQuery query, QueryRequest request) {
    boolean isFacetedQuery = false;
    Serializable textFacetPropRaw = request.getPropertyValue(EXPERIMENTAL_FACET_PROPERTIES_KEY);
    if (textFacetPropRaw instanceof TermFacetProperties) {
        TermFacetProperties textFacetProp = (TermFacetProperties) textFacetPropRaw;
        isFacetedQuery = true;
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Enabling faceted query for request [{}] on field {}", request, textFacetProp);
        }
        textFacetProp.getFacetAttributes().stream().map(this::addAttributeTypeSuffix).filter(attr -> attr.contains(String.valueOf(FIRST_CHAR_OF_SUFFIX))).forEach(query::addFacetField);
        query.setFacetSort(textFacetProp.getSortKey().name().toLowerCase());
        query.setFacetLimit(textFacetProp.getFacetLimit());
        query.setFacetMinCount(textFacetProp.getMinFacetCount());
    }
    return isFacetedQuery;
}
Also used : ADDITIONAL_SORT_BYS(ddf.catalog.Constants.ADDITIONAL_SORT_BYS) Arrays(java.util.Arrays) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrClient(org.codice.solr.client.solrj.SolrClient) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) LoggerFactory(org.slf4j.LoggerFactory) MetacardCreationException(ddf.catalog.data.MetacardCreationException) TermFacetProperties(ddf.catalog.operation.TermFacetProperties) AttributeType(ddf.catalog.data.AttributeType) NumberUtils(org.apache.commons.lang.math.NumberUtils) BooleanUtils(org.apache.commons.lang.BooleanUtils) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) FIRST_CHAR_OF_SUFFIX(ddf.catalog.source.solr.DynamicSchemaResolver.FIRST_CHAR_OF_SUFFIX) ContentTypeImpl(ddf.catalog.data.impl.ContentTypeImpl) Map(java.util.Map) SUGGESTION_QUERY_KEY(ddf.catalog.Constants.SUGGESTION_QUERY_KEY) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) Collection(java.util.Collection) AbstractUpdateRequest(org.apache.solr.client.solrj.request.AbstractUpdateRequest) ResultImpl(ddf.catalog.data.impl.ResultImpl) Set(java.util.Set) PrivilegedAction(java.security.PrivilegedAction) Collation(org.apache.solr.client.solrj.response.SpellCheckResponse.Collation) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) MetacardType(ddf.catalog.data.MetacardType) Serializable(java.io.Serializable) List(java.util.List) Attribute(ddf.catalog.data.Attribute) SUGGEST_DICT(org.apache.solr.spelling.suggest.SuggesterParams.SUGGEST_DICT) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Optional(java.util.Optional) SUGGEST_BUILD(org.apache.solr.spelling.suggest.SuggesterParams.SUGGEST_BUILD) AccessController(java.security.AccessController) SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) HashMap(java.util.HashMap) FilterAdapter(ddf.catalog.filter.FilterAdapter) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FacetAttributeResultImpl(ddf.catalog.operation.impl.FacetAttributeResultImpl) SortBy(org.opengis.filter.sort.SortBy) Lists(com.google.common.collect.Lists) METHOD(org.apache.solr.client.solrj.SolrRequest.METHOD) FacetAttributeResult(ddf.catalog.operation.FacetAttributeResult) Metacard(ddf.catalog.data.Metacard) CollectionUtils(org.apache.commons.collections.CollectionUtils) FacetField(org.apache.solr.client.solrj.response.FacetField) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SUGGEST_CONTEXT_FILTER_QUERY(org.apache.solr.spelling.suggest.SuggesterParams.SUGGEST_CONTEXT_FILTER_QUERY) Result(ddf.catalog.data.Result) SortOrder(org.opengis.filter.sort.SortOrder) SuggesterResponse(org.apache.solr.client.solrj.response.SuggesterResponse) ContentType(ddf.catalog.data.ContentType) Logger(org.slf4j.Logger) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) EXPERIMENTAL_FACET_PROPERTIES_KEY(ddf.catalog.Constants.EXPERIMENTAL_FACET_PROPERTIES_KEY) SUGGESTION_RESULT_KEY(ddf.catalog.Constants.SUGGESTION_RESULT_KEY) IOException(java.io.IOException) EXPERIMENTAL_FACET_RESULTS_KEY(ddf.catalog.Constants.EXPERIMENTAL_FACET_RESULTS_KEY) CommonParams(org.apache.solr.common.params.CommonParams) SUGGESTION_BUILD_KEY(ddf.catalog.Constants.SUGGESTION_BUILD_KEY) SolrDocument(org.apache.solr.common.SolrDocument) SourceResponse(ddf.catalog.operation.SourceResponse) AbstractMap(java.util.AbstractMap) SUGGESTION_DICT_KEY(ddf.catalog.Constants.SUGGESTION_DICT_KEY) PivotField(org.apache.solr.client.solrj.response.PivotField) Distance(ddf.measure.Distance) SUGGESTION_CONTEXT_KEY(ddf.catalog.Constants.SUGGESTION_CONTEXT_KEY) Collections(java.util.Collections) SUGGEST_Q(org.apache.solr.spelling.suggest.SuggesterParams.SUGGEST_Q) Serializable(java.io.Serializable) TermFacetProperties(ddf.catalog.operation.TermFacetProperties)

Example 2 with TermFacetProperties

use of ddf.catalog.operation.TermFacetProperties in project ddf by codice.

the class FacetAttributeAccessPlugin method processPreQuery.

@Override
public QueryRequest processPreQuery(QueryRequest input) throws StopProcessingException {
    if (input.getProperties().get(EXPERIMENTAL_FACET_PROPERTIES_KEY) instanceof TermFacetProperties) {
        TermFacetProperties facetProperties = (TermFacetProperties) input.getProperties().get(EXPERIMENTAL_FACET_PROPERTIES_KEY);
        Set<String> facetAttributes = facetProperties.getFacetAttributes();
        for (String attr : facetAttributes) {
            if (!config.getFacetAttributeWhitelist().contains(attr)) {
                throw new StopProcessingException("Invalid Facet Attribute Detected: " + attr);
            }
        }
    }
    return input;
}
Also used : StopProcessingException(ddf.catalog.plugin.StopProcessingException) TermFacetProperties(ddf.catalog.operation.TermFacetProperties)

Aggregations

TermFacetProperties (ddf.catalog.operation.TermFacetProperties)2 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 ADDITIONAL_SORT_BYS (ddf.catalog.Constants.ADDITIONAL_SORT_BYS)1 EXPERIMENTAL_FACET_PROPERTIES_KEY (ddf.catalog.Constants.EXPERIMENTAL_FACET_PROPERTIES_KEY)1 EXPERIMENTAL_FACET_RESULTS_KEY (ddf.catalog.Constants.EXPERIMENTAL_FACET_RESULTS_KEY)1 SUGGESTION_BUILD_KEY (ddf.catalog.Constants.SUGGESTION_BUILD_KEY)1 SUGGESTION_CONTEXT_KEY (ddf.catalog.Constants.SUGGESTION_CONTEXT_KEY)1 SUGGESTION_DICT_KEY (ddf.catalog.Constants.SUGGESTION_DICT_KEY)1 SUGGESTION_QUERY_KEY (ddf.catalog.Constants.SUGGESTION_QUERY_KEY)1 SUGGESTION_RESULT_KEY (ddf.catalog.Constants.SUGGESTION_RESULT_KEY)1 Attribute (ddf.catalog.data.Attribute)1 AttributeType (ddf.catalog.data.AttributeType)1 ContentType (ddf.catalog.data.ContentType)1 Metacard (ddf.catalog.data.Metacard)1 MetacardCreationException (ddf.catalog.data.MetacardCreationException)1 MetacardType (ddf.catalog.data.MetacardType)1 Result (ddf.catalog.data.Result)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 ContentTypeImpl (ddf.catalog.data.impl.ContentTypeImpl)1