diff options
Diffstat (limited to 'container-search')
16 files changed, 124 insertions, 91 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json index d2dcb5aaf85..47c27a52e0b 100644 --- a/container-search/abi-spec.json +++ b/container-search/abi-spec.json @@ -485,12 +485,12 @@ "public" ], "methods": [ - "public com.yahoo.prelude.query.Item$ItemType getItemType()", - "public java.lang.String getName()", - "protected void adding(com.yahoo.prelude.query.Item)", "public void <init>()", "public void <init>(com.yahoo.prelude.query.Item)", - "public void <init>(com.yahoo.prelude.query.Item, java.util.Collection)" + "public void <init>(com.yahoo.prelude.query.Item, java.util.Collection)", + "public com.yahoo.prelude.query.Item$ItemType getItemType()", + "public java.lang.String getName()", + "protected void adding(com.yahoo.prelude.query.Item)" ], "fields": [] }, @@ -2401,6 +2401,8 @@ "public com.yahoo.search.grouping.request.ConstantValue getFrom()", "public com.yahoo.search.grouping.request.ConstantValue getTo()", "public int compareTo(com.yahoo.search.grouping.request.BucketValue)", + "public boolean equals(java.lang.Object)", + "public int hashCode()", "public bridge synthetic com.yahoo.search.grouping.request.GroupingExpression copy()", "public bridge synthetic int compareTo(java.lang.Object)" ], @@ -2799,7 +2801,9 @@ "methods": [ "public void <init>(boolean)", "public java.lang.String toString()", - "public int compareTo(java.lang.Object)" + "public int compareTo(java.lang.Object)", + "public boolean equals(java.lang.Object)", + "public int hashCode()" ], "fields": [] }, @@ -4320,6 +4324,8 @@ "public void setScore(double)", "public double increaseScore(double)", "public int compareTo(com.yahoo.search.intent.model.Node)", + "public boolean equals(java.lang.Object)", + "public int hashCode()", "public bridge synthetic int compareTo(java.lang.Object)" ], "fields": [] diff --git a/container-search/src/main/java/com/yahoo/prelude/Freshness.java b/container-search/src/main/java/com/yahoo/prelude/Freshness.java index 11f6bb4bd50..84f65f8bdc7 100644 --- a/container-search/src/main/java/com/yahoo/prelude/Freshness.java +++ b/container-search/src/main/java/com/yahoo/prelude/Freshness.java @@ -13,7 +13,7 @@ import static com.yahoo.text.Lowercase.toLowerCase; * <p> * This is a value object * - * @author <a href="mailto:pauran@yahoo-inc.com">Per G. Auran</a> + * @author Per G. Auran */ public class Freshness { diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/GroupingListHit.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/GroupingListHit.java index e57fe3a200e..e0d569c6ae1 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/GroupingListHit.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/GroupingListHit.java @@ -9,8 +9,6 @@ import com.yahoo.searchlib.aggregation.Grouping; public class GroupingListHit extends Hit { - private static final long serialVersionUID = -6645125887873082234L; - /** for unit tests only, may give problems if grouping contains docsums */ public GroupingListHit(List<Grouping> groupingList) { this(groupingList, null); diff --git a/container-search/src/main/java/com/yahoo/prelude/query/parser/SpecialTokens.java b/container-search/src/main/java/com/yahoo/prelude/query/parser/SpecialTokens.java index 30c20ddb0ee..c206ff7567e 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/parser/SpecialTokens.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/parser/SpecialTokens.java @@ -142,16 +142,23 @@ public class SpecialTokens { return replace; } + @Override public int compareTo(SpecialToken other) { - if (this.token().length() < other.token().length()) { - return 1; - } else if (this.token().length() == other.token().length()) { - return 0; - } else { - return -1; - } + if (this.token().length() < other.token().length()) return 1; + if (this.token().length() == other.token().length()) return 0; + return -1; } + @Override + public boolean equals(Object other) { + if (other == this) return true; + if ( ! (other instanceof SpecialToken)) return false; + return Objects.equals(this.token, ((SpecialToken)other).token); + } + + @Override + public int hashCode() { return token.hashCode(); } + public Token toToken(int start,String rawSource) { return new Token(Token.Kind.WORD, replace(), true, new Substring(start, start + token.length(), rawSource)); // XXX: Unsafe? } diff --git a/container-search/src/main/java/com/yahoo/search/grouping/request/BucketValue.java b/container-search/src/main/java/com/yahoo/search/grouping/request/BucketValue.java index 392c6386eb7..944616a0b1c 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/request/BucketValue.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/request/BucketValue.java @@ -1,6 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.grouping.request; +import java.util.Objects; + /** * This class represents a bucket in a {@link PredefinedFunction}. The generic T is the data type of the range values * 'from' and 'to'. The range is inclusive-from and exclusive-to. All supported data types are represented as subclasses @@ -48,12 +50,25 @@ public class BucketValue extends GroupingExpression implements Comparable<Bucket @Override public int compareTo(BucketValue rhs) { - if (comparator.compare(to, rhs.from) <= 0) { - return -1; - } - if (comparator.compare(from, rhs.to) >= 0) { - return 1; - } + if (comparator.compare(to, rhs.from) <= 0) return -1; + if (comparator.compare(from, rhs.to) >= 0) return 1; return 0; } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if ( ! (o instanceof BucketValue)) return false; + + BucketValue other = (BucketValue)o; + if ( ! Objects.equals(this.from, other.from)) return false; + if ( ! Objects.equals(this.to, other.to)) return false; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(from, to); + } + } diff --git a/container-search/src/main/java/com/yahoo/search/grouping/request/Infinite.java b/container-search/src/main/java/com/yahoo/search/grouping/request/Infinite.java index 766571914cc..36b59906c11 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/request/Infinite.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/request/Infinite.java @@ -14,6 +14,7 @@ public class Infinite implements Comparable { /** * Create an Infinite object with positive or negative sign. + * * @param negative the signedness. */ public Infinite(boolean negative) { @@ -35,4 +36,15 @@ public class Infinite implements Comparable { public int compareTo(Object rhs) { return (negative ? -1 : 1); } + + @Override + public boolean equals(Object other) { + if (other == this) return true; + if ( ! (other instanceof Infinite)) return false; + return this.negative == ((Infinite)other).negative; + } + + @Override + public int hashCode() { return negative ? -1 : 1; } + } diff --git a/container-search/src/main/java/com/yahoo/search/grouping/request/RawBuffer.java b/container-search/src/main/java/com/yahoo/search/grouping/request/RawBuffer.java index 9b18d7b374c..8af5d47335c 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/request/RawBuffer.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/request/RawBuffer.java @@ -106,7 +106,7 @@ public class RawBuffer implements Comparable<RawBuffer>, Cloneable { return 1; } } - return (my.length < their.length ? -1 : (my.length > their.length ? 1 : 0)); + return Integer.compare(my.length, their.length); } @Override @@ -115,10 +115,10 @@ public class RawBuffer implements Comparable<RawBuffer>, Cloneable { } @Override - public boolean equals(Object rhs) { - if (rhs instanceof RawBuffer) { - return (compareTo((RawBuffer)rhs) == 0); - } - return false; + public boolean equals(Object other) { + if (other == this) return true; + if ( ! (other instanceof RawBuffer)) return false; + return (compareTo((RawBuffer)other) == 0); } + } diff --git a/container-search/src/main/java/com/yahoo/search/intent/model/Node.java b/container-search/src/main/java/com/yahoo/search/intent/model/Node.java index 98bfd588004..84b90b388b0 100644 --- a/container-search/src/main/java/com/yahoo/search/intent/model/Node.java +++ b/container-search/src/main/java/com/yahoo/search/intent/model/Node.java @@ -32,12 +32,25 @@ public abstract class Node implements Comparable<Node> { return getScore(); } + @Override public int compareTo(Node other) { if (this.getScore() < other.getScore()) return 1; if (this.getScore() > other.getScore()) return -1; return 0; } + @Override + public boolean equals(Object other) { + if (other == this) return true; + if ( ! (other instanceof Node)) return false; + return this.getScore() == ((Node)other).getScore(); + } + + @Override + public int hashCode() { + return Double.hashCode(getScore()); + } + /** * Adds the sources at (and beneath) this node to the given * sparsely represented source vector, weighted by the score of this node diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java index 2f4804f0c48..b8290fa092b 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/FieldDescription.java @@ -126,6 +126,7 @@ public class FieldDescription implements Comparable<FieldDescription> { /** Returns false if overrides to values for this field from the outside should be ignored. Default: true */ public boolean isOverridable() { return overridable; } + @Override public int compareTo(FieldDescription other) { return name.toString().compareTo(other.name.toString()); } diff --git a/container-search/src/main/java/com/yahoo/search/result/ChainableComparator.java b/container-search/src/main/java/com/yahoo/search/result/ChainableComparator.java index ebf25f54a99..7981e451697 100644 --- a/container-search/src/main/java/com/yahoo/search/result/ChainableComparator.java +++ b/container-search/src/main/java/com/yahoo/search/result/ChainableComparator.java @@ -26,9 +26,10 @@ public abstract class ChainableComparator implements Comparator<Hit> { * When overriding this in the subclass, always <code>return super.compare(first,second)</code> * at the end of the subclass' implementation. */ - public int compare(Hit first,Hit second) { - if (secondaryComparator==null) return 0; - return secondaryComparator.compare(first,second); + @Override + public int compare(Hit first, Hit second) { + if (secondaryComparator == null) return 0; + return secondaryComparator.compare(first, second); } } diff --git a/container-search/src/main/java/com/yahoo/search/result/FieldComparator.java b/container-search/src/main/java/com/yahoo/search/result/FieldComparator.java index c835ab744b1..211d04a0eac 100644 --- a/container-search/src/main/java/com/yahoo/search/result/FieldComparator.java +++ b/container-search/src/main/java/com/yahoo/search/result/FieldComparator.java @@ -13,7 +13,7 @@ import java.util.Comparator; * <b>Note:</b> this comparator imposes orderings that are inconsistent with equals. * <p> * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ // Is tested in HitSortSpecOrdererTestCase public class FieldComparator extends ChainableComparator { @@ -49,8 +49,7 @@ public class FieldComparator extends ChainableComparator { * There is no locale based sorting here, as the backend does * not do that either. * - * @return -1, 0, 1 if first should be sorted before, equal to - * or after second + * @return -1, 0, 1 if first should be sorted before, equal to or after second */ @Override public int compare(Hit first, Hit second) { @@ -66,7 +65,7 @@ public class FieldComparator extends ChainableComparator { return x; } } - return super.compare(first,second); + return super.compare(first, second); } private Object getSubField(Object field, String key) { @@ -100,7 +99,7 @@ public class FieldComparator extends ChainableComparator { return field; } - public Object getField(Hit hit,String key) { + public Object getField(Hit hit, String key) { if ("[relevance]".equals(key)) return hit.getRelevance(); if ("[rank]".equals(key)) return hit.getRelevance(); if ("[source]".equals(key)) return hit.getSource(); @@ -124,8 +123,7 @@ public class FieldComparator extends ChainableComparator { } else if (second == null) { return 1; } - if (first.getClass().isInstance(second) - && first instanceof Comparable) { + if (first.getClass().isInstance(second) && first instanceof Comparable) { // We now know: // second is of a type which is a subclass of first's type // They both implement Comparable @@ -135,6 +133,7 @@ public class FieldComparator extends ChainableComparator { } } + @Override public String toString() { StringBuilder b = new StringBuilder(); b.append("FieldComparator:"); diff --git a/container-search/src/main/java/com/yahoo/search/result/Hit.java b/container-search/src/main/java/com/yahoo/search/result/Hit.java index 1299654e2b7..bbfa6ec62ad 100644 --- a/container-search/src/main/java/com/yahoo/search/result/Hit.java +++ b/container-search/src/main/java/com/yahoo/search/result/Hit.java @@ -615,15 +615,15 @@ public class Hit extends ListenableFreezableClass implements Data, Comparable<Hi unmodifiableFieldMap = null; } - /** Returns true if the argument is a hit having the same uri as this */ + /** Returns true if the argument is a hit having the same id as this */ @Override - public boolean equals(Object object) { - if ( ! (object instanceof Hit)) - return false; - return getId().equals(((Hit) object).getId()); + public boolean equals(Object other) { + if (other == this) return true; + if ( ! (other instanceof Hit)) return false; + return getId().equals(((Hit) other).getId()); } - /** Returns the hashCode of this hit, which is the hashcode of its uri. */ + /** Returns the hashCode of this hit: The hashcode of its id */ @Override public int hashCode() { if (getId() == null) @@ -645,7 +645,7 @@ public class Hit extends ListenableFreezableClass implements Data, Comparable<Hi if (result != 0) return result; - // if all else fails, compare URIs (alphabetically) + // if all else fails, compare ids if (this.getId() == null && other.getId() == null) return 0; else if (other.getId() == null) diff --git a/container-search/src/main/java/com/yahoo/search/result/HitIterator.java b/container-search/src/main/java/com/yahoo/search/result/HitIterator.java index 3a7793cd6d5..8811d2c6b72 100644 --- a/container-search/src/main/java/com/yahoo/search/result/HitIterator.java +++ b/container-search/src/main/java/com/yahoo/search/result/HitIterator.java @@ -19,10 +19,10 @@ public class HitIterator implements Iterator<Hit> { private int index = -1; /** The list of hits to iterate over */ - private List<Hit> hits = null; + private List<Hit> hits; /** The result the hits belong to */ - private HitGroup hitGroup = null; + private HitGroup hitGroup; /** Whether the iterator is in a state where remove is OK */ private boolean canRemove = false; diff --git a/container-search/src/main/java/com/yahoo/search/result/Relevance.java b/container-search/src/main/java/com/yahoo/search/result/Relevance.java index 69d49dc33ed..da4a1942bc7 100644 --- a/container-search/src/main/java/com/yahoo/search/result/Relevance.java +++ b/container-search/src/main/java/com/yahoo/search/result/Relevance.java @@ -11,8 +11,6 @@ package com.yahoo.search.result; */ public class Relevance implements Comparable<Relevance> { - private static final long serialVersionUID = 4536685722731661704L; - /** The relevancy score. */ private double score; @@ -49,15 +47,12 @@ public class Relevance implements Comparable<Relevance> { } /** Compares relevancy values with */ + @Override public int compareTo(Relevance other) { double thisScore = getScore(); double otherScore = other.getScore(); if (Double.isNaN(thisScore)) { - if (Double.isNaN(otherScore)) { - return 0; - } else { - return -1; - } + return Double.isNaN(otherScore) ? 0 : -1; } else if (Double.isNaN(otherScore)) { return 1; } else { @@ -67,21 +62,16 @@ public class Relevance implements Comparable<Relevance> { /** Compares relevancy values */ @Override - public boolean equals(Object object) { - if (object==this) return true; - - if (!(object instanceof Relevance)) { return false; } - - Relevance other = (Relevance) object; - return getScore() == other.getScore(); + public boolean equals(Object other) { + if (other == this) return true; + if ( ! (other instanceof Relevance)) { return false; } + return this.compareTo((Relevance)other) == 0; } /** Returns a hash from the relevancy value */ @Override public int hashCode() { - double hash=getScore()*335451367; // A largish prime - if (hash>-1 && hash<1) hash=1/hash; - return (int) hash; + return Double.hashCode(score); } } diff --git a/container-search/src/main/java/com/yahoo/search/statistics/PeakQpsSearcher.java b/container-search/src/main/java/com/yahoo/search/statistics/PeakQpsSearcher.java index cf38351d2b5..108e46fb68e 100644 --- a/container-search/src/main/java/com/yahoo/search/statistics/PeakQpsSearcher.java +++ b/container-search/src/main/java/com/yahoo/search/statistics/PeakQpsSearcher.java @@ -19,9 +19,10 @@ import java.util.*; /** * Aggregate peak qps and expose through meta hits and/or log events. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class PeakQpsSearcher extends Searcher { + private final ThreadLocalDirectory<Deque<QueryRatePerSecond>, Long> directory; private final Value qpsStatistics; private final CompoundName propertyName; @@ -34,19 +35,11 @@ public class PeakQpsSearcher extends Searcher { * in the QpsHit class. */ public static class QpsHit extends Hit { - /** - * Machine generated version ID for serialization. - */ - private static final long serialVersionUID = 1042868845398233889L; - - /** - * The name of the field containing mean QPS since the last measurement. - */ + + /** The name of the field containing mean QPS since the last measurement. */ public static final String MEAN_QPS = "mean_qps"; - /** - * The name of the field containing peak QPS since the last measurement. - */ + /** The name of the field containing peak QPS since the last measurement. */ public static final String PEAK_QPS = "peak_qps"; public static final String SCHEME = "meta"; @@ -64,6 +57,7 @@ public class PeakQpsSearcher extends Searcher { public String toString() { return "QPS hit: Peak QPS " + getField(PEAK_QPS) + ", mean QPS " + getField(MEAN_QPS) + "."; } + } static class QueryRatePerSecond { @@ -92,8 +86,7 @@ public class PeakQpsSearcher extends Searcher { static class QueryRate implements ThreadLocalDirectory.Updater<Deque<QueryRatePerSecond>, Long> { @Override - public Deque<QueryRatePerSecond> update( - Deque<QueryRatePerSecond> current, Long when) { + public Deque<QueryRatePerSecond> update(Deque<QueryRatePerSecond> current, Long when) { QueryRatePerSecond last = current.peekLast(); if (last == null || last.when != when) { last = new QueryRatePerSecond(when); @@ -104,8 +97,7 @@ public class PeakQpsSearcher extends Searcher { } @Override - public Deque<QueryRatePerSecond> createGenerationInstance( - Deque<QueryRatePerSecond> previous) { + public Deque<QueryRatePerSecond> createGenerationInstance(Deque<QueryRatePerSecond> previous) { if (previous == null) { return new ArrayDeque<>(); } else { @@ -120,7 +112,7 @@ public class PeakQpsSearcher extends Searcher { List<Deque<QueryRatePerSecond>> data = directory.fetch(); List<QueryRatePerSecond> chewed = merge(data); for (QueryRatePerSecond qps : chewed) { - qpsStatistics.put((double) qps.howMany); + qpsStatistics.put(qps.howMany); } } } @@ -145,9 +137,8 @@ public class PeakQpsSearcher extends Searcher { useMetaHit = false; propertyName = null; } else { - throw new IllegalArgumentException( - "Config definition out of sync with implementation." - + " No way to create output for method " + method + "."); + throw new IllegalArgumentException("Config definition out of sync with implementation." + + " No way to create output for method " + method + "."); } } @@ -158,8 +149,7 @@ public class PeakQpsSearcher extends Searcher { static List<QueryRatePerSecond> merge(List<Deque<QueryRatePerSecond>> measurements) { List<QueryRatePerSecond> rates = new ArrayList<>(); while (measurements.size() > 0) { - Deque<Deque<QueryRatePerSecond>> consumeFrom - = new ArrayDeque<>(measurements.size()); + Deque<Deque<QueryRatePerSecond>> consumeFrom = new ArrayDeque<>(measurements.size()); long current = Long.MAX_VALUE; for (ListIterator<Deque<QueryRatePerSecond>> i = measurements.listIterator(); i.hasNext();) { Deque<QueryRatePerSecond> deck = i.next(); @@ -221,17 +211,15 @@ public class PeakQpsSearcher extends Searcher { int max = Integer.MIN_VALUE; double sum = 0.0d; if (l.size() == 0) { - return new Tuple2<>(Integer.valueOf(0), - Double.valueOf(0.0)); + return new Tuple2<>(0, 0.0); } for (QueryRatePerSecond qps : l) { - sum += (double) qps.howMany; + sum += qps.howMany; if (qps.howMany > max) { max = qps.howMany; } } - return new Tuple2<>(Integer.valueOf(max), - Double.valueOf(sum / (double) l.size())); + return new Tuple2<>(max, sum / (double) l.size()); } } diff --git a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/ListMerger.java b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/ListMerger.java index 7136e32cefd..a17b06d3d0c 100644 --- a/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/ListMerger.java +++ b/container-search/src/main/java/com/yahoo/vespa/streamingvisitors/ListMerger.java @@ -8,9 +8,10 @@ import java.util.ArrayList; /** * A list merger that merges two sorted lists. * - * @author <a href="mailto:ulf@yahoo-inc.com">Ulf Carlin</a> + * @author Ulf Carlin */ public class ListMerger { + public static <T extends Comparable<? super T>> void mergeLinkedLists(List<T> to, List<T> from, int maxEntryCount) { int entryCount = 0; ListIterator<T> i = to.listIterator(); @@ -44,6 +45,7 @@ public class ListMerger { } public static <T extends Comparable<? super T>> List<T> mergeIntoArrayList(List<T> l1, List<T> l2, int maxEntryCount) { + List<T> mergedList = new ArrayList<>(); ListIterator<T> i1 = l1.listIterator(); ListIterator<T> i2 = l2.listIterator(); @@ -101,4 +103,5 @@ public class ListMerger { public static <T extends Comparable<? super T>> List<T> mergeIntoArrayList(List<T> l1, List<T> l2) { return mergeIntoArrayList(l1, l2, Integer.MAX_VALUE); } + } |