You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2021/07/16 00:31:45 UTC

[GitHub] [lucene] jtibshirani opened a new pull request #212: LUCENE-10026: Fix CombinedFieldQuery equals and hashCode

jtibshirani opened a new pull request #212:
URL: https://github.com/apache/lucene/pull/212


   The previous equals and hashCode methods only compared query terms. This meant
   that queries on different fields, or with different field weights, were
   considered the same.
   
   During boolean query rewrites, duplicate clauses are removed. So because
   equals/ hashCode was incorrect, rewrites could accidentally drop
   CombinedFieldQuery clauses.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [lucene] jtibshirani merged pull request #212: LUCENE-10026: Fix CombinedFieldQuery equals and hashCode

Posted by GitBox <gi...@apache.org>.
jtibshirani merged pull request #212:
URL: https://github.com/apache/lucene/pull/212


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [lucene] jpountz commented on a change in pull request #212: LUCENE-10026: Fix CombinedFieldQuery equals and hashCode

Posted by GitBox <gi...@apache.org>.
jpountz commented on a change in pull request #212:
URL: https://github.com/apache/lucene/pull/212#discussion_r671012619



##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java
##########
@@ -212,13 +226,18 @@ public String toString(String field) {
   }
 
   @Override
-  public int hashCode() {
-    return 31 * classHash() + Arrays.hashCode(terms);
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;

Review comment:
       use `Query#sameClassAs` ?

##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java
##########
@@ -212,13 +226,18 @@ public String toString(String field) {
   }
 
   @Override
-  public int hashCode() {
-    return 31 * classHash() + Arrays.hashCode(terms);
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+    CombinedFieldQuery that = (CombinedFieldQuery) o;
+    return Objects.equals(fieldAndWeights, that.fieldAndWeights) && Arrays.equals(terms, that.terms);
   }
 
   @Override
-  public boolean equals(Object other) {
-    return sameClassAs(other) && Arrays.equals(terms, ((CombinedFieldQuery) other).terms);
+  public int hashCode() {
+    int result = Objects.hash(fieldAndWeights);
+    result = 31 * result + Arrays.hashCode(terms);

Review comment:
       use `classHash()` in the hashcode?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [lucene] jtibshirani commented on a change in pull request #212: LUCENE-10026: Fix CombinedFieldQuery equals and hashCode

Posted by GitBox <gi...@apache.org>.
jtibshirani commented on a change in pull request #212:
URL: https://github.com/apache/lucene/pull/212#discussion_r671362459



##########
File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java
##########
@@ -212,13 +226,18 @@ public String toString(String field) {
   }
 
   @Override
-  public int hashCode() {
-    return 31 * classHash() + Arrays.hashCode(terms);
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;

Review comment:
       Thanks, I had just auto-generated these.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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