lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: Supported way to get segment from IndexWriter?
Date Wed, 13 Jan 2010 10:59:07 GMT
Indeed, getReader is an expensive way to get the segment count (it
flushes the current RAM buffer to disk as a new segment).

Since SegmentInfos is now public, you could use SegmentInfos.read to
read the current segments_N file, and then call its .size() method?

But, this will only count as of the last commit... which is probably
not sufficient for SOLR-1559?

We could simply make getSegmentCount public / expert / not only for tests?

Mike

On Tue, Jan 12, 2010 at 8:42 PM, Chris Hostetter
<hossman_lucene@fucit.org> wrote:
>
> 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
>
>

---------------------------------------------------------------------
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