Grokbase Groups Lucene dev April 2005
FAQ
Erik, why was the last change to BooleanQuery made?
The comment was "Correct BooleanQuery.equals such that every clause is
compared".

It looks like Vector.equals() should have worked, and the new code is
probably slower as it creates two new arrays.

We actually need to do some caching with Query as part of the key, so
I'm very glad you have been taking care of the equals()/hashCode()
issues in the Query hierarchy!

-Yonik

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

Search Discussions

  • Erik Hatcher at Apr 12, 2005 at 10:32 am

    On Apr 11, 2005, at 5:57 PM, Yonik Seeley wrote:
    Erik, why was the last change to BooleanQuery made?
    The comment was "Correct BooleanQuery.equals such that every clause is
    compared".

    It looks like Vector.equals() should have worked, and the new code is
    probably slower as it creates two new arrays.
    Vector.equals() compares the Vector object instances and is only true
    if they are the same object - it does not compare the contents of the
    Vector for equality at that level. Try it out with some test cases.

    Where in the .equals that I added are two arrays being created?

    public boolean equals(Object o) {
    if (!(o instanceof BooleanQuery))
    return false;
    BooleanQuery other = (BooleanQuery)o;
    return (this.getBoost() == other.getBoost())
    && Arrays.equals(this.getClauses(), other.getClauses());
    }

    It's especially risky on this list to use the word "probably" when
    talking about speed. :) Is it really slower?

    I'm more than happy to adjust the .equals method to something better;
    do you have a specific improvement?

    Erik


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-dev-help@lucene.apache.org
  • Yonik Seeley at Apr 12, 2005 at 2:59 pm

    On Apr 11, 2005, at 5:57 PM, Yonik Seeley wrote:
    Erik, why was the last change to BooleanQuery made?
    The comment was "Correct BooleanQuery.equals such that every clause is
    compared".

    It looks like Vector.equals() should have worked, and the new code is
    probably slower as it creates two new arrays.
    Vector.equals() compares the Vector object instances and is only true
    if they are the same object - it does not compare the contents of the
    Vector for equality at that level. Try it out with some test cases.
    ???
    Did you try it out? (sorry, couldn't resist ;-)

    The javadoc for Vector.equals() says it does the right thing.
    Vector.equals() calls super.equals() which is AbstractList.equals()
    which also "does the right thing". As a sanity check, I did write a
    simple test and tested it on 1.4 and 1.5 (the only JVMs I currently
    have installed). It's included at the end.
    Where in the .equals that I added are two arrays being created?
    this.getClauses() and other.getClauses() both create an array.
    public boolean equals(Object o) {
    if (!(o instanceof BooleanQuery))
    return false;
    BooleanQuery other = (BooleanQuery)o;
    return (this.getBoost() == other.getBoost())
    && Arrays.equals(this.getClauses(), other.getClauses());
    }

    It's especially risky on this list to use the word "probably" when
    talking about speed. :) Is it really slower?
    Yeah, I know... esp with todays latest HotSpot JVMs. It was just an
    educated guess.
    I'm more than happy to adjust the .equals method to something better;
    do you have a specific improvement?
    Change it back to the original ;-)

    I really wasn't trying to nitpick or anything... I had noticed your
    comment about equals() and panicked a little since we really only want
    to use an official lucene release in production (and we need to hash
    on Query).

    -Yonik

    --------------------------- little test prog ---------------------------
    import java.util.Vector;
    public class vec {
    public static void main(String[] args) {
    Integer a = new Integer(5);
    Integer b = new Integer(5);
    Vector va = new Vector(); va.add(a);
    Vector vb = new Vector(); vb.add(b);
    System.out.println("should be false:" + (a==b) );
    System.out.println("should be true:" + a.equals(b) );
    System.out.println("should be true:" + va.equals(vb) );
    }
    }

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-dev-help@lucene.apache.org
  • Erik Hatcher at Apr 12, 2005 at 5:25 pm

    On Apr 12, 2005, at 10:59 AM, Yonik Seeley wrote:
    On Apr 11, 2005, at 5:57 PM, Yonik Seeley wrote:
    Erik, why was the last change to BooleanQuery made?
    The comment was "Correct BooleanQuery.equals such that every clause
    is
    compared".

    It looks like Vector.equals() should have worked, and the new code is
    probably slower as it creates two new arrays.
    Vector.equals() compares the Vector object instances and is only true
    if they are the same object - it does not compare the contents of the
    Vector for equality at that level. Try it out with some test cases.
    ???
    Did you try it out? (sorry, couldn't resist ;-)
    Fair enough! In fact I did try and I stand completely corrected. I
    have reverted the change to BooleanQuery.equals and added a test case.

    I was certain, up to this point, that I had a test case failing on
    another project due to BooleanQuery.equals and that I fixed it by
    making the change - but apparently I was delusional as all seems to be
    well as it originally was.

    Thanks for your persistence and education!

    Erik


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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categorieslucene
postedApr 11, '05 at 9:57p
activeApr 12, '05 at 5:25p
posts4
users2
websitelucene.apache.org

2 users in discussion

Yonik Seeley: 2 posts Erik Hatcher: 2 posts

People

Translate

site design / logo © 2021 Grokbase