FAQ
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

Search Discussions

  • Luke Shannon at Jan 7, 2005 at 8:22 pm
    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" <mcrump@leadscope.com>
    To: <lucene-user@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
  • Morus Walter at Jan 7, 2005 at 8:22 pm

    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
  • Luke Francl at Jan 7, 2005 at 8:23 pm

    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
  • Mike Snare at Jan 7, 2005 at 8:30 pm

    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
    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
  • Mike Snare at Jan 7, 2005 at 8:46 pm
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedJan 7, '05 at 7:24p
activeJan 7, '05 at 8:46p
posts6
users5
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase