Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. /**
  2. * Performs a partial search on a query
  3. *
  4. * @param queries
  5. * @return ArrayList of QueryResult objects
  6. */
  7. private List<QueryResult> partialSearch(Collection<String> queries) {
  8. // Temporary Map to combine results
  9. HashMap<String, QueryResult> combinedResults = new HashMap<>();
  10. ArrayList<QueryResult> queryResults = new ArrayList<>();
  11.  
  12. // Get and combine the results
  13. for(String query : queries) {
  14. for(String key : index.tailMap(query).keySet()) {
  15. if(key.startsWith(query)) {
  16. for(String location : this.index.get(key).keySet()) {
  17. if(combinedResults.containsKey(location)) {
  18. combinedResults.get(location)
  19. .updateMatchCount(key, location);
  20. }
  21. else {
  22. QueryResult result = new QueryResult(location);
  23. result.updateMatchCount(key, location);
  24. combinedResults.put(location, result);
  25. queryResults.add(result);
  26. }
  27. }
  28. }
  29. }
  30. }
  31.  
  32. Collections.sort(queryResults);
  33. return queryResults;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement