@SuppressWarnings("unchecked") @Override public List<String> getClusterByCarrot2(String query) { // TODO Auto-generated method stub List<String> strs = new ArrayList<String>(); final Controller controller = ControllerFactory.createCachingPooling(IDocumentSource.class); final List<org.carrot2.core.Document> documents = Lists.newArrayList(); try { q = getParser().parse(QueryParserUtil.escape(query)); docs = getIndexSearcher().search(q, Integer.MAX_VALUE); hits = docs.scoreDocs; for (int i = 0; i < hits.length; i++) { Document doc = getIndexSearcher().doc(hits[i].doc); documents.add( new org.carrot2.core.Document( doc.get(CONTENTS_FIELD), doc.get(TITLE_FIELD), doc.get(USER_FIELD))); } final ProcessingResult byTopicClusters = controller.process(documents, query, LingoClusteringAlgorithm.class); final List<Cluster> clustersByTopic = byTopicClusters.getClusters(); final ProcessingResult byDomainClusters = controller.process(documents, query, ByUrlClusteringAlgorithm.class); final List<Cluster> clustersByDomain = byDomainClusters.getClusters(); for (Cluster c : clustersByDomain) { strs.add(c.getLabel()); } for (Cluster c : clustersByTopic) { strs.add(c.getLabel()); } } catch (Exception ex) { } return strs; }
@UsesExternalServices @Test public void testRequestIndependence() { @SuppressWarnings("unchecked") final Controller controller = ControllerFactory.createCachingPooling(org.carrot2.core.IDocumentSource.class); closeAfterTest(controller); final Map<String, Object> attrs = Maps.newHashMap(); CommonAttributesDescriptor.attributeBuilder(attrs).results(50).query("data mining"); controller.process( attrs, org.carrot2.webapp.source.WebDocumentSource.class, LingoClusteringAlgorithm.class); attrs.clear(); CommonAttributesDescriptor.attributeBuilder(attrs) .results(50) .query(WebDocumentSource.QUERY_FAILURE); try { controller.process( attrs, org.carrot2.webapp.source.WebDocumentSource.class, LingoClusteringAlgorithm.class); fail(); } catch (ProcessingException e) { assertThat(e.getCause().getMessage()).contains("Synthetic failure"); } }