lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Supported way to get segment from IndexWriter?
Date Wed, 13 Jan 2010 01:42:05 GMT

A conversation with someone earlier today got me thinking about cranking 
out a patch for SOLR-1559 (in which the goal is to allow for rules do 
dermine the iput to optimize(maxNumSegments) instead of requiring a fixed 
integer value as input)  when i realized that i wasn't certain what 
"approved" methods there might be for deterrmining hte current number of 
segments from an IndexWriter.

I see IndexWriter.getSegmentCount() but it's package protected (with a 
comment that it exists for tests).  So my best guess using only public 
APIs would be something like...

  int numCurrentSegments = -1;
  IndexReader r = writer.getReader();
  try {
    IndexReader[]tmp = r.getSequentialSubReaders();
    numCurrentSegments = null==tmp ? 1 : tmp.length;
  } finally {
    r.close();
  }

Is there a better way?

(My main concern about this approach being that my intuition (which seems 
supported by the javadocs) is that getReader might be a little 
expensive/excesive just to count the segments)

-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message