Apache Solr open-source search software
LUCENE-7295: TermAutomatonQuery.hashCode calculates Automaton.toDot().hash.
Dawid Weiss6e8ca1a094ee
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 18b99c22dc0..35052cfdeda 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -136,6 +136,9 @@ DocumentationOther+* LUCENE-7295: TermAutomatonQuery.hashCode calculates Automaton.toDot().hash,+ equivalence relationship replaced with object identity. (Dawid Weiss)+* LUCENE-7277: Make Query.hashCode and Query.equals abstract. (Paul Elschot,Dawid Weiss)diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java b/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.javaindex d0298c403bc..b3a7ba2a4e4 100644--- a/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java+++ b/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java@@ -245,19 +245,18 @@ public class TermAutomatonQuery extends Query {}private boolean equalsTo(TermAutomatonQuery other) {- // NOTE: not quite correct, because if terms were added in different- // order in each query but the language is the same, we return false:return checkFinished(this) &&checkFinished(other) &&- termToID.equals(other.termToID) &&- Operations.sameLanguage(det, other.det);+ other == this;}@Overridepublic int hashCode() {checkFinished(this);- // TODO: LUCENE-7295: Automaton.toDot() is very costly!- return classHash() ^ termToID.hashCode() + det.toDot().hashCode();+ // LUCENE-7295: this used to be very awkward toDot() call; it is safer to assume+ // that no two instances are equivalent instead (until somebody finds a better way to check+ // on automaton equivalence quickly).+ return System.identityHashCode(this);}/** Returns the dot (graphviz) representation of this automaton.@@ -328,7 +327,6 @@ public class TermAutomatonQuery extends Query {}final class TermAutomatonWeight extends Weight {- private final IndexSearcher searcher;final Automaton automaton;private final Map<Integer,TermContext> termStates;private final Similarity.SimWeight stats;@@ -337,7 +335,6 @@ public class TermAutomatonQuery extends Query {public TermAutomatonWeight(Automaton automaton, IndexSearcher searcher, Map<Integer,TermContext> termStates) throws IOException {super(TermAutomatonQuery.this);this.automaton = automaton;- this.searcher = searcher;this.termStates = termStates;this.similarity = searcher.getSimilarity(true);List<TermStatistics> allTermStats = new ArrayList<>();