mirror of https://github.com/apache/lucene.git
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:
parent
1829a5d781
commit
757aa1f9a0
|
@ -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,12 +389,18 @@ 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;
|
||||||
int numTerms = 0;
|
try{
|
||||||
while (te.next()) {
|
te = reader.terms();
|
||||||
numTerms++;
|
int numTerms = 0;
|
||||||
|
while (te.next()) {
|
||||||
|
numTerms++;
|
||||||
|
}
|
||||||
|
indexInfo.add("numTerms", numTerms );
|
||||||
|
}
|
||||||
|
finally{
|
||||||
|
if( te != null ) te.close();
|
||||||
}
|
}
|
||||||
indexInfo.add("numTerms", numTerms );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 )?
|
||||||
|
@ -538,39 +543,45 @@ 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();
|
|
||||||
|
|
||||||
while (terms.next()) {
|
TermEnum terms = null;
|
||||||
String field = terms.term().field();
|
try{
|
||||||
String t = terms.term().text();
|
terms = reader.terms();
|
||||||
|
while (terms.next()) {
|
||||||
// Compute distinct terms for every field
|
String field = terms.term().field();
|
||||||
TopTermQueue tiq = info.get( field );
|
String t = terms.term().text();
|
||||||
if( tiq == null ) {
|
|
||||||
tiq = new TopTermQueue( numTerms );
|
// Compute distinct terms for every field
|
||||||
info.put( field, tiq );
|
TopTermQueue tiq = info.get( field );
|
||||||
}
|
if( tiq == null ) {
|
||||||
tiq.distinctTerms++;
|
tiq = new TopTermQueue( numTerms+1 );
|
||||||
tiq.histogram.add( terms.docFreq() ); // add the term to the histogram
|
info.put( field, tiq );
|
||||||
|
}
|
||||||
// Only save the distinct terms for fields we worry about
|
tiq.distinctTerms++;
|
||||||
if (fields != null && fields.size() > 0) {
|
tiq.histogram.add( terms.docFreq() ); // add the term to the histogram
|
||||||
if( !fields.contains( field ) ) {
|
|
||||||
|
// Only save the distinct terms for fields we worry about
|
||||||
|
if (fields != null && fields.size() > 0) {
|
||||||
|
if( !fields.contains( field ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( junkWords != null && junkWords.contains( t ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if( junkWords != null && junkWords.contains( t ) ) {
|
if( terms.docFreq() > tiq.minFreq ) {
|
||||||
continue;
|
tiq.put(new TopTermQueue.TermInfo(terms.term(), terms.docFreq()));
|
||||||
}
|
if (tiq.size() > numTerms) { // if tiq full
|
||||||
|
tiq.pop(); // remove lowest in tiq
|
||||||
if( terms.docFreq() > tiq.minFreq ) {
|
tiq.minFreq = ((TopTermQueue.TermInfo)tiq.top()).docFreq; // reset minFreq
|
||||||
tiq.put(new TopTermQueue.TermInfo(terms.term(), terms.docFreq()));
|
}
|
||||||
if (tiq.size() >= numTerms) { // if tiq full
|
|
||||||
tiq.pop(); // remove lowest in tiq
|
|
||||||
tiq.minFreq = ((TopTermQueue.TermInfo)tiq.top()).docFreq; // reset minFreq
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
if( terms != null ) terms.close();
|
||||||
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue