Example usage for org.apache.solr.search QueryParsing getLocalParams

List of usage examples for org.apache.solr.search QueryParsing getLocalParams

Introduction

In this page you can find the example usage for org.apache.solr.search QueryParsing getLocalParams.

Prototype

public static SolrParams getLocalParams(String txt, SolrParams params) throws SyntaxError 

Source Link

Document

"foo" returns null "{!prefix f=myfield}yes" returns type="prefix",f="myfield",v="yes" "{!prefix f=myfield v=$p}" returns type="prefix",f="myfield",v=params.get("p")

Usage

From source file:fi.nationallibrary.ndl.solr.request.RangeFieldFacets.java

License:Apache License

void parseParams(String type, String param) throws ParseException, IOException {
    localParams = QueryParsing.getLocalParams(param, req.getParams());
    base = docs;/* ww  w.  j av  a  2 s.  co m*/
    facetValue = param;
    key = param;

    if (localParams == null)
        return;

    // remove local params unless it's a query
    if (type != FacetParams.FACET_QUERY) {
        facetValue = localParams.get(CommonParams.VALUE);
    }

    // reset set the default key now that localParams have been removed
    key = facetValue;

    // allow explicit set of the key
    key = localParams.get(CommonParams.OUTPUT_KEY, key);

    // figure out if we need a new base DocSet
    String excludeStr = localParams.get(CommonParams.EXCLUDE);
    if (excludeStr == null)
        return;

    Map tagMap = (Map) req.getContext().get("tags");
    if (tagMap != null && rb != null) {
        List<String> excludeTagList = StrUtils.splitSmart(excludeStr, ',');

        IdentityHashMap<Query, Boolean> excludeSet = new IdentityHashMap<Query, Boolean>();
        for (String excludeTag : excludeTagList) {
            Object olst = tagMap.get(excludeTag);
            // tagMap has entries of List<String,List<QParser>>, but subject to change in the future
            if (!(olst instanceof Collection))
                continue;
            for (Object o : (Collection) olst) {
                if (!(o instanceof QParser))
                    continue;
                QParser qp = (QParser) o;
                excludeSet.put(qp.getQuery(), Boolean.TRUE);
            }
        }
        if (excludeSet.size() == 0)
            return;

        List<Query> qlist = new ArrayList<Query>();

        // add the base query
        if (!excludeSet.containsKey(rb.getQuery())) {
            qlist.add(rb.getQuery());
        }

        // add the filters
        if (rb.getFilters() != null) {
            for (Query q : rb.getFilters()) {
                if (!excludeSet.containsKey(q)) {
                    qlist.add(q);
                }
            }
        }

        // get the new base docset for this facet
        base = searcher.getDocSet(qlist);
    }

}

From source file:org.jahia.services.search.facets.SimpleJahiaJcrFacets.java

License:Open Source License

@SuppressWarnings("unused")
void parseParams(String type, String param) throws ParseException, IOException {
    // TODO: Should we activate that and how ? - we have no request object in backend        
    //        localParams = QueryParsing.getLocalParams(param, req.getParams());
    localParams = QueryParsing.getLocalParams(param, params);
    base = docs;/*w  ww .  j  a v  a2 s.  c om*/
    facetValue = param;
    key = param;

    if (localParams == null)
        return;

    // remove local params unless it's a query
    if (!FacetParams.FACET_QUERY.equals(type)) {
        facetValue = localParams.get(CommonParams.VALUE);
    }

    // reset set the default key now that localParams have been removed
    key = facetValue;

    // allow explicit set of the key
    key = localParams.get(CommonParams.OUTPUT_KEY, key);

    // figure out if we need a new base DocSet
    String excludeStr = localParams.get(CommonParams.EXCLUDE);
    if (excludeStr == null)
        return;

    // TODO: Should we activate that and how ? - we have no request object in backend
    //        Map tagMap = (Map)req.getContext().get("tags");
    /*if (tagMap != null && rb != null) {
      List<String> excludeTagList = StrUtils.splitSmart(excludeStr,',');
            
      IdentityHashMap<Query,Boolean> excludeSet = new IdentityHashMap<Query,Boolean>();
      for (String excludeTag : excludeTagList) {
    Object olst = tagMap.get(excludeTag);
    // tagMap has entries of List<String,List<QParser>>, but subject to change in the future
    if (!(olst instanceof Collection)) continue;
    for (Object o : (Collection<?>)olst) {
      if (!(o instanceof QParser)) continue;
      QParser qp = (QParser)o;
      excludeSet.put(qp.getQuery(), Boolean.TRUE);
    }
      }
      if (excludeSet.size() == 0) return;
            
      List<Query> qlist = new ArrayList<Query>();
            
      // add the base query
      if (!excludeSet.containsKey(rb.getQuery())) {
    qlist.add(rb.getQuery());
      }
            
      // add the filters
      if (rb.getFilters() != null) {
    for (Query q : rb.getFilters()) {
      if (!excludeSet.containsKey(q)) {
        qlist.add(q);
      }
    }
      }
            
      // get the new base docset for this facet
      base = getDocIdSet(qlist, "");
    }*/

}

From source file:uk.co.flax.biosolr.TreeFacetComponent.java

License:Apache License

private void addTreeFieldsToFacets(ResponseBuilder rb) throws SyntaxError {
    String[] ftFields = rb.req.getParams().getParams(FACET_TREE_FIELD);
    if (ftFields == null || ftFields.length == 0) {
        LOGGER.warn("No facet tree fields specified - ignoring facet trees");
    } else {//  w w w .  j  a va  2 s  .co  m
        // Take a modifiable copy of the incoming params
        ModifiableSolrParams params = new ModifiableSolrParams(rb.req.getParams());

        // Put the original facet fields (if any) into a Set
        Set<String> facetFields = new LinkedHashSet<>();
        if (params.getParams(FacetParams.FACET_FIELD) != null) {
            facetFields.addAll(Arrays.asList(params.getParams(FacetParams.FACET_FIELD)));
        }

        // Add the facet tree fields
        for (String ftField : ftFields) {
            // Parse the facet tree field, so we only add the field value,
            // rather than the whole string (ensure it's unique)
            facetFields.add(QueryParsing.getLocalParams(ftField, params).get(QueryParsing.V));
        }

        // Add the (possibly) new facet fields
        params.set(FacetParams.FACET_FIELD, facetFields.toArray(new String[facetFields.size()]));

        // Re-set the params in the request
        rb.req.setParams(params);
    }
}