You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by "Crump, Michael" <mc...@leadscope.com> on 2005/01/07 20:24:19 UTC

Check to see if index is optimized

Hello,

 

Lucene is great!  I just have a question.

 

Is there a simple way to check and see if an index is already optimized?
What happens if optimize is called on an already optimized index - does
the call basically do a noop?  Or is it still and expensive call?

 

 

Regards,

 

Michael


Re: Check to see if index is optimized

Posted by Mike Snare <mi...@gmail.com>.
Based on the method sent earlier, it looks like Lucene first checks to
see if optimization is even necessary.

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


Re: Check to see if index is optimized

Posted by Mike Snare <mi...@gmail.com>.
> If an index has no deletions, it does not need to be optimized. You can
> find out if it has deletions with IndexReader.hasDeletions.

Is that true?  An index that has just been created (with no deletions)
can still have multiple segments that could be optimized.  I'm not
sure your statement is correct.

-Mike

On Fri, 07 Jan 2005 14:22:23 -0600, Luke Francl
<lu...@stellent.com> wrote:
> On Fri, 2005-01-07 at 13:24, Crump, Michael wrote:
> 
> > Is there a simple way to check and see if an index is already optimized?
> > What happens if optimize is called on an already optimized index - does
> > the call basically do a noop?  Or is it still and expensive call?
> 
> If an index has no deletions, it does not need to be optimized. You can
> find out if it has deletions with IndexReader.hasDeletions.
> 
> I am not sure what the cost of optimization is if the index doesn't need
> it. Perhaps someone else on this list knows.
> 
> Regards,
> Luke Francl
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 
>

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


Re: Check to see if index is optimized

Posted by Luke Francl <lu...@stellent.com>.
On Fri, 2005-01-07 at 13:24, Crump, Michael wrote:

> Is there a simple way to check and see if an index is already optimized?
> What happens if optimize is called on an already optimized index - does
> the call basically do a noop?  Or is it still and expensive call?

If an index has no deletions, it does not need to be optimized. You can
find out if it has deletions with IndexReader.hasDeletions.

I am not sure what the cost of optimization is if the index doesn't need
it. Perhaps someone else on this list knows.

Regards,
Luke Francl


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


Re: Check to see if index is optimized

Posted by Morus Walter <mo...@gmx.de>.
Crump, Michael writes:

> 
> Is there a simple way to check and see if an index is already optimized?
> What happens if optimize is called on an already optimized index - does
> the call basically do a noop?  Or is it still and expensive call?
> 
Why don't you just try that? E.g. using luke. Or three lines of code...

You will find, that calling optimize for an optimized index does
not change the index. (optimized means just one segement and no
deleted documents)

So I guess the answer for your first question can be found in the sources
of optimize:

  public synchronized void optimize() throws IOException {
    flushRamSegments();
    while (segmentInfos.size() > 1 ||
           (segmentInfos.size() == 1 &&
            (SegmentReader.hasDeletions(segmentInfos.info(0)) ||
             segmentInfos.info(0).dir != directory ||
             (useCompoundFile &&
              (!SegmentReader.usesCompoundFile(segmentInfos.info(0)) ||
                SegmentReader.hasSeparateNorms(segmentInfos.info(0))))))) {
      int minSegment = segmentInfos.size() - mergeFactor;
      mergeSegments(minSegment < 0 ? 0 : minSegment);
    }
  }

segmentInfos is private in IndexWriter, so I suspect you cannot check
that without modifying lucene.

HTH
	Morus

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


Re: Check to see if index is optimized

Posted by Luke Shannon <ls...@futurebrand.com>.
This may not be a simple way, but you could just do a quick check on the
folder to see if there is more than one file containing the name segment.

Luke

----- Original Message ----- 
From: "Crump, Michael" <mc...@leadscope.com>
To: <lu...@jakarta.apache.org>
Sent: Friday, January 07, 2005 2:24 PM
Subject: Check to see if index is optimized


Hello,



Lucene is great!  I just have a question.



Is there a simple way to check and see if an index is already optimized?
What happens if optimize is called on an already optimized index - does
the call basically do a noop?  Or is it still and expensive call?





Regards,



Michael



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