diff --git a/browse-indexing/Leech.java b/browse-indexing/Leech.java index 75764d4..bea0826 100644 --- a/browse-indexing/Leech.java +++ b/browse-indexing/Leech.java @@ -4,6 +4,8 @@ import java.io.*; import java.util.*; +import org.apache.lucene.util.BytesRef; + import org.vufind.util.BrowseEntry; import org.vufind.util.Normalizer; import org.vufind.util.NormalizerFactory; @@ -73,36 +75,42 @@ private boolean termExists(String t) // public BrowseEntry next() throws Exception { - if (tenum == null) { - if (leafReaders.isEmpty()) { - // Nothing left to do - return null; - } + for (;;) { + if (tenum == null) { + // Load the next reader in our list and position the term enum. + + if (leafReaders.isEmpty()) { + // Nothing left to do + return null; + } + + // Select our next LeafReader to work from + LeafReader ir = leafReaders.remove(0).reader(); + Terms terms = ir.terms(this.field); - // Select our next LeafReader to work from - LeafReader ir = leafReaders.remove(0).reader(); - Terms terms = ir.terms(this.field); + if (terms == null) { + // Try the next reader + continue; + } - if (terms == null) { - // Try the next reader - return next(); + tenum = terms.iterator(); } - tenum = terms.iterator(); - } + BytesRef nextTerm = tenum.next(); + + if (nextTerm == null) { + // Exhausted this reader. Try the next one. + tenum = null; + continue; + } - if (tenum.next() != null) { - String termText = tenum.term().utf8ToString(); + String termText = nextTerm.utf8ToString(); if (termExists(termText)) { - return new BrowseEntry(buildSortKey(termText), termText, termText) ; - } else { - return this.next(); + return new BrowseEntry(buildSortKey(termText), termText, termText); } - } else { - // Exhausted this reader - tenum = null; - return next(); + + // Try the next term } } }