Пример #1
0
 @Override
 public List<LookupResult> lookup(
     CharSequence key, Set<BytesRef> contexts, boolean onlyMorePopular, int num) {
   if (contexts != null) {
     throw new IllegalArgumentException("this suggester doesn't support contexts");
   }
   List<LookupResult> res = new ArrayList<>();
   List<String> list;
   int count = onlyMorePopular ? num * 2 : num;
   if (usePrefix) {
     list = trie.matchPrefix(key, count);
   } else {
     list = trie.matchAlmost(key, count);
   }
   if (list == null || list.size() == 0) {
     return res;
   }
   int maxCnt = Math.min(num, list.size());
   if (onlyMorePopular) {
     LookupPriorityQueue queue = new LookupPriorityQueue(num);
     for (String s : list) {
       long freq = ((Number) trie.get(s)).longValue();
       queue.insertWithOverflow(new LookupResult(new CharsRef(s), freq));
     }
     for (LookupResult lr : queue.getResults()) {
       res.add(lr);
     }
   } else {
     for (int i = 0; i < maxCnt; i++) {
       String s = list.get(i);
       long freq = ((Number) trie.get(s)).longValue();
       res.add(new LookupResult(new CharsRef(s), freq));
     }
   }
   return res;
 }
Пример #2
0
 /** Returns the value for the specified key, or null if the key does not exist. */
 public Object get(CharSequence key) {
   return trie.get(key);
 }