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; }