Return-Path: Delivered-To: apmail-lucene-java-commits-archive@www.apache.org Received: (qmail 42655 invoked from network); 17 Aug 2009 14:27:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Aug 2009 14:27:36 -0000 Received: (qmail 37021 invoked by uid 500); 17 Aug 2009 14:27:43 -0000 Delivered-To: apmail-lucene-java-commits-archive@lucene.apache.org Received: (qmail 36954 invoked by uid 500); 17 Aug 2009 14:27:43 -0000 Mailing-List: contact java-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-commits@lucene.apache.org Received: (qmail 36945 invoked by uid 99); 17 Aug 2009 14:27:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Aug 2009 14:27:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Aug 2009 14:27:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8759E2388882; Mon, 17 Aug 2009 14:27:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r804994 - in /lucene/java/trunk/src: java/org/apache/lucene/search/ java/org/apache/lucene/search/payloads/ java/org/apache/lucene/search/spans/ test/org/apache/lucene/search/payloads/ Date: Mon, 17 Aug 2009 14:27:20 -0000 To: java-commits@lucene.apache.org From: markrmiller@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090817142720.8759E2388882@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: markrmiller Date: Mon Aug 17 14:27:19 2009 New Revision: 804994 URL: http://svn.apache.org/viewvc?rev=804994&view=rev Log: LUCENE-1790 hashCode/equals update Modified: lucene/java/trunk/src/java/org/apache/lucene/search/Query.java lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java Modified: lucene/java/trunk/src/java/org/apache/lucene/search/Query.java URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/Query.java?rev=804994&r1=804993&r2=804994&view=diff ============================================================================== --- lucene/java/trunk/src/java/org/apache/lucene/search/Query.java (original) +++ lucene/java/trunk/src/java/org/apache/lucene/search/Query.java Mon Aug 17 14:27:19 2009 @@ -213,4 +213,24 @@ throw new RuntimeException("Clone not supported: " + e.getMessage()); } } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Float.floatToIntBits(boost); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Query other = (Query) obj; + if (Float.floatToIntBits(boost) != Float.floatToIntBits(other.boost)) + return false; + return true; + } } Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java?rev=804994&r1=804993&r2=804994&view=diff ============================================================================== --- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java (original) +++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java Mon Aug 17 14:27:19 2009 @@ -1,6 +1,5 @@ package org.apache.lucene.search.payloads; -import org.apache.lucene.index.Term; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -35,4 +34,20 @@ return numPayloadsSeen > 0 ? (payloadScore / numPayloadsSeen) : 1; } + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.getClass().hashCode(); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return true; + } } Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java?rev=804994&r1=804993&r2=804994&view=diff ============================================================================== --- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java (original) +++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java Mon Aug 17 14:27:19 2009 @@ -170,11 +170,31 @@ } } - public boolean equals(Object o) { - if (!(o instanceof BoostingFunctionTermQuery)) + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((function == null) ? 0 : function.hashCode()); + result = prime * result + (includeSpanScore ? 1231 : 1237); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + BoostingFunctionTermQuery other = (BoostingFunctionTermQuery) obj; + if (function == null) { + if (other.function != null) + return false; + } else if (!function.equals(other.function)) return false; - BoostingFunctionTermQuery other = (BoostingFunctionTermQuery) o; - return (this.getBoost() == other.getBoost()) - && this.term.equals(other.term) && this.function.equals(other.function); + if (includeSpanScore != other.includeSpanScore) + return false; + return true; } + + } Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java?rev=804994&r1=804993&r2=804994&view=diff ============================================================================== --- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java (original) +++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java Mon Aug 17 14:27:19 2009 @@ -1,6 +1,5 @@ package org.apache.lucene.search.payloads; -import org.apache.lucene.index.Term; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -25,7 +24,7 @@ * Is thread safe and completely reusable. * **/ -public class MaxPayloadFunction extends PayloadFunction{ +public class MaxPayloadFunction extends PayloadFunction { public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen, float currentScore, float currentPayloadScore) { return Math.max(currentPayloadScore, currentScore); } @@ -33,4 +32,21 @@ public float docScore(int docId, String field, int numPayloadsSeen, float payloadScore) { return numPayloadsSeen > 0 ? payloadScore : 1; } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.getClass().hashCode(); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return true; + } } Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java?rev=804994&r1=804993&r2=804994&view=diff ============================================================================== --- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java (original) +++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java Mon Aug 17 14:27:19 2009 @@ -1,7 +1,21 @@ package org.apache.lucene.search.payloads; -import org.apache.lucene.index.Term; - +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /** * Calculates the miniumum payload seen @@ -16,5 +30,22 @@ public float docScore(int docId, String field, int numPayloadsSeen, float payloadScore) { return numPayloadsSeen > 0 ? payloadScore : 1; } + + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.getClass().hashCode(); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + return true; + } } Modified: lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java?rev=804994&r1=804993&r2=804994&view=diff ============================================================================== --- lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java (original) +++ lucene/java/trunk/src/java/org/apache/lucene/search/spans/SpanTermQuery.java Mon Aug 17 14:27:19 2009 @@ -61,18 +61,27 @@ return buffer.toString(); } - /** Returns true iff o is equal to this. */ - public boolean equals(Object o) { - if (!(o instanceof SpanTermQuery)) - return false; - SpanTermQuery other = (SpanTermQuery)o; - return (this.getBoost() == other.getBoost()) - && this.term.equals(other.term); + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((term == null) ? 0 : term.hashCode()); + return result; } - /** Returns a hash code value for this object.*/ - public int hashCode() { - return Float.floatToIntBits(getBoost()) ^ term.hashCode() ^ 0xD23FE494; + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + SpanTermQuery other = (SpanTermQuery) obj; + if (term == null) { + if (other.term != null) + return false; + } else if (!term.equals(other.term)) + return false; + return true; } public Spans getSpans(final IndexReader reader) throws IOException { Modified: lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java?rev=804994&r1=804993&r2=804994&view=diff ============================================================================== --- lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java (original) +++ lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java Mon Aug 17 14:27:19 2009 @@ -19,12 +19,14 @@ import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.English; import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.QueryUtils; import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.CheckHits; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.DefaultSimilarity; +import org.apache.lucene.search.spans.SpanTermQuery; import org.apache.lucene.search.spans.Spans; import org.apache.lucene.search.spans.TermSpans; import org.apache.lucene.analysis.Analyzer; @@ -151,6 +153,21 @@ }*/ } + + public void testQuery() { + BoostingFunctionTermQuery boostingFuncTermQuery = new BoostingFunctionTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"), + new MaxPayloadFunction()); + QueryUtils.check(boostingFuncTermQuery); + + SpanTermQuery spanTermQuery = new SpanTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy")); + + assertTrue(boostingFuncTermQuery.equals(spanTermQuery) == spanTermQuery.equals(boostingFuncTermQuery)); + + BoostingFunctionTermQuery boostingFuncTermQuery2 = new BoostingFunctionTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"), + new AveragePayloadFunction()); + + QueryUtils.checkUnequal(boostingFuncTermQuery, boostingFuncTermQuery2); + } public void testMultipleMatchesPerDoc() throws Exception { BoostingFunctionTermQuery query = new BoostingFunctionTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"),