mirror of https://github.com/apache/lucene.git
Contrib queries package Query implementations do not override equals()
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@763857 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a1b3fd7240
commit
413cabef1f
|
@ -83,6 +83,38 @@ public class BoostingQuery extends Query {
|
|||
return result;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Float.floatToIntBits(boost);
|
||||
result = prime * result + ((context == null) ? 0 : context.hashCode());
|
||||
result = prime * result + ((match == null) ? 0 : match.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BoostingQuery other = (BoostingQuery) obj;
|
||||
if (Float.floatToIntBits(boost) != Float.floatToIntBits(other.boost))
|
||||
return false;
|
||||
if (context == null) {
|
||||
if (other.context != null)
|
||||
return false;
|
||||
} else if (!context.equals(other.context))
|
||||
return false;
|
||||
if (match == null) {
|
||||
if (other.match != null)
|
||||
return false;
|
||||
} else if (!match.equals(other.match))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString(String field) {
|
||||
return match.toString(field) + "/" + context.toString(field);
|
||||
}
|
||||
|
|
|
@ -57,8 +57,45 @@ public class FuzzyLikeThisQuery extends Query
|
|||
ScoreTermQueue q;
|
||||
int MAX_VARIANTS_PER_TERM=50;
|
||||
boolean ignoreTF=false;
|
||||
private int maxNumTerms;
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((analyzer == null) ? 0 : analyzer.hashCode());
|
||||
result = prime * result
|
||||
+ ((fieldVals == null) ? 0 : fieldVals.hashCode());
|
||||
result = prime * result + (ignoreTF ? 1231 : 1237);
|
||||
result = prime * result + maxNumTerms;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
FuzzyLikeThisQuery other = (FuzzyLikeThisQuery) obj;
|
||||
if (analyzer == null) {
|
||||
if (other.analyzer != null)
|
||||
return false;
|
||||
} else if (!analyzer.equals(other.analyzer))
|
||||
return false;
|
||||
if (fieldVals == null) {
|
||||
if (other.fieldVals != null)
|
||||
return false;
|
||||
} else if (!fieldVals.equals(other.fieldVals))
|
||||
return false;
|
||||
if (ignoreTF != other.ignoreTF)
|
||||
return false;
|
||||
if (maxNumTerms != other.maxNumTerms)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param maxNumTerms The total number of terms clauses that will appear once rewritten as a BooleanQuery
|
||||
|
@ -68,6 +105,7 @@ public class FuzzyLikeThisQuery extends Query
|
|||
{
|
||||
q=new ScoreTermQueue(maxNumTerms);
|
||||
this.analyzer=analyzer;
|
||||
this.maxNumTerms = maxNumTerms;
|
||||
}
|
||||
|
||||
class FieldVals
|
||||
|
@ -83,6 +121,46 @@ public class FuzzyLikeThisQuery extends Query
|
|||
prefixLength = length;
|
||||
this.queryString = queryString;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((fieldName == null) ? 0 : fieldName.hashCode());
|
||||
result = prime * result + Float.floatToIntBits(minSimilarity);
|
||||
result = prime * result + prefixLength;
|
||||
result = prime * result
|
||||
+ ((queryString == null) ? 0 : queryString.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
FieldVals other = (FieldVals) obj;
|
||||
if (fieldName == null) {
|
||||
if (other.fieldName != null)
|
||||
return false;
|
||||
} else if (!fieldName.equals(other.fieldName))
|
||||
return false;
|
||||
if (Float.floatToIntBits(minSimilarity) != Float
|
||||
.floatToIntBits(other.minSimilarity))
|
||||
return false;
|
||||
if (prefixLength != other.prefixLength)
|
||||
return false;
|
||||
if (queryString == null) {
|
||||
if (other.queryString != null)
|
||||
return false;
|
||||
} else if (!queryString.equals(other.queryString))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.lucene.search;
|
||||
|
||||
import org.apache.lucene.index.Term;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BoostingQueryTest extends TestCase {
|
||||
public void testBoostingQueryEquals() {
|
||||
TermQuery q1 = new TermQuery(new Term("subject:", "java"));
|
||||
TermQuery q2 = new TermQuery(new Term("subject:", "java"));
|
||||
assertEquals("Two TermQueries with same attributes should be equal", q1, q2);
|
||||
BoostingQuery bq1 = new BoostingQuery(q1, q2, 0.1f);
|
||||
BoostingQuery bq2 = new BoostingQuery(q1, q2, 0.1f);
|
||||
assertEquals("BoostingQuery with same attributes is not equal", bq1, bq2);
|
||||
}
|
||||
}
|
|
@ -111,4 +111,14 @@ public class FuzzyLikeThisQueryTest extends TestCase
|
|||
Document doc=searcher.doc(sd[0].doc);
|
||||
assertEquals("Should match most similar when using 2 words", "2",doc.get("id"));
|
||||
}
|
||||
|
||||
public void testFuzzyLikeThisQueryEquals() {
|
||||
Analyzer analyzer = new WhitespaceAnalyzer();
|
||||
FuzzyLikeThisQuery fltq1 = new FuzzyLikeThisQuery(10, analyzer);
|
||||
fltq1.addTerms("javi", "subject", 0.5f, 2);
|
||||
FuzzyLikeThisQuery fltq2 = new FuzzyLikeThisQuery(10, analyzer);
|
||||
fltq2.addTerms("javi", "subject", 0.5f, 2);
|
||||
assertEquals("FuzzyLikeThisQuery with same attributes is not equal", fltq1,
|
||||
fltq2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue