tempAttributes.put(AttributeNames.CLUSTERS, getClusters());
public Object cluster(Query query, DocList docList, SolrQueryRequest sreq) { try { // Prepare attributes for Carrot2 clustering call Map<String, Object> attributes = new HashMap<String, Object>(); List<Document> documents = getDocuments(docList, query, sreq); attributes.put(AttributeNames.DOCUMENTS, documents); attributes.put(AttributeNames.QUERY, query.toString()); // Pass extra overriding attributes from the request, if any extractCarrotAttributes(sreq.getParams(), attributes); // Perform clustering and convert to named list return clustersToNamedList(controller.process(attributes, clusteringAlgorithmClass).getClusters(), sreq.getParams()); } catch (Exception e) { log.error("Carrot2 clustering failed", e); throw new RuntimeException(e); } }
@Override protected void afterFetch(SearchEngineResponse response, ProcessingResult processingResult) { if (readClusters) { final Set<String> ids = Sets.newHashSet(); List<Document> documents = processingResult.getDocuments(); if (documents == null) documents = Collections.emptyList(); List<Cluster> clusters = processingResult.getClusters(); if (documents != null && clusters != null) { for (Document doc : documents) { ids.add(doc.getStringId()); } Predicate<Document> docFilter = new Predicate<Document>() { @Override public boolean apply(Document input) { return input != null && ids.contains(input.getStringId()); } }; this.clusters = sanityCheck(clusters, docFilter); } } }
if (getClusters() != null) clusters = Lists.newArrayList(getClusters());
this.clusters = processingResult.getClusters();
@Override public Object cluster(Query query, SolrDocumentList solrDocList, Map<SolrDocument, Integer> docIds, SolrQueryRequest sreq) { try { // Prepare attributes for Carrot2 clustering call Map<String, Object> attributes = new HashMap<>(); List<Document> documents = getDocuments(solrDocList, docIds, query, sreq); attributes.put(AttributeNames.DOCUMENTS, documents); attributes.put(AttributeNames.QUERY, query.toString()); // Pass the fields on which clustering runs. attributes.put("solrFieldNames", getFieldsForClustering(sreq)); // Pass extra overriding attributes from the request, if any extractCarrotAttributes(sreq.getParams(), attributes); // Perform clustering and convert to an output structure of clusters. // // Carrot2 uses current thread's context class loader to get // certain classes (e.g. custom tokenizer/stemmer) at runtime. // To make sure classes from contrib JARs are available, // we swap the context class loader for the time of clustering. return withContextClassLoader(core.getResourceLoader().getClassLoader(), () -> clustersToNamedList(controller.process(attributes, clusteringAlgorithmClass).getClusters(), sreq.getParams())); } catch (Exception e) { log.error("Carrot2 clustering failed", e); throw new SolrException(ErrorCode.SERVER_ERROR, "Carrot2 clustering failed", e); } }
{response.toXContent(builder, request);} if (processingResult != null && processingResult.getClusters() != null) { final Collection<Cluster> clusters = processingResult.getClusters(); final Map<String, Object> attributes = processingResult.getAttributes();