Example usage for org.apache.solr.common.params SolrParams getParams

List of usage examples for org.apache.solr.common.params SolrParams getParams

Introduction

In this page you can find the example usage for org.apache.solr.common.params SolrParams getParams.

Prototype

public abstract String[] getParams(String param);

Source Link

Document

returns an array of the String values of a param, or null if no mapping for the param exists.

Usage

From source file:alba.components.FilteredShowFileRequestHandler.java

License:Apache License

public static Set<String> initHidden(SolrParams invariants) {

    Set<String> hiddenRet = new HashSet<>();
    // Build a list of hidden files
    if (invariants != null) {
        String[] hidden = invariants.getParams(HIDDEN);
        if (hidden != null) {
            for (String s : hidden) {
                hiddenRet.add(s.toUpperCase(Locale.ROOT));
            }//  ww  w  .  ja  v  a2s .  c  o  m
        }
    }
    return hiddenRet;
}

From source file:at.newmedialab.lmf.util.solr.SuggestionRequestHandler.java

License:Apache License

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {

    SolrParams params = req.getParams();

    if (params.getBool(SuggestionRequestParams.SUGGESTION, SUGGESTION)) {

        String q = params.get(CommonParams.Q);
        if (q == null) {
            rsp.add("error", error(400, "SuggestionRequest needs to have a 'q' parameter"));
            return;
        }// w ww .  j a v a2  s  . c o  m

        String[] fields = params.getParams(SuggestionRequestParams.SUGGESTION_FIELD) != null
                ? params.getParams(SuggestionRequestParams.SUGGESTION_FIELD)
                : FIELDS;
        if (fields == null) {
            rsp.add("error",
                    error(400, "SuggestionRequest needs to have at least one 'suggestion.field' parameter"));
            return;
        }

        String df = params.get(SuggestionRequestParams.SUGGESTION_DF, DF);
        if (df == null) {
            rsp.add("error", error(400, "SuggestionRequest needs to have a 'df' parameter"));
            return;
        }

        int limit = params.getInt(SuggestionRequestParams.SUGGESTION_LIMIT, LIMIT);
        if (limit < 1) {
            rsp.add("error", error(400, "SuggestionRequest needs to have a 'suggestion.limit' greater than 0"));
            return;
        }

        String[] fqs = params.getParams(CommonParams.FQ) != null ? params.getParams(CommonParams.FQ) : FQS;

        Boolean multivalue = params.getBool(SuggestionRequestParams.SUGGESTION_MULTIVALUE, MULTIVALUE);

        //TODO replace
        if (multivalue) {
            rsp.add("error", error(500, "Multivalue suggestions are not yet supported!"));
            return;
        }

        suggestionService.run(rsp, q, df, fields, fqs, limit, multivalue);

    } else {
        super.handleRequestBody(req, rsp);
    }
}

From source file:com.adr.bigdata.search.product.cm.CmBackendQuery.java

public CmBackendQuery(SolrQueryRequest req) {
    SolrParams param = req.getParams();
    this.keyword = param.get(Params.KEYWORD);
    this.start = param.get(Params.START, "0");
    this.rows = param.get(Params.ROWS, "10");
    this.sort = param.get(Params.SORT);
    this.dateFromTo = param.get(Params.DATE_FROM_TO);
    this.categoryIds = param.getParams(Params.CATEGORY_ID);
    this.warehouseIds = param.getParams(Params.WAREHOUSE_ID);
    this.warehouseProductItemMappingId = param.getParams(Params.WAREHOUSE_PRODUCT_ITEM_MAPPING_ID);
    this.merchantIds = param.getParams(Params.MERCHANT_ID);
    this.brandIds = param.getParams(Params.BRAND_ID);
    this.productItemIds = param.getParams(Params.PRODUCT_ITEM_ID);
    this.visible = param.get(Params.VISIBLE);
    this.productItemStatuses = param.getParams(Params.PRODUCT_ITEM_STATUS);
    this.merchantProductItemStatuses = param.getParams(Params.MERCHANT_PRODUCT_ITEM_STATUS);
    this.productItemTypes = param.getParams(Params.PRODUCT_ITEM_TYPE);
    this.inStock = param.get(Params.IN_STOCK);
    this.approved = param.get(Params.APPROVED);
    this.safetyStock = param.get(Params.SAFETY_STOCK);
    this.isoriginal = param.get(Params.IS_ORIGINAL);
}

From source file:com.cominvent.solr.RequestSanitizerComponent.java

License:Apache License

@Override
public void prepare(ResponseBuilder rb) throws IOException {
    SolrParams params = rb.req.getParams();
    if (!params.getBool(COMPONENT_NAME, true))
        return;/*w  w w .  ja  v a2  s.co m*/
    Map<String, Map<String, String>> mappings = parseMappings(Arrays.asList(params.getParams(SANITIZE_PARAM)));
    log.info("Initialized RequestSanitizerComponent with mappings " + mappings);

    Map<String, String> modified = getModifications(params, mappings);
    if (modified.size() > 0) {
        log.info("Request parameters that were modified by RequestSanitizerComponent: " + modified);
        rb.req.setParams(new DefaultSolrParams(new MapSolrParams(modified), params));
    }
}

