Example usage for org.apache.solr.common.util NamedList removeAll

List of usage examples for org.apache.solr.common.util NamedList removeAll

Introduction

In this page you can find the example usage for org.apache.solr.common.util NamedList removeAll.

Prototype

public List<T> removeAll(String name) 

Source Link

Document

Removes and returns all values for the specified name.

Usage

From source file:org.apache.lucene.queryparser.classic.PreAnalyzedQueryParser.java

License:Apache License

/***
 * Main entry that parses the "q" parameter value from every query,
 * overwrites the parse method from the Solr Query Class.
 * /*  ww  w . j ava  2  s  .  com*/
 */
@Override
public Query parse() throws SyntaxError {

    // Get list of params from request
    NamedList<Object> requestParams = this.params.toNamedList();

    // Getting q param value from request
    String qryJO = requestParams.get("q").toString();

    String finalQry = "";

    if (requestParams.get("queryProcessing") == null) {

        // Get debug parameter from request
        Boolean debugQuery = Boolean.valueOf(params.get("debugQuery"));
        if (debugQuery == null) {
            debugQuery = false;
        }

        // Get lemma exp global param
        Boolean lemmaExp = Boolean.valueOf(params.get("lemma"));
        if (lemmaExp == null) {
            lemmaExp = false;
        }

        // Get synonym exp global param
        Boolean synExp = Boolean.valueOf(params.get("syn"));
        if (synExp == null) {
            synExp = false;
        }

        // Get accent removal global param
        Boolean accRem = Boolean.valueOf(params.get("accRem"));
        if (accRem == null) {
            accRem = false;
        }

        // Get language for the query terms, default to english
        String lang = params.get("language");
        if (lang == null) {
            lang = "en";
        }

        // Special param for lemmatizer testing
        Boolean showLemmas = params.getBool("showLemmas");

        // Store debug messages
        String debugMessage = "<![CDATA[";

        String[] transOut = new String[2];
        if (!qryJO.equals("*:*")) { // validates all docs wildcard query
            transOut = transformParamValue(qryJO, debugQuery, lang, synExp, lemmaExp, accRem);
            finalQry = transOut[0];
        } else { // all docs wildcard query scenario
            finalQry = "*:*";
        }
        // Print final transformed query
        if (debugQuery) {
            debugMessage += transOut[1];
            debugMessage += "After PreAnalyzed transformation->" + finalQry + "]]>";
            System.out.println(debugMessage);
        }

        // Get fq params from request
        List<Object> allFQs = requestParams.getAll("fq");
        requestParams.removeAll("fq");
        // Iterate over all fq params and apply transformations (tokenization, lemmatization, JSON format)
        for (Object fqValue : allFQs) {
            if (fqValue instanceof String[]) {
                for (String val : (String[]) fqValue) {
                    String newFQ = transformParamValue(val, false, lang, synExp, lemmaExp, accRem)[0];
                    requestParams.add("fq", newFQ);
                }
            } else {
                String newFQ = transformParamValue(fqValue.toString(), false, lang, synExp, lemmaExp,
                        accRem)[0];
                requestParams.add("fq", newFQ);
            }
        }
        if (debugQuery) {
            requestParams.add("queryParserDebugProcess", debugMessage);
        }
        requestParams.add("queryProcessing", "True");
        requestParams.remove("q");
        requestParams.add("q", finalQry);
        this.req.setParams(SolrParams.toSolrParams(requestParams));
    } else {
        finalQry = requestParams.get("q").toString();
    }

    // Redirect the transform query to Solr Query Class
    QueryParser qp = new QueryParser(schema.getDefaultLuceneMatchVersion(), params.get("df"), this);

    Query qry = qp.parse(finalQry);
    return qry;
}