diff --git a/solr/src/java/org/apache/solr/request/SimpleFacets.java b/solr/src/java/org/apache/solr/request/SimpleFacets.java index 7d2a0012e35..853a9fa3bfa 100644 --- a/solr/src/java/org/apache/solr/request/SimpleFacets.java +++ b/solr/src/java/org/apache/solr/request/SimpleFacets.java @@ -516,6 +516,7 @@ public class SimpleFacets { Terms terms = fields==null ? null : fields.terms(field); TermsEnum termsEnum = null; + BytesRef term = null; if (terms != null) { termsEnum = terms.iterator(); @@ -525,10 +526,12 @@ public class SimpleFacets { if (startTermBytes != null) { if (termsEnum.seek(startTermBytes, true) == TermsEnum.SeekStatus.END) { termsEnum = null; + } else { + term = termsEnum.term(); } } else { // position termsEnum on first term - termsEnum.next(); + term = termsEnum.next(); } } @@ -536,11 +539,8 @@ public class SimpleFacets { DocsEnum docsEnum = null; - if (termsEnum != null && docs.size() >= mincount) { - for(;;) { - BytesRef term = termsEnum.term(); - if (term == null) - break; + if (docs.size() >= mincount) { + while (term != null) { if (startTermBytes != null && !term.startsWith(startTermBytes)) break; @@ -597,7 +597,7 @@ public class SimpleFacets { } } - termsEnum.next(); + term = termsEnum.next(); } } diff --git a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java index 0c5a64ebebc..f8d835773cf 100644 --- a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -18,12 +18,11 @@ package org.apache.solr.search; import org.apache.lucene.document.*; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermDocs; +import org.apache.lucene.index.*; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.util.BytesRef; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; import org.apache.solr.core.SolrConfig; @@ -631,21 +630,29 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean { Term t = ((TermQuery)query).getTerm(); SolrIndexReader[] readers = reader.getLeafReaders(); int[] offsets = reader.getLeafOffsets(); - int[] arr = new int[256]; - int[] freq = new int[256]; + for (int i=0; i