From source file:com.doculibre.constellio.servlets.ConstellioServletUtils.java

License:Open Source License

private static void addParams(NamedList<Object> responseHeader, SolrParams solrParams) {
    NamedList<Object> params = new NamedList<Object>();
    responseHeader.add("params", params);
    Iterator<String> enumParams = solrParams.getParameterNamesIterator();
    while (enumParams.hasNext()) {
        String param = enumParams.next();
        if (!param.equals(ServletsConstants.DIGEST_PARAM)) {
            String[] values = solrParams.getParams(param);
            params.add(param, values.length > 1 ? Arrays.asList(values) : values[0]);
        }//  w  w  w.j  a v a 2s  .co m
    }
}

From source file:com.doculibre.constellio.solr.handler.component.SearchLogComponent.java

License:Apache License

private static String getSimpleSearchStr(SolrParams params) {
    //      return params.toString();
    StringBuffer result = new StringBuffer();

    for (Iterator<String> it = params.getParameterNamesIterator(); it.hasNext();) {
        final String name = it.next();
        if (name.equals("shard.url"))
            continue;
        final String[] values = params.getParams(name);
        if (values.length == 1) {
            result.append(name + "=" + values[0] + "&");
        } else {//from   w w w  .  j  ava 2 s .  c  om
            // currently no reason not to use the same array
            result.append(name + "=" + values + "&");
        }
    }
    return result.toString();
}

From source file:com.searchbox.SuggesterComponent.java

License:Apache License

@Override
// actually do the request
public void process(ResponseBuilder rb) throws IOException {
    LOGGER.trace(("Hit process"));
    SolrParams params = rb.req.getParams();
    // see what fields we should be using for query
    String[] fields = params.getParams(SuggesterComponentParams.FIELDS + "." + SuggesterComponentParams.FIELD);

    if (fields == null) {

        fields = gfields;/*from  w  w  w  .  j a  v a2 s.  c o  m*/
    } else {
        for (String field : fields) {
            LOGGER.info("Using overrode fields:" + field);

        }
    }
    boolean build = params.getBool(SuggesterComponentParams.PRODUCT_NAME + "." + SuggesterComponentParams.BUILD,
            false);
    SolrIndexSearcher searcher = rb.req.getSearcher();
    // request has requested rebuilding of the dictionary
    if (build) {
        long lstartTime = System.currentTimeMillis();
        buildAndWrite(searcher, fields);
        totalBuildTime += System.currentTimeMillis() - lstartTime;
        lastbuildDate = new Date().toString();
    }

    if (suggester == null) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
                "Model for SBsuggester not created, create using sbsuggester.build=true");
    }
    String query = params.get(SuggesterComponentParams.PRODUCT_NAME + "." + SuggesterComponentParams.QUERY,
            params.get(CommonParams.Q));
    LOGGER.debug("Query:\t" + query);
    if (query == null) {
        LOGGER.warn("No query, returning..maybe was just used for  building index?");
        numErrors++;
        return;
    }

    long lstartTime = System.currentTimeMillis();
    numRequests++;

    // maximum number of phrases to look though
    int maxPhraseSearch = params.getInt(
            SuggesterComponentParams.PRODUCT_NAME + "." + SuggesterComponentParams.MAX_PHRASE_SEARCH,
            SuggesterComponentParams.MAX_PHRASE_SEARCH_DEFAULT);
    LOGGER.debug("maxPhraseSearch:\t" + maxPhraseSearch);
    SuggestionResultSet suggestions = suggester.getSuggestions(searcher, fields, query, maxPhraseSearch); // actually find suggestions

    Integer numneeded = params.getInt(
            SuggesterComponentParams.PRODUCT_NAME + "." + SuggesterComponentParams.COUNT,
            SuggesterComponentParams.COUNT_DEFAULT);

    NamedList response = new SimpleOrderedMap();

    int numout = 0;
    // stick results in an response object
    for (SuggestionResult suggestion : suggestions.suggestions) {
        LOGGER.debug(suggestion.suggestion + "\t" + suggestion.probability);
        response.add(suggestions.myval + suggestion.suggestion, suggestion.probability);
        numout++;
        if (numout > numneeded) {
            break;
        }
    }
    LOGGER.debug("\n\n");

    rb.rsp.add(SuggesterComponentParams.PRODUCT_NAME, response);
    totalRequestsTime += System.currentTimeMillis() - lstartTime;
}

From source file:com.searchbox.TaggerComponent.java

License:Apache License

@Override
public void process(ResponseBuilder rb) throws IOException {
    LOGGER.trace(("Hit process"));
    numRequests++;//from   ww w .  j a va  2s  .c om

    SolrParams params = rb.req.getParams();
    String[] fields = params
            .getParams(TaggerComponentParams.QUERY_FIELDS + "." + TaggerComponentParams.QUERY_FIELD);

    if (fields == null) {
        fields = gfields;
    } else {
        for (String field : fields) {
            LOGGER.info("Using overrode fields:" + field);
        }
    }
    boolean build = params.getBool(TaggerComponentParams.PRODUCT_NAME + "." + TaggerComponentParams.BUILD,
            false);
    SolrIndexSearcher searcher = rb.req.getSearcher();
    if (build) {
        long lstartTime = System.currentTimeMillis();
        buildAndWrite(searcher, fields);
        totalBuildTime += System.currentTimeMillis() - lstartTime;
        lastbuildDate = new Date().toString();
    }

    if (dfb == null) {
        LOGGER.error("Model for SBtagger not created, create using sbtagger.build=true");
        return;
    }
    String commonparamsQuery = params.get(CommonParams.Q);
    String query = params.get(TaggerComponentParams.PRODUCT_NAME + "." + TaggerComponentParams.QUERY);

    int lcount = params.getInt(TaggerComponentParams.PRODUCT_NAME + "." + TaggerComponentParams.COUNT,
            TaggerComponentParams.COUNT_DEFAULT);

    LOGGER.debug("Tagger Query:\t" + query);
    LOGGER.debug("Common params Query:\t" + commonparamsQuery);

    long lstartTime = System.currentTimeMillis();

    NamedList response = null;
    if (commonparamsQuery != null) {
        // do for documents
        response = doDocuments(rb, params, searcher, lcount);
    } else if (query != null) {
        // do for tag text
        response = doText(query, lcount);
    } else {
        LOGGER.warn("No query in q or sbtagger.q, returning..maybe was just used for  building index?");
        numErrors++;
        return;
    }

    rb.rsp.add(TaggerComponentParams.PRODUCT_NAME, response);
    totalRequestsTime += System.currentTimeMillis() - lstartTime;
}

From source file:com.searchbox.TaggerComponent.java

License:Apache License

private NamedList doDocuments(ResponseBuilder rb, SolrParams params, SolrIndexSearcher searcher, int lcount) {
    /*-----------------*/

    String[] localfields = params.getParams(TaggerComponentParams.QUERY_FIELDS);
    String[] fields = null;//from  w  ww .j  a  va 2s . com

    if (gfields != null) {
        fields = gfields;
    }
    if (localfields != null) {
        fields = localfields;
    }

    if (fields == null) {
        LOGGER.error("Fields aren't defined, not performing tagging.");
        return null;
    }

    DocList docs = rb.getResults().docList;
    if (docs == null || docs.size() == 0) {
        LOGGER.debug("No results");
    }
    LOGGER.debug("Doing This many docs:\t" + docs.size());

    Set<String> fset = new HashSet<String>();

    SchemaField keyField = rb.req.getCore().getSchema().getUniqueKeyField();
    if (null != keyField) {
        fset.add(keyField.getName());
    }
    for (String field : fields) {
        fset.add(field);
    }

    NamedList response = new SimpleOrderedMap();

    DocIterator iterator = docs.iterator();
    for (int i = 0; i < docs.size(); i++) {
        try {
            int docId = iterator.nextDoc();

            Document doc = searcher.doc(docId, fset);
            StringBuilder sb = new StringBuilder();
            for (String field : fields) {
                IndexableField[] multifield = doc.getFields(field);
                for (IndexableField singlefield : multifield) {
                    sb.append(singlefield.stringValue() + ". ");
                }
            }

            String q = sb.toString();
            String id = doc.getField(keyField.getName()).stringValue();
            // do work here
            TaggerResultSet trs = dfb.tagText(q, lcount);
            NamedList docresponse = new SimpleOrderedMap();
            for (TaggerResult tr : trs.suggestions) {
                docresponse.add(tr.suggestion, tr.score);
            }
            response.add(id, docresponse);
        } catch (IOException ex) {
            java.util.logging.Logger.getLogger(TaggerComponent.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    // response.add(suggestion.suggestion, suggestion.probability);
    return response;
}

From source file:com.sindicetech.siren.solr.qparser.SirenQParser.java

License:Open Source License

/**
 * Process the nested queries and add them as a (MUST) clause of the {@link org.apache.lucene.search.BooleanQuery}
 * that will be executed.//from  w ww  .j  a v a  2 s . co  m
 */
private void processNestedQuery(final BooleanQuery main, final SolrParams solrParams) throws SyntaxError {
    if (solrParams.getParams("nested") != null) {
        for (final String nested : solrParams.getParams("nested")) {
            final QParser baseParser = this.subQuery(nested, null);
            main.add(baseParser.getQuery(), Occur.MUST);
        }
    }
}