mirror of https://github.com/apache/lucene.git
LUCENE-1790 hashCode/equals update
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@804994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
20505fd0d5
commit
465fac206f
|
@ -213,4 +213,24 @@ public abstract class Query implements java.io.Serializable, Cloneable {
|
||||||
throw new RuntimeException("Clone not supported: " + e.getMessage());
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.apache.lucene.search.payloads;
|
package org.apache.lucene.search.payloads;
|
||||||
|
|
||||||
import org.apache.lucene.index.Term;
|
|
||||||
/**
|
/**
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
@ -35,4 +34,20 @@ public class AveragePayloadFunction extends PayloadFunction{
|
||||||
return numPayloadsSeen > 0 ? (payloadScore / numPayloadsSeen) : 1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,11 +170,31 @@ public class BoostingFunctionTermQuery extends SpanTermQuery implements Payload
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public int hashCode() {
|
||||||
if (!(o instanceof BoostingFunctionTermQuery))
|
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;
|
return false;
|
||||||
BoostingFunctionTermQuery other = (BoostingFunctionTermQuery) o;
|
if (getClass() != obj.getClass())
|
||||||
return (this.getBoost() == other.getBoost())
|
return false;
|
||||||
&& this.term.equals(other.term) && this.function.equals(other.function);
|
BoostingFunctionTermQuery other = (BoostingFunctionTermQuery) obj;
|
||||||
|
if (function == null) {
|
||||||
|
if (other.function != null)
|
||||||
|
return false;
|
||||||
|
} else if (!function.equals(other.function))
|
||||||
|
return false;
|
||||||
|
if (includeSpanScore != other.includeSpanScore)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.apache.lucene.search.payloads;
|
package org.apache.lucene.search.payloads;
|
||||||
|
|
||||||
import org.apache.lucene.index.Term;
|
|
||||||
/**
|
/**
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
@ -33,4 +32,21 @@ public class MaxPayloadFunction extends PayloadFunction{
|
||||||
public float docScore(int docId, String field, int numPayloadsSeen, float payloadScore) {
|
public float docScore(int docId, String field, int numPayloadsSeen, float payloadScore) {
|
||||||
return numPayloadsSeen > 0 ? payloadScore : 1;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,21 @@
|
||||||
package org.apache.lucene.search.payloads;
|
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
|
* Calculates the miniumum payload seen
|
||||||
|
@ -17,4 +31,21 @@ public class MinPayloadFunction extends PayloadFunction {
|
||||||
return numPayloadsSeen > 0 ? payloadScore : 1;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,18 +61,27 @@ public class SpanTermQuery extends SpanQuery {
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true iff <code>o</code> is equal to this. */
|
public int hashCode() {
|
||||||
public boolean equals(Object o) {
|
final int prime = 31;
|
||||||
if (!(o instanceof SpanTermQuery))
|
int result = super.hashCode();
|
||||||
return false;
|
result = prime * result + ((term == null) ? 0 : term.hashCode());
|
||||||
SpanTermQuery other = (SpanTermQuery)o;
|
return result;
|
||||||
return (this.getBoost() == other.getBoost())
|
|
||||||
&& this.term.equals(other.term);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a hash code value for this object.*/
|
public boolean equals(Object obj) {
|
||||||
public int hashCode() {
|
if (this == obj)
|
||||||
return Float.floatToIntBits(getBoost()) ^ term.hashCode() ^ 0xD23FE494;
|
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 {
|
public Spans getSpans(final IndexReader reader) throws IOException {
|
||||||
|
|
|
@ -19,12 +19,14 @@ package org.apache.lucene.search.payloads;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.lucene.util.English;
|
import org.apache.lucene.util.English;
|
||||||
import org.apache.lucene.search.IndexSearcher;
|
import org.apache.lucene.search.IndexSearcher;
|
||||||
|
import org.apache.lucene.search.QueryUtils;
|
||||||
import org.apache.lucene.search.TopDocs;
|
import org.apache.lucene.search.TopDocs;
|
||||||
import org.apache.lucene.search.ScoreDoc;
|
import org.apache.lucene.search.ScoreDoc;
|
||||||
import org.apache.lucene.search.CheckHits;
|
import org.apache.lucene.search.CheckHits;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
import org.apache.lucene.search.DefaultSimilarity;
|
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.Spans;
|
||||||
import org.apache.lucene.search.spans.TermSpans;
|
import org.apache.lucene.search.spans.TermSpans;
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
@ -152,6 +154,21 @@ public class BoostingFunctionTermQueryTest extends LuceneTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
public void testMultipleMatchesPerDoc() throws Exception {
|
||||||
BoostingFunctionTermQuery query = new BoostingFunctionTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"),
|
BoostingFunctionTermQuery query = new BoostingFunctionTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"),
|
||||||
new MaxPayloadFunction());
|
new MaxPayloadFunction());
|
||||||
|
|
Loading…
Reference in New Issue