Example usage for org.apache.solr.request SolrQueryRequest getCore

List of usage examples for org.apache.solr.request SolrQueryRequest getCore

Introduction

In this page you can find the example usage for org.apache.solr.request SolrQueryRequest getCore.

Prototype

SolrCore getCore();

Source Link

Document

The solr core (coordinator, etc) associated with this request

Usage

From source file:alba.components.FilteredShowFileRequestHandler.java

License:Apache License

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
        throws InterruptedException, KeeperException, IOException {

    CoreContainer coreContainer = req.getCore().getCoreDescriptor().getCoreContainer();
    if (coreContainer.isZooKeeperAware()) {
        showFromZooKeeper(req, rsp, coreContainer);
    } else {/*from   w w  w.j a  v a  2s . c  o m*/
        showFromFileSystem(req, rsp);
    }
}

From source file:alba.components.FilteredShowFileRequestHandler.java

License:Apache License

public static boolean isHiddenFile(SolrQueryRequest req, SolrQueryResponse rsp, String fnameIn,
        boolean reportError, Set<String> hiddenFiles) {
    String fname = fnameIn.toUpperCase(Locale.ROOT);
    if (hiddenFiles.contains(fname) || hiddenFiles.contains("*")) {
        if (reportError) {
            log.error("Cannot access " + fname);
            rsp.setException(/*  www. jav a2  s .  c o m*/
                    new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access: " + fnameIn));
        }
        return true;
    }

    // This is slightly off, a valid path is something like ./schema.xml. I don't think it's worth the effort though
    // to fix it to handle all possibilities though.
    if (fname.indexOf("..") >= 0 || fname.startsWith(".")) {
        if (reportError) {
            log.error("Invalid path: " + fname);
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Invalid path: " + fnameIn));
        }
        return true;
    }

    // Make sure that if the schema is managed, we don't allow editing. Don't really want to put
    // this in the init since we're not entirely sure when the managed schema will get initialized relative to this
    // handler.
    SolrCore core = req.getCore();
    IndexSchema schema = core.getLatestSchema();
    if (schema instanceof ManagedIndexSchema) {
        String managed = schema.getResourceName();

        if (fname.equalsIgnoreCase(managed)) {
            return true;
        }
    }
    return false;
}

From source file:alba.components.FilteredShowFileRequestHandler.java

License:Apache License

public static String getAdminFileFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp,
        SolrZkClient zkClient, Set<String> hiddenFiles) throws KeeperException, InterruptedException {
    String adminFile = null;// ww  w .j  a va2  s . c  om
    SolrCore core = req.getCore();

    final ZkSolrResourceLoader loader = (ZkSolrResourceLoader) core.getResourceLoader();
    String confPath = loader.getConfigSetZkPath();

    String fname = req.getParams().get("file", null);
    if (fname == null) {
        adminFile = confPath;
    } else {
        fname = fname.replace('\\', '/'); // normalize slashes
        if (isHiddenFile(req, rsp, fname, true, hiddenFiles)) {
            return null;
        }
        if (fname.startsWith("/")) { // Only files relative to conf are valid
            fname = fname.substring(1);
        }
        adminFile = confPath + "/" + fname;
    }

    // Make sure the file exists, is readable and is not a hidden file
    if (!zkClient.exists(adminFile, true)) {
        log.error("Can not find: " + adminFile);
        rsp.setException(new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can not find: " + adminFile));
        return null;
    }

    return adminFile;
}

From source file:alba.components.FilteredShowFileRequestHandler.java

License:Apache License

public static File getAdminFileFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp,
        Set<String> hiddenFiles) {
    File adminFile = null;//from w w w  .j  a  va2s . co m
    final SolrResourceLoader loader = req.getCore().getResourceLoader();
    File configdir = new File(loader.getConfigDir());
    if (!configdir.exists()) {
        // TODO: maybe we should just open it this way to start with?
        try {
            configdir = new File(loader.getClassLoader().getResource(loader.getConfigDir()).toURI());
        } catch (URISyntaxException e) {
            log.error("Can not access configuration directory!");
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN,
                    "Can not access configuration directory!", e));
            return null;
        }
    }
    String fname = req.getParams().get("file", null);
    if (fname == null) {
        adminFile = configdir;
    } else {
        fname = fname.replace('\\', '/'); // normalize slashes
        if (hiddenFiles.contains(fname.toUpperCase(Locale.ROOT))) {
            log.error("Can not access: " + fname);
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access: " + fname));
            return null;
        }
        if (fname.indexOf("..") >= 0) {
            log.error("Invalid path: " + fname);
            rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Invalid path: " + fname));
            return null;
        }
        adminFile = new File(configdir, fname);
    }
    return adminFile;
}

