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 Michael Chan <da...@gmail.com> on 2006/05/05 16:13:57 UTC

SpanNearQuery .equals()/.hash()

Hi,

It seems to me SpanNearQuery.equals()/.hash() are not overriden
because I've tried testing two logically equivalent queries but
.equals() returns false. Could anyone provide an implementation?

Cheers,

Michael

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


Re: SpanNearQuery .equals()/.hash()

Posted by Chris Hostetter <ho...@fucit.org>.
: I'm not sure if it's worth fixing them all or not... implementing set

i'm -1 against making this change.  The results of searching on these
query objects may be the same -- but that doesn't mean the query objects
themselves should be considered equivilent.  attempting to define them as
equal would lead to a slippery slope of trying to determine that any two
queries (possibly implimented by different classes) are "equal" because
they produce the same results.

Assume that (hypothetically) a SpanNearQuery containing two
SpanTermQueries with inOrder=1 and slop=0 scores *exactly* the same as a
PhraseQuery with 0 slop containing the same two terms.  SHould these
queries be considered equal ?




-Hoss


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


Re: SpanNearQuery .equals()/.hash()

Posted by Yonik Seeley <ys...@gmail.com>.
Yes, most of Lucene's Query equals() and hashCode() methods consider
clause order important (including BooleanQuery).  It's like
List.equals() vs Set.equals()

I'm not sure if it's worth fixing them all or not... implementing set
equality with an underlying list can certainly be more expensive (some
kind of HashSet would be more efficient for that).

Users can also get this behavior by normalizing or sorting clauses.

-Yonik
http://incubator.apache.org/solr Solr, the open-source Lucene search server


On 5/6/06, Michael Chan <da...@gmail.com> wrote:
> Hi,
>
> I'm using the latest version. Try the following:
>
>                                 SpanQuery[] clauses1 = {new SpanTermQuery(new Term("contents",
> "test1")), new SpanTermQuery(new Term("contents", "test2"))};
>                                 SpanNearQuery nearQ1 = new SpanNearQuery(clauses1, 3, false);
>
>                                 SpanQuery[] clauses2 = {new SpanTermQuery(new Term("contents",
> "test2")), new SpanTermQuery(new Term("contents", "test1"))};
>                                 SpanNearQuery nearQ2 = new SpanNearQuery(clauses2, 3, false);
>
>                                 System.out.println(nearQ1.equals(nearQ2));
>
> It works if clauses2 = {new SpanTermQuery(new Term("contents",
> "test1")), new SpanTermQuery(new Term("contents", "test2"))}. But,
> since order doesn't matter here, the two queries should be equal,
> right?
>
> Cheers,
>
> Michael
>
>
> On 5/6/06, Erik Hatcher <er...@ehatchersolutions.com> wrote:
> > What version of Lucene are you using?   It should work fine with
> > 1.9.  If not, could you supply a test case demonstrating this issue?
> >
> > Thanks,
> >         Erik
> >
> >
> >
> > On May 5, 2006, at 10:13 AM, Michael Chan wrote:
> >
> > > Hi,
> > >
> > > It seems to me SpanNearQuery.equals()/.hash() are not overriden
> > > because I've tried testing two logically equivalent queries but
> > > .equals() returns false. Could anyone provide an implementation?
> > >
> > > Cheers,
> > >
> > > Michael
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> >
>
> ---------------------------------------------------------------------
> 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


Re: SpanNearQuery .equals()/.hash()

Posted by Michael Chan <da...@gmail.com>.
Hi,

I'm using the latest version. Try the following:

				SpanQuery[] clauses1 = {new SpanTermQuery(new Term("contents",
"test1")), new SpanTermQuery(new Term("contents", "test2"))};
				SpanNearQuery nearQ1 = new SpanNearQuery(clauses1, 3, false);

				SpanQuery[] clauses2 = {new SpanTermQuery(new Term("contents",
"test2")), new SpanTermQuery(new Term("contents", "test1"))};
				SpanNearQuery nearQ2 = new SpanNearQuery(clauses2, 3, false);

				System.out.println(nearQ1.equals(nearQ2));

It works if clauses2 = {new SpanTermQuery(new Term("contents",
"test1")), new SpanTermQuery(new Term("contents", "test2"))}. But,
since order doesn't matter here, the two queries should be equal,
right?

Cheers,

Michael


On 5/6/06, Erik Hatcher <er...@ehatchersolutions.com> wrote:
> What version of Lucene are you using?   It should work fine with
> 1.9.  If not, could you supply a test case demonstrating this issue?
>
> Thanks,
>         Erik
>
>
>
> On May 5, 2006, at 10:13 AM, Michael Chan wrote:
>
> > Hi,
> >
> > It seems to me SpanNearQuery.equals()/.hash() are not overriden
> > because I've tried testing two logically equivalent queries but
> > .equals() returns false. Could anyone provide an implementation?
> >
> > Cheers,
> >
> > Michael
> >
> > ---------------------------------------------------------------------
> > 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
>
>

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


Re: SpanNearQuery .equals()/.hash()

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
What version of Lucene are you using?   It should work fine with  
1.9.  If not, could you supply a test case demonstrating this issue?

Thanks,
	Erik



On May 5, 2006, at 10:13 AM, Michael Chan wrote:

> Hi,
>
> It seems to me SpanNearQuery.equals()/.hash() are not overriden
> because I've tried testing two logically equivalent queries but
> .equals() returns false. Could anyone provide an implementation?
>
> Cheers,
>
> Michael
>
> ---------------------------------------------------------------------
> 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