From 7949e3e218722d7a3db77ce67b7534fe1aee3b35 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Mon, 3 May 2010 22:51:05 +0000 Subject: [PATCH] fix faceting's use of flex: term() is undefined after next() returns null git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@940661 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/request/SimpleFacets.java | 14 ++++----- .../apache/solr/search/SolrIndexSearcher.java | 31 ++++++++++++------- 2 files changed, 26 insertions(+), 19 deletions(-) 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