From source file:com.github.healthonnet.search.SynonymExpandingExtendedDismaxQParserPlugin.java

License:Apache License

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    if (luceneMatchVersion == null) {
        this.luceneMatchVersion = req.getCore().getSolrConfig().luceneMatchVersion;
        synonymAnalyzers = new HashMap<>();
        parseConfig(synonymAnalyzers, "synonymAnalyzers");
        mainAnalyzers = new HashMap<>();
        parseConfig(mainAnalyzers, "queryAnalyzers");

    }//  w  w w .  jav a2 s  .c o m
    return new SynonymExpandingExtendedDismaxQParser(qstr, localParams, params, req, synonymAnalyzers,
            mainAnalyzers);
}

From source file:com.github.le11.nls.solr.UIMAAsyncUpdateRequestProcessorFactory.java

License:Apache License

@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req, SolrQueryResponse rsp,
        UpdateRequestProcessor next) {//from  w w w .  j a  v  a2 s .  co m
    return new UIMAAsyncUpdateRequestProcessor(next, req.getCore(),
            new SolrUIMAConfigurationReader(args).readSolrUIMAConfiguration());
}

From source file:com.search.MySearchHandler.java

License:Apache License

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    // int sleep = req.getParams().getInt("sleep",0);
    // if (sleep > 0) {log.error("SLEEPING for " + sleep);
    // Thread.sleep(sleep);}

    /*** Pre-processing of the Query by REGEX starts here -------------- ***/
    SolrParams originalParams = req.getOriginalParams();
    SolrParams psuedoParams = req.getParams(); // These psuedoParams keep
    // changing//from  w  w  w  . j  av  a2s .com
    if (originalParams.get(CommonParams.Q) != null) {
        String finalQuery;
        String originalQuery = originalParams.get(CommonParams.Q);
        rsp.add("Original query", originalQuery);
        SchemaField keyField = null;
        keyField = req.getCore().getLatestSchema().getUniqueKeyField();
        if (keyField != null) {
            fieldSet.add(keyField.getName());
        }
        /***
         * START CODE TO PARSE QUERY
         * 
         * Arafath's code to prepare query starts here The query should be
         * in the following format ->
         * 
         * 
         * 
         * Example : Original Query:
         * "Which musical object did russ conway play" Temporary Query :
         * "relations:instrument AND entity:enty" // Generate the relation
         * Final Query : "name:"russ conway" AND occupation:musician"
         */
        ParsedQuestion parsedq = new ParsedQuestion();
        parsedq = parseQues(originalQuery);
        if (parsedq != null) {
            System.out.println(parsedq);
            Map<Integer, String> relationstr = getRelation(parsedq.getRelationKeyWord(), parsedq.getWhtype(),
                    req);

            /**
             * END CODE TO PARSE QUERY
             */

            /*** Final Phase starts here ***/
            finalQuery = "title:\"" + parsedq.getSearchName() + "\"";
            NamedList finalparamsList = req.getParams().toNamedList();
            finalparamsList.setVal(finalparamsList.indexOf(CommonParams.Q, 0), finalQuery);
            psuedoParams = SolrParams.toSolrParams(finalparamsList);
            if (psuedoParams.get(CommonParams.SORT) == null) {
                finalparamsList.add(CommonParams.SORT, "score desc");
            } else {
                finalparamsList.setVal(finalparamsList.indexOf(CommonParams.SORT, 0), "score desc");
            }
            int documentsRetrieved = 0;
            if (relationstr != null) {
                rsp.add("total relations retrieved", relationstr.size());
                rsp.add("relations", relationstr);
                NamedList finaldocresults = new NamedList();
                NamedList forwarddocresults = new NamedList();
                Set<String> checkDocuments = new HashSet<String>();

                for (int i = 0; i < relationstr.size() && (documentsRetrieved < 10); i++) {
                    NamedList relationdocresults = new NamedList();
                    String desiredField = relationstr.get(i);
                    Set<String> tempFieldSet = new HashSet<String>();
                    int docsRetrievedforThisRelation = 0;
                    tempFieldSet.add(desiredField);
                    psuedoParams = SolrParams.toSolrParams(finalparamsList);
                    if (psuedoParams.get(CommonParams.FL) == null) {
                        finalparamsList.add(CommonParams.FL, desiredField);
                    } else {
                        finalparamsList.setVal(finalparamsList.indexOf(CommonParams.FL, 0), desiredField);
                    }
                    SolrQueryRequest finalreq = new LocalSolrQueryRequest(req.getCore(), finalparamsList);
                    rsp.add("Final Query", finalreq.getParams().get(CommonParams.Q));

                    SolrQueryResponse finalrsp = new SolrQueryResponse();

                    ResponseBuilder finalrb = new ResponseBuilder(finalreq, finalrsp, components);
                    for (SearchComponent c : components) {
                        c.prepare(finalrb);
                        c.process(finalrb);
                    }

                    DocList finaldocs = finalrb.getResults().docList;
                    if (finaldocs == null || finaldocs.size() == 0) {
                        log.debug("No results");
                        // support for reverse query
                    } else {
                        DocIterator finaliterator = finaldocs.iterator();
                        Document finaldoc;
                        for (int j = 0; j < finaldocs.size(); j++) {
                            try {
                                if (finaliterator.hasNext()) {
                                    int finaldocid = finaliterator.nextDoc();
                                    finaldoc = finalrb.req.getSearcher().doc(finaldocid, tempFieldSet);
                                    if (!checkDocuments.contains(finaldoc.get("id"))) {
                                        if (finaldoc.get(desiredField) != null) {
                                            checkDocuments.add(finaldoc.get("id"));
                                            docsRetrievedforThisRelation++;
                                            documentsRetrieved++;
                                            relationdocresults.add(finaldoc.get("title"), finaldoc);
                                            if (documentsRetrieved >= 10) {
                                                break;
                                            }
                                        }
                                    }
                                }
                            } catch (IOException ex) {
                                java.util.logging.Logger.getLogger(MySearchHandler.class.getName())
                                        .log(Level.SEVERE, null, ex);
                            }
                        }
                        if (docsRetrievedforThisRelation > 0) {
                            rsp.add("docs retrieved for : " + desiredField, docsRetrievedforThisRelation);
                            forwarddocresults.add(desiredField, relationdocresults);
                        }
                    }
                    finalreq.close();
                    if (documentsRetrieved > 0) {
                        rsp.add("type", "forward");
                        rsp.add("final results", forwarddocresults);
                    }
                }
                if (documentsRetrieved == 0) {
                    NamedList reversedocresults = new NamedList();
                    relationstr = getRelationReverse(parsedq.getRelationKeyWord(), req);
                    System.out.println(relationstr);
                    StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_46);
                    String reversequery = "";
                    for (int i = 0; i < relationstr.size(); i++) {
                        QueryParser relationsparser = new QueryParser(Version.LUCENE_46, relationstr.get(i),
                                analyzer);
                        try {
                            reversequery += relationsparser.parse(parsedq.getSearchName()).toString() + " ";
                        } catch (ParseException e) {

                            e.printStackTrace();
                        }
                    }
                    QueryParser relationsparser = new QueryParser(Version.LUCENE_46, "infotype", analyzer);
                    reversequery += relationsparser.parse(parsedq.getWhtype().firstKey().toLowerCase());

                    NamedList reverseList = req.getParams().toNamedList();
                    psuedoParams = SolrParams.toSolrParams(reverseList);
                    reverseList.setVal(reverseList.indexOf(CommonParams.Q, 0), reversequery);
                    SolrQueryRequest reversereq = new LocalSolrQueryRequest(req.getCore(), reverseList);
                    SolrQueryResponse reversersp = new SolrQueryResponse();
                    ResponseBuilder reverserb = new ResponseBuilder(reversereq, reversersp, components);
                    for (SearchComponent c : components) {
                        try {
                            c.prepare(reverserb);
                            c.process(reverserb);
                        } catch (IOException ex) {

                            java.util.logging.Logger.getLogger(MySearchHandler.class.getName())
                                    .log(Level.SEVERE, null, ex);
                        }
                    }
                    DocList reversedocs = reverserb.getResults().docList;
                    if (reversedocs == null || reversedocs.size() == 0) {
                        log.debug("No results");
                        // GET SECOND entry from WHTYPE .. search with that ..
                    } else {
                        //   NamedList docresults = new NamedList();
                        DocIterator reverseiterator = reversedocs.iterator();
                        Document reversedoc;
                        int docScore = 0;
                        for (int m = 0; m < reversedocs.size(); m++) {
                            try {
                                int reversedocid = reverseiterator.nextDoc();
                                reversedoc = reverserb.req.getSearcher().doc(reversedocid, fieldSet);
                                if (reversedoc.get("title") != null) {
                                    documentsRetrieved++;
                                    reversedocresults.add(reversedoc.get("title"), reversedoc);
                                    if (documentsRetrieved >= 10) {
                                        break;
                                    }
                                }
                            } catch (IOException ex) {
                                java.util.logging.Logger.getLogger(MySearchHandler.class.getName())
                                        .log(Level.SEVERE, null, ex);
                            }
                        }
                    }
                    if (documentsRetrieved == 0) {
                        rsp.add("message", "No Results found. Try another query!");
                    } else {
                        rsp.add("type", "reverse");
                        rsp.add("final results", reversedocresults);
                    }
                    reversereq.close();
                }
            } else {
                if (documentsRetrieved == 0) {
                    rsp.add("message", "No Results found. Please rephrase the query!");
                }
            }
        } else {
            rsp.add("message", "This is not a valid query!");
        }
    } else {
        rsp.add("message", "User should provide at least one word as a query!");
    }
}

From source file:com.search.MySearchHandler.java

License:Apache License

private Map<Integer, String> getRelationReverse(String value, SolrQueryRequest req) {
    /*** Galla's modified code starts here ---- >
     * //ww  w  . ja v  a2s .  c o  m
     */
    StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_46);
    QueryParser relationsparser = new QueryParser(Version.LUCENE_46, "relations", analyzer);
    QueryParser entityparser = new QueryParser(Version.LUCENE_46, "entity", analyzer);
    QueryParser fieldidparser = new QueryParser(Version.LUCENE_46, "fieldid", analyzer);

    Map<Integer, String> desiredFieldList = null;
    int desiredFieldsCount = 0;
    String desiredRelation = null;

    Set<String> checkRelation = null;
    if (desiredFieldsCount < 5) {
        desiredFieldList = new HashMap<Integer, String>();
        checkRelation = new HashSet<String>();
        NamedList tempparamsList = req.getParams().toNamedList();
        SolrParams psuedoParams = SolrParams.toSolrParams(tempparamsList);
        if (psuedoParams.get(CommonParams.SORT) == null) {
            tempparamsList.add(CommonParams.SORT, "score desc");
        } else {
            tempparamsList.setVal(tempparamsList.indexOf(CommonParams.SORT, 0), "score desc");
        }
        SolrQueryRequest firstreq = null;
        SolrQueryResponse firstrsp = null;
        ResponseBuilder firstrb = null;
        DocList docs = null;

        String relString = "";
        String fieldString = "";
        try {
            relString = relationsparser.parse(value).toString();

            fieldString = fieldidparser.parse(value).toString();
        } catch (ParseException e) {

            e.printStackTrace();
        }
        //      (+relations:"children" and +entity:"num") or (relations:"children" and fieldid:"children") or (fieldid:"children" and entity:"num")
        String tempQuery = "(" + relString + ")" + " OR (" + fieldString + ")";

        System.out.println(tempQuery);
        tempparamsList.setVal(tempparamsList.indexOf(CommonParams.Q, 0), tempQuery);

        firstreq = new LocalSolrQueryRequest(req.getCore(), tempparamsList);
        firstrsp = new SolrQueryResponse();
        firstrb = new ResponseBuilder(firstreq, firstrsp, components);

        for (SearchComponent c : components) {
            try {
                c.prepare(firstrb);
                c.process(firstrb);
            } catch (IOException ex) {

                java.util.logging.Logger.getLogger(MySearchHandler.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        docs = firstrb.getResults().docList;

        if (docs == null || docs.size() == 0) {
            log.debug("No results");
            // GET SECOND entry from WHTYPE .. search with that ..

        } else {
            //   NamedList docresults = new NamedList();
            DocIterator iterator = docs.iterator();
            Document doc;
            int docScore = 0;
            for (int i = 0; i < docs.size(); i++) {
                try {
                    int docid = iterator.nextDoc();
                    doc = firstrb.req.getSearcher().doc(docid, fieldSet);
                    desiredRelation = doc.get("fieldid");
                    if (!checkRelation.contains(desiredRelation)) {
                        checkRelation.add(desiredRelation);
                        desiredFieldList.put(desiredFieldsCount++, desiredRelation);
                        System.out.println("vgalla's relation : " + desiredRelation);
                        if (desiredFieldsCount >= 5) {
                            return desiredFieldList;
                        }
                    }
                } catch (IOException ex) {
                    java.util.logging.Logger.getLogger(MySearchHandler.class.getName()).log(Level.SEVERE, null,
                            ex);
                }
            }
        }
        firstreq.close();

        /*** Galla's code ends here ----- >
         * 
         */
    }

    return desiredFieldList;
}

From source file:com.search.MySearchHandler.java

License:Apache License

private static Map<Integer, String> getRelation(String value, TreeMap<String, Double> whtype,
        SolrQueryRequest req) {

    /***/*from  ww w  . j av  a2s. c  o  m*/
     * Galla's modified code starts here ---- >
     * 
     */
    Map<Integer, String> desiredFieldList = null;
    if (whtype != null) {
        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_46);
        QueryParser relationsparser = new QueryParser(Version.LUCENE_46, "relations", analyzer);
        QueryParser entityparser = new QueryParser(Version.LUCENE_46, "entity", analyzer);
        QueryParser fieldidparser = new QueryParser(Version.LUCENE_46, "fieldid", analyzer);

        int desiredFieldsCount = 0;
        String desiredRelation = null;
        Set<String> whtypeSet = whtype.keySet();
        Set<String> checkRelation = null;
        if (!whtypeSet.isEmpty() && (desiredFieldsCount < 5)) {
            desiredFieldList = new HashMap<Integer, String>();
            checkRelation = new HashSet<String>();
            NamedList tempparamsList = req.getParams().toNamedList();
            SolrParams psuedoParams = SolrParams.toSolrParams(tempparamsList);
            if (psuedoParams.get(CommonParams.SORT) == null) {
                tempparamsList.add(CommonParams.SORT, "score desc");
            } else {
                tempparamsList.setVal(tempparamsList.indexOf(CommonParams.SORT, 0), "score desc");
            }
            SolrQueryRequest firstreq = null;
            SolrQueryResponse firstrsp = null;
            ResponseBuilder firstrb = null;
            DocList docs = null;
            for (String tempStr : whtypeSet) {
                String tempType = tempStr.toLowerCase().trim();
                String relString = "";
                String entyString = "";
                String fieldString = "";
                try {
                    relString = relationsparser.parse(value).toString();
                    entyString = entityparser.parse(tempType).toString();
                    fieldString = fieldidparser.parse(value).toString();
                } catch (ParseException e) {

                    e.printStackTrace();
                }
                // (+relations:"children" and +entity:"num") or
                // (relations:"children" and fieldid:"children") or
                // (fieldid:"children" and entity:"num")
                String tempQuery = "(" + relString + " AND " + entyString + ")" + " OR " + "(" + relString
                        + " AND " + fieldString + ")" + " OR " + "(" + fieldString + " AND " + entyString + ")";

                System.out.println(tempQuery);
                tempparamsList.setVal(tempparamsList.indexOf(CommonParams.Q, 0), tempQuery);

                firstreq = new LocalSolrQueryRequest(req.getCore(), tempparamsList);
                firstrsp = new SolrQueryResponse();
                firstrb = new ResponseBuilder(firstreq, firstrsp, components);

                for (SearchComponent c : components) {
                    try {
                        c.prepare(firstrb);
                        c.process(firstrb);
                    } catch (IOException ex) {

                        java.util.logging.Logger.getLogger(MySearchHandler.class.getName()).log(Level.SEVERE,
                                null, ex);
                    }
                }

                docs = firstrb.getResults().docList;

                if (docs == null || docs.size() == 0) {
                    log.debug("No results");
                    // GET SECOND entry from WHTYPE .. search with that ..

                } else {
                    // NamedList docresults = new NamedList();
                    DocIterator iterator = docs.iterator();
                    Document doc;
                    int docScore = 0;
                    for (int i = 0; i < docs.size(); i++) {
                        try {
                            int docid = iterator.nextDoc();
                            doc = firstrb.req.getSearcher().doc(docid, fieldSet);
                            desiredRelation = doc.get("fieldid");
                            if (!checkRelation.contains(desiredRelation)) {
                                checkRelation.add(desiredRelation);
                                desiredFieldList.put(desiredFieldsCount++, desiredRelation);
                                System.out.println("vgalla's relation : " + desiredRelation);
                                if (desiredFieldsCount >= 5) {
                                    return desiredFieldList;
                                }
                            }
                        } catch (IOException ex) {
                            java.util.logging.Logger.getLogger(MySearchHandler.class.getName())
                                    .log(Level.SEVERE, null, ex);
                        }
                    }
                }
                firstreq.close();

                /***
                 * Galla's code ends here ----- >
                 * 
                 */

                String exrelstring = "";

                String[] strarray = value.split(" ");

                for (int i = 0; i < strarray.length; i++) {
                    if (exrelmap.containsKey(strarray[i].toLowerCase().trim())) {
                        exrelstring += exrelmap.get(strarray[i].toLowerCase().trim());
                    }
                }

                if (!exrelstring.equals("")) {
                    String[] temp = exrelstring.split("~~");
                    for (int i = 0; i < temp.length; i++) {
                        if (!temp[i].trim().equals("")) {

                            String mapdetect = mappingmap.get(temp[i].trim());

                            if (mapdetect.toLowerCase().trim().equals(tempType)) {
                                desiredRelation = temp[i].trim();
                                if (!checkRelation.contains(desiredRelation)) {
                                    checkRelation.add(desiredRelation);
                                    desiredFieldList.put(desiredFieldsCount++, desiredRelation);
                                    System.out.println("arafath's relation : " + desiredRelation);
                                    if (desiredFieldsCount >= 5) {
                                        return desiredFieldList;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return desiredFieldList;
}

From source file:com.search.MySearchHandlerTest.java

License:Apache License

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    // int sleep = req.getParams().getInt("sleep",0);
    // if (sleep > 0) {log.error("SLEEPING for " + sleep);  Thread.sleep(sleep);}

    /*** Pre-processing of the Query by REGEX starts here --------------***/
    SolrParams originalParams = req.getOriginalParams();
    SolrParams psuedoParams = req.getParams(); // These psuedoParams keep changing
    if (originalParams.get(CommonParams.Q) != null) {
        String finalQuery;//from   w  ww  .ja v a 2s  .  c  o  m

        String originalQuery = originalParams.get(CommonParams.Q);

        rsp.add("Original query", originalQuery);

        /*** Arafath's code to prepare query starts here
         * The query should be in the following format ->
         * Example : 
         *       Original Query: "Which musical object did russ conway play"
         *      Temporary Query : "relations:instrument AND entity:enty" // Generate the relation
         *       Final Query : "name:"russ conway" AND occupation:musician"
         */

        String tempQuery = "relations:instrumental AND entity:enty";
        rsp.add("Temporary query", tempQuery);
        String desiredField = null;
        Set<String> fieldSet = null;
        SchemaField keyField = null;

        NamedList tempparamsList = req.getParams().toNamedList();
        tempparamsList.setVal(tempparamsList.indexOf(CommonParams.Q, 0), tempQuery);
        psuedoParams = SolrParams.toSolrParams(tempparamsList);
        //      if (psuedoParams.get(CommonParams.SORT) == null) {
        //         tempparamsList.add(CommonParams.SORT, "score desc");
        //      } else {
        //         tempparamsList.setVal(tempparamsList.indexOf(CommonParams.SORT, 0), "score desc");
        //      }

        SolrQueryRequest firstreq = new LocalSolrQueryRequest(req.getCore(), tempparamsList);
        SolrQueryResponse firstrsp = new SolrQueryResponse();
        firstrsp.setAllValues(rsp.getValues());
        ResponseBuilder firstrb = new ResponseBuilder(firstreq, firstrsp, components);

        for (SearchComponent c : components) {
            c.prepare(firstrb);
            c.process(firstrb);
        }
        rsp.add("response", firstrb.getResults().docList);
        /***
                 DocList docs = firstrb.getResults().docList;
                 if (docs == null || docs.size() == 0) {
                    log.debug("No results");
                 } else {
                    fieldSet = new HashSet <String> ();
                    keyField = firstrb.req.getCore().getLatestSchema().getUniqueKeyField();
                    if (keyField != null) {
                       fieldSet.add(keyField.getName());
                    }
                    fieldSet.add("fieldid");
                    fieldSet.add("relations");
                    fieldSet.add("entity");
                    fieldSet.add("count");
                    NamedList docresults = new NamedList();
                    DocIterator iterator = docs.iterator();
                    Document doc;
                    int docScore = 0;
                    rsp.add("doc retrieved ", docs.size());
                    for (int i=0; i<docs.size(); i++) {
                       try {
          int docid = iterator.nextDoc();
          doc = firstrb.req.getSearcher().doc(docid, fieldSet);
          if (Integer.parseInt(doc.get("count")) > docScore) {
             docScore = Integer.parseInt(doc.get("count"));
             desiredField = doc.get("fieldid");
          }
          docresults.add(String.valueOf(docid), doc);
                       } catch (IOException ex) {
          java.util.logging.Logger.getLogger(CustomQueryComponent.class.getName()).log(Level.SEVERE, null,ex);
                       }
                    }
                    fieldSet.clear();
                    rsp.add("Intermediate results", docresults);
                    if (desiredField != null) {
                       rsp.add("Required Field", desiredField);
                    }
                 } ***/

        firstreq.close();

        /*** Final Phase starts here ***/
        /***   finalQuery = "name:\"russ conway\" AND occupation:musician";
              NamedList finalparamsList = req.getParams().toNamedList();
              finalparamsList.setVal(finalparamsList.indexOf(CommonParams.Q, 0), finalQuery);
              psuedoParams = SolrParams.toSolrParams(finalparamsList);
              if (psuedoParams.get(CommonParams.SORT) == null) {
                 finalparamsList.add(CommonParams.SORT, "score desc");
              } else {
                 finalparamsList.setVal(finalparamsList.indexOf(CommonParams.SORT, 0), "score desc");
              }   
           //   if (desiredField != null) {
           //      if (psuedoParams.get(CommonParams.FL) != null) {
           //         finalparamsList.setVal(finalparamsList.indexOf(CommonParams.FL, 0), desiredField);
           //      } else {
           //         finalparamsList.add(CommonParams.FL, desiredField);
           //      }
           //   }
                
              SolrQueryRequest finalreq = new LocalSolrQueryRequest(req.getCore(), finalparamsList);
              rsp.add("Final Query", finalreq.getParams().get(CommonParams.Q));
              ResponseBuilder rb = new ResponseBuilder(finalreq,rsp,components);
              for (SearchComponent c : components) {
                 c.prepare(rb);
                 c.process(rb);
              } ***/
        /*** testing
                 DocList finaldocs = rb.getResults().docList;
                 if (finaldocs == null || finaldocs.size() == 0) {
                    log.debug("No results");
                 } else {
                    keyField = rb.req.getCore().getLatestSchema().getUniqueKeyField();
                    if (keyField != null) {
                       fieldSet.add(keyField.getName());
                    }
                    if (desiredField != null) {
                       fieldSet.add(desiredField);
                    }
                    fieldSet.add("name");
                    NamedList finaldocresults = new NamedList();
                    DocIterator finaliterator = finaldocs.iterator();
                    Document finaldoc;
                    rsp.add("finaldocs retrieved ", finaldocs.size());
                    for (int i=0; i<docs.size(); i++) {
                       try {
          if (finaliterator.hasNext()) {
             int finaldocid = finaliterator.nextDoc();
             finaldoc = rb.req.getSearcher().doc(finaldocid, fieldSet);
             finaldocresults.add(String.valueOf(finaldocid), finaldoc);
          }
                       } catch (IOException ex) {
          java.util.logging.Logger.getLogger(MySearchHandler.class.getName()).log(Level.SEVERE, null,ex);
                       }
                    }
                    rsp.add("final results", finaldocresults);
                 } ***/
        //   finalreq.close(); 
    } else {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
                "Need to give at least one word as query!");
    }
}