@Override public void finishStage(ResponseBuilder rb) { SolrParams params = rb.req.getParams(); if (!params.getBool(COMPONENT_NAME, false) || !params.getBool(ClusteringParams.USE_SEARCH_RESULTS, false)) { return; } if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) { String name = getClusteringEngineName(rb); SearchClusteringEngine engine = searchClusteringEngines.get(name); if (engine != null) { checkAvailable(name, engine); SolrDocumentList solrDocList = (SolrDocumentList) rb.rsp.getResponse(); // TODO: Currently, docIds is set to null in distributed environment. // This causes CarrotParams.PRODUCE_SUMMARY doesn't work. // To work CarrotParams.PRODUCE_SUMMARY under distributed mode, we can choose either one of: // (a) In each shard, ClusteringComponent produces summary and finishStage() // merges these summaries. // (b) Adding doHighlighting(SolrDocumentList, ...) method to SolrHighlighter and // making SolrHighlighter uses "external text" rather than stored values to produce snippets. Map<SolrDocument,Integer> docIds = null; Object clusters = engine.cluster(rb.getQuery(), solrDocList, docIds, rb.req); rb.rsp.add("clusters", clusters); } else { log.warn("No engine named: " + name); } } }
public PageTool(SolrQueryRequest request, SolrQueryResponse response) { String rows = request.getParams().get("rows"); if (rows != null) { results_per_page = Integer.parseInt(rows); } //TODO: Handle group by results Object docs = response.getResponse(); if (docs != null) { if (docs instanceof DocSlice) { results_found = ((DocSlice) docs).matches(); start = ((DocSlice) docs).offset(); } else if(docs instanceof ResultContext) { DocList dl = ((ResultContext) docs).getDocList(); results_found = dl.matches(); start = dl.offset(); } else if(docs instanceof SolrDocumentList) { SolrDocumentList doc_list = (SolrDocumentList) docs; results_found = doc_list.getNumFound(); start = doc_list.getStart(); } else { throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Unknown response type "+docs+". Expected one of DocSlice, ResultContext or SolrDocumentList"); } } page_count = (int) Math.ceil(results_found / (double) results_per_page); current_page_number = (int) Math.ceil(start / (double) results_per_page) + (page_count > 0 ? 1 : 0); }