public Keywords findKeywords(User user, Request request) throws ParseException, IOException { Path dumpFile = dumpSearchResults(user, request); Scanner scanner = new Scanner(dumpFile); TObjectIntHashMap<String> words = new TObjectIntHashMap<>(); while (scanner.hasNextLine()) { String line = scanner.nextLine(); for (String word : StringUtils.tokenize(line, /* Remove stop words */ true)) { if (request.query.contains(word)) continue; Integer cnt = words.get(word); if (cnt == null) { cnt = 1; } else { cnt++; } words.put(word, cnt); } } PriorityQueue<WordAndCount> pq = createPriorityQueue(); words.forEachEntry((a, b) -> pq.add(new WordAndCount(a, b))); scanner.close(); Keywords kw = new Keywords(); WordAndCount[] wc = new WordAndCount[Math.min(request.pageSize, pq.size())]; for (int i = 0; i < wc.length; i++) wc[i] = pq.poll(); kw.keywords = wc; return kw; }
public Graph getNetwork(User user, Request request) throws ParseException, IOException { IndexSearcher searcher = getSearcher(request, user); Query query = searchService.getQuery(request); TopDocs docs = searcher.search(query, request.scanSize); GraphBuilder builder = new GraphBuilder(); for (ScoreDoc sd : docs.scoreDocs) { Document doc = searcher.doc(sd.doc); String from = doc.get(MailSchemaField.from.name()); List<String> to = StringUtils.parseCSV(doc.get(MailSchemaField.to.name())); List<String> cc = StringUtils.parseCSV(doc.get(MailSchemaField.cc.name())); Node fromNode = Node.of(from); builder.addNode(fromNode); to.stream().forEach(n -> builder.addEdge(fromNode, Node.of(n), 1.0f)); cc.stream().forEach(n -> builder.addEdge(fromNode, Node.of(n), 0.5f)); } return builder.build(); }