Example usage for org.apache.solr.response SolrQueryResponse addResponse

List of usage examples for org.apache.solr.response SolrQueryResponse addResponse

Introduction

In this page you can find the example usage for org.apache.solr.response SolrQueryResponse addResponse.

Prototype

public void addResponse(Object response) 

Source Link

Document

Set response

Usage

From source file:net.semanticmetadata.lire.solr.LireRequestHandler.java

License:Open Source License

/**
 * Returns a random set of documents from the index. Mainly for testing purposes.
 *
 * @param req//w  w w.jav a  2 s.  c om
 * @param rsp
 * @throws IOException
 */
private void handleRandomSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
    SolrIndexSearcher searcher = req.getSearcher();
    DirectoryReader indexReader = searcher.getIndexReader();
    double maxDoc = indexReader.maxDoc();
    int paramRows = req.getParams().getInt("rows", defaultNumberOfResults);
    if (paramRows > maxDoc)
        paramRows = (int) Math.floor(maxDoc);
    if (maxDoc < 1)
        rsp.add("Error", "No documents in index");
    else {
        LinkedList list = new LinkedList();
        while (list.size() < paramRows) {
            Document d = searcher.doc((int) Math.floor(Math.random() * maxDoc));
            list.add(d);
        }
        rsp.addResponse(list);
    }
}