private void handleRandomSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
SolrIndexSearcher searcher = req.getSearcher();
Query query = new MatchAllDocsQuery();
DocList docList = searcher.getDocList(query, getFilterQueries(req), Sort.RELEVANCE, 0, numberOfCandidateResults, 0);
int paramRows = Math.min(req.getParams().getInt("rows", defaultNumberOfResults), docList.size());
if (docList.size() < 1) {
rsp.add("Error", "No documents in index");
} else {
LinkedList list = new LinkedList();
while (list.size() < paramRows) {
DocList auxList = docList.subset((int) (Math.random() * docList.size()), 1);
Document doc = null;
for (DocIterator it = auxList.iterator(); it.hasNext(); ) {
doc = searcher.doc(it.nextDoc());
}
if (!list.contains(doc)) {
list.add(doc);
}
}
rsp.addResponse(list);
}
}