diff --git a/modules/suggest/src/java/org/apache/lucene/search/suggest/Lookup.java b/modules/suggest/src/java/org/apache/lucene/search/suggest/Lookup.java index e200225b2c7..5783eea5332 100644 --- a/modules/suggest/src/java/org/apache/lucene/search/suggest/Lookup.java +++ b/modules/suggest/src/java/org/apache/lucene/search/suggest/Lookup.java @@ -17,7 +17,6 @@ package org.apache.lucene.search.suggest; * limitations under the License. */ -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -57,6 +56,9 @@ public abstract class Lookup { } } + /** + * A simple char-by-char comparator for {@link CharSequence} + */ public static final Comparator CHARSEQUENCE_COMPARATOR = new CharSequenceComparator(); private static class CharSequenceComparator implements Comparator { @@ -79,8 +81,11 @@ public abstract class Lookup { } + /** + * A {@link PriorityQueue} collecting a fixed size of high priority {@link LookupResult} + */ public static final class LookupPriorityQueue extends PriorityQueue { - + // TODO: should we move this out of the interface into a utility class? public LookupPriorityQueue(int size) { super(size); } @@ -90,6 +95,10 @@ public abstract class Lookup { return a.value < b.value; } + /** + * Returns the top N results in descending order. + * @return the top N results in descending order. + */ public LookupResult[] getResults() { int size = size(); LookupResult[] res = new LookupResult[size]; diff --git a/modules/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java b/modules/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java index 86a10cde713..dc656e4aeeb 100644 --- a/modules/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java +++ b/modules/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java @@ -19,9 +19,6 @@ package org.apache.lucene.search.suggest.tst; import java.io.DataInputStream; import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -104,6 +101,7 @@ public class TSTLookup extends Lookup { int maxCnt = Math.min(num, list.size()); if (onlyMorePopular) { LookupPriorityQueue queue = new LookupPriorityQueue(num); + for (TernaryTreeNode ttn : list) { queue.insertWithOverflow(new LookupResult(ttn.token, ((Number)ttn.val).longValue())); } @@ -198,4 +196,5 @@ public class TSTLookup extends Lookup { } return true; } + }