SOLR-296 -- wrapping reader.terms() in try/catch

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@554915 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2007-07-10 11:57:36 +00:00
parent 1829a5d781
commit 757aa1f9a0
1 changed files with 44 additions and 33 deletions

View File

@ -71,7 +71,6 @@ import org.apache.solr.search.SolrQueryParser;
* For more documentation see: * For more documentation see:
* http://wiki.apache.org/solr/LukeRequestHandler * http://wiki.apache.org/solr/LukeRequestHandler
* *
* @author ryan
* @version $Id$ * @version $Id$
* @since solr 1.2 * @since solr 1.2
*/ */
@ -390,13 +389,19 @@ public class LukeRequestHandler extends RequestHandlerBase
indexInfo.add("maxDoc", reader.maxDoc()); indexInfo.add("maxDoc", reader.maxDoc());
if( countTerms ) { if( countTerms ) {
TermEnum te = reader.terms(); TermEnum te = null;
try{
te = reader.terms();
int numTerms = 0; int numTerms = 0;
while (te.next()) { while (te.next()) {
numTerms++; numTerms++;
} }
indexInfo.add("numTerms", numTerms ); indexInfo.add("numTerms", numTerms );
} }
finally{
if( te != null ) te.close();
}
}
indexInfo.add("version", reader.getVersion()); // TODO? Is this different then: IndexReader.getCurrentVersion( dir )? indexInfo.add("version", reader.getVersion()); // TODO? Is this different then: IndexReader.getCurrentVersion( dir )?
indexInfo.add("optimized", reader.isOptimized() ); indexInfo.add("optimized", reader.isOptimized() );
@ -538,8 +543,10 @@ public class LukeRequestHandler extends RequestHandlerBase
private static Map<String,TopTermQueue> getTopTerms( IndexReader reader, Set<String> fields, int numTerms, Set<String> junkWords ) throws Exception private static Map<String,TopTermQueue> getTopTerms( IndexReader reader, Set<String> fields, int numTerms, Set<String> junkWords ) throws Exception
{ {
Map<String,TopTermQueue> info = new HashMap<String, TopTermQueue>(); Map<String,TopTermQueue> info = new HashMap<String, TopTermQueue>();
TermEnum terms = reader.terms();
TermEnum terms = null;
try{
terms = reader.terms();
while (terms.next()) { while (terms.next()) {
String field = terms.term().field(); String field = terms.term().field();
String t = terms.term().text(); String t = terms.term().text();
@ -547,7 +554,7 @@ public class LukeRequestHandler extends RequestHandlerBase
// Compute distinct terms for every field // Compute distinct terms for every field
TopTermQueue tiq = info.get( field ); TopTermQueue tiq = info.get( field );
if( tiq == null ) { if( tiq == null ) {
tiq = new TopTermQueue( numTerms ); tiq = new TopTermQueue( numTerms+1 );
info.put( field, tiq ); info.put( field, tiq );
} }
tiq.distinctTerms++; tiq.distinctTerms++;
@ -565,12 +572,16 @@ public class LukeRequestHandler extends RequestHandlerBase
if( terms.docFreq() > tiq.minFreq ) { if( terms.docFreq() > tiq.minFreq ) {
tiq.put(new TopTermQueue.TermInfo(terms.term(), terms.docFreq())); tiq.put(new TopTermQueue.TermInfo(terms.term(), terms.docFreq()));
if (tiq.size() >= numTerms) { // if tiq full if (tiq.size() > numTerms) { // if tiq full
tiq.pop(); // remove lowest in tiq tiq.pop(); // remove lowest in tiq
tiq.minFreq = ((TopTermQueue.TermInfo)tiq.top()).docFreq; // reset minFreq tiq.minFreq = ((TopTermQueue.TermInfo)tiq.top()).docFreq; // reset minFreq
} }
} }
} }
}
finally {
if( terms != null ) terms.close();
}
return info; return info;
} }
} }