diff options
26 files changed, 90 insertions, 76 deletions
diff --git a/client/src/main/java/ai/vespa/client/dsl/A.java b/client/src/main/java/ai/vespa/client/dsl/A.java index 3708448ee91..24afeab3df8 100644 --- a/client/src/main/java/ai/vespa/client/dsl/A.java +++ b/client/src/main/java/ai/vespa/client/dsl/A.java @@ -10,7 +10,9 @@ import java.util.stream.Stream; * Helper class for generating Annotation * https://docs.vespa.ai/en/reference/query-language-reference.html#annotations */ -public final class A { +public class A { + + private A() { } private final static Annotation EMPTY = new Annotation(); @@ -97,4 +99,5 @@ public final class A { static boolean hasAnnotation(Annotation annotation) { return annotation != null && !EMPTY.equals(annotation); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/Aggregator.java b/client/src/main/java/ai/vespa/client/dsl/Aggregator.java index cfe885f895c..3c45540c0a0 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Aggregator.java +++ b/client/src/main/java/ai/vespa/client/dsl/Aggregator.java @@ -3,11 +3,11 @@ package ai.vespa.client.dsl; public class Aggregator { - String type; - Object value = ""; + private final String type; + private final Object value; Aggregator(String type) { - this.type = type; + this(type, ""); } Aggregator(String type, Object value) { @@ -19,4 +19,5 @@ public class Aggregator { public String toString() { return Text.format("%s(%s)", type, value); } -} + +}
\ No newline at end of file diff --git a/client/src/main/java/ai/vespa/client/dsl/Annotation.java b/client/src/main/java/ai/vespa/client/dsl/Annotation.java index 6e82e3e462b..ae95ed8647c 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Annotation.java +++ b/client/src/main/java/ai/vespa/client/dsl/Annotation.java @@ -1,14 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.client.dsl; -import java.util.Collections; +import java.util.HashMap; import java.util.Map; public class Annotation { - Map<String, Object> annotations = Collections.emptyMap(); + private final Map<String, Object> annotations; Annotation() { + this(new HashMap<>()); } Annotation(Map<String, Object> annotations) { @@ -24,10 +25,13 @@ public class Annotation { return annotations.containsKey(key); } + public Object get(String key) { + return annotations.get(key); + } + @Override public String toString() { - return annotations == null || annotations.isEmpty() - ? "" - : Q.gson.toJson(annotations); + return annotations == null || annotations.isEmpty() ? "" : Q.gson.toJson(annotations); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/DotProduct.java b/client/src/main/java/ai/vespa/client/dsl/DotProduct.java index 63f47aa64cc..0132c4cd4da 100644 --- a/client/src/main/java/ai/vespa/client/dsl/DotProduct.java +++ b/client/src/main/java/ai/vespa/client/dsl/DotProduct.java @@ -5,8 +5,8 @@ import java.util.Map; public class DotProduct extends QueryChain { - private String fieldName; - private Map<String, Integer> weightedSet; + private final String fieldName; + private final Map<String, Integer> weightedSet; DotProduct(String fieldName, Map<String, Integer> weightedSet) { this.fieldName = fieldName; @@ -47,4 +47,5 @@ public class DotProduct extends QueryChain { // TODO: implementation throw new UnsupportedOperationException("method not implemented"); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/EndQuery.java b/client/src/main/java/ai/vespa/client/dsl/EndQuery.java index 8d6720f6419..61ffe84e5a9 100644 --- a/client/src/main/java/ai/vespa/client/dsl/EndQuery.java +++ b/client/src/main/java/ai/vespa/client/dsl/EndQuery.java @@ -13,10 +13,10 @@ import java.util.stream.Collectors; */ public class EndQuery { - QueryChain queryChain; - Map<String, Integer> map = new LinkedHashMap<>(); - List<Object[]> order = new ArrayList<>(); - String groupQueryStr; + final QueryChain queryChain; + final Map<String, Integer> map = new LinkedHashMap<>(); + final List<Object[]> order = new ArrayList<>(); + private String groupQueryStr; EndQuery(QueryChain queryChain) { this.queryChain = queryChain; @@ -93,8 +93,7 @@ public class EndQuery { * @return the end query */ public EndQuery group(Group group) { - this.groupQueryStr = group.toString(); - return this; + return group(group.toString()); } /** @@ -186,4 +185,5 @@ public class EndQuery { return sb.toString(); } -} + +}
\ No newline at end of file diff --git a/client/src/main/java/ai/vespa/client/dsl/Field.java b/client/src/main/java/ai/vespa/client/dsl/Field.java index 95eb8410503..f166101a854 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Field.java +++ b/client/src/main/java/ai/vespa/client/dsl/Field.java @@ -10,7 +10,7 @@ import java.util.stream.Stream; public class Field extends QueryChain { - private String fieldName; + private final String fieldName; private List<Object> values = new ArrayList<>(); private Annotation annotation = A.empty(); private String relation; @@ -597,9 +597,7 @@ public class Field extends QueryChain { this.relation = relation; this.values = Stream.concat(Stream.of(value), Stream.of(others)).collect(Collectors.toList()); this.nonEmpty = true; - return query != null - ? query - : new Query(sources, this); + return query != null ? query : new Query(sources, this); } @Override @@ -609,7 +607,7 @@ public class Field extends QueryChain { switch (relation) { case "range": valuesStr = values.stream() - .map(i -> i instanceof Long ? i.toString() + "L" : i.toString()) + .map(i -> i instanceof Long ? i + "L" : i.toString()) .collect(Collectors.joining(", ")); return hasAnnotation @@ -635,7 +633,7 @@ public class Field extends QueryChain { : Text.format("nearestNeighbor(%s, %s)", fieldName, valuesStr); default: Object value = values.get(0); - valuesStr = value instanceof Long ? value.toString() + "L" : value.toString(); + valuesStr = value instanceof Long ? value + "L" : value.toString(); return hasAnnotation ? Text.format("%s %s ([%s]%s)", fieldName, relation, annotation, valuesStr) : Text.format("%s %s %s", fieldName, relation, valuesStr); diff --git a/client/src/main/java/ai/vespa/client/dsl/FixedQuery.java b/client/src/main/java/ai/vespa/client/dsl/FixedQuery.java index f122171518c..9976a405182 100644 --- a/client/src/main/java/ai/vespa/client/dsl/FixedQuery.java +++ b/client/src/main/java/ai/vespa/client/dsl/FixedQuery.java @@ -15,9 +15,9 @@ import java.util.stream.Collectors; */ public class FixedQuery { - final EndQuery endQuery; - Map<String, String> others = new HashMap<>(); - Map<String, String> queryMap; + private final EndQuery endQuery; + private final Map<String, String> others = new HashMap<>(); + private Map<String, String> queryMap; FixedQuery(EndQuery endQuery) { this.endQuery = endQuery; @@ -423,4 +423,5 @@ public class FixedQuery { public boolean hasNegativeSearchField(String fieldName, Object value) { return endQuery.queryChain.hasNegativeSearchField(fieldName, value); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/G.java b/client/src/main/java/ai/vespa/client/dsl/G.java index 9605fa67a62..8174bbf0f53 100644 --- a/client/src/main/java/ai/vespa/client/dsl/G.java +++ b/client/src/main/java/ai/vespa/client/dsl/G.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.client.dsl; - /** * Helper class for generating group syntax * https://docs.vespa.ai/en/reference/grouping-syntax.html @@ -10,7 +9,9 @@ package ai.vespa.client.dsl; * The only exception "max" in the Vespa group syntax which represents 'max returned documents', * is replaced by "maxRtn" in the dsl lib. */ -public final class G { +public class G { + + private G() { } public static Group all(IGroupOperation... ops) { return new Group("all", ops); @@ -51,4 +52,5 @@ public final class G { public static Aggregator summary(String summaryClass) { return new Aggregator("summary", summaryClass); } -} + +}
\ No newline at end of file diff --git a/client/src/main/java/ai/vespa/client/dsl/GeoLocation.java b/client/src/main/java/ai/vespa/client/dsl/GeoLocation.java index f60dd6bed6b..8ccb2e69749 100644 --- a/client/src/main/java/ai/vespa/client/dsl/GeoLocation.java +++ b/client/src/main/java/ai/vespa/client/dsl/GeoLocation.java @@ -5,10 +5,10 @@ import org.apache.commons.text.StringEscapeUtils; public class GeoLocation extends QueryChain { - private String fieldName; - private Double longitude; - private Double latitude; - private String radius; + private final String fieldName; + private final Double longitude; + private final Double latitude; + private final String radius; public GeoLocation(String fieldName, Double longitude, Double latitude, String radius) { this.fieldName = fieldName; diff --git a/client/src/main/java/ai/vespa/client/dsl/Group.java b/client/src/main/java/ai/vespa/client/dsl/Group.java index b4047623ca4..840f26a3487 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Group.java +++ b/client/src/main/java/ai/vespa/client/dsl/Group.java @@ -7,8 +7,8 @@ import java.util.stream.Stream; public class Group implements IGroup, IGroupOperation { - String type; - IGroupOperation[] operations; + private final String type; + private final IGroupOperation[] operations; Group(String type, IGroupOperation[] operations) { this.type = type; diff --git a/client/src/main/java/ai/vespa/client/dsl/GroupOperation.java b/client/src/main/java/ai/vespa/client/dsl/GroupOperation.java index f5c86f916e0..b75c2c60ad9 100644 --- a/client/src/main/java/ai/vespa/client/dsl/GroupOperation.java +++ b/client/src/main/java/ai/vespa/client/dsl/GroupOperation.java @@ -7,9 +7,9 @@ import java.util.stream.Stream; public class GroupOperation implements IGroupOperation { - String type; - Object value; - Aggregator[] aggregators; + private final String type; + private Object value; + private Aggregator[] aggregators; public GroupOperation(String type, Object value) { this.type = type; diff --git a/client/src/main/java/ai/vespa/client/dsl/IGroup.java b/client/src/main/java/ai/vespa/client/dsl/IGroup.java index acf8bf755ad..9db71309218 100644 --- a/client/src/main/java/ai/vespa/client/dsl/IGroup.java +++ b/client/src/main/java/ai/vespa/client/dsl/IGroup.java @@ -5,6 +5,4 @@ package ai.vespa.client.dsl; * interface for group syntax */ -public interface IGroup { - -} +public interface IGroup { } diff --git a/client/src/main/java/ai/vespa/client/dsl/IGroupOperation.java b/client/src/main/java/ai/vespa/client/dsl/IGroupOperation.java index 7cedadf7687..26b8b5f1932 100644 --- a/client/src/main/java/ai/vespa/client/dsl/IGroupOperation.java +++ b/client/src/main/java/ai/vespa/client/dsl/IGroupOperation.java @@ -5,6 +5,4 @@ package ai.vespa.client.dsl; * interface for group operation */ -public interface IGroupOperation { - -} +public interface IGroupOperation { } diff --git a/client/src/main/java/ai/vespa/client/dsl/NearestNeighbor.java b/client/src/main/java/ai/vespa/client/dsl/NearestNeighbor.java index 3c3f33ea8da..1ae7f5cdfde 100644 --- a/client/src/main/java/ai/vespa/client/dsl/NearestNeighbor.java +++ b/client/src/main/java/ai/vespa/client/dsl/NearestNeighbor.java @@ -1,13 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.client.dsl; -import java.util.stream.Collectors; - public class NearestNeighbor extends QueryChain { + private final String docVectorName; + private final String queryVectorName; private Annotation annotation; - private String docVectorName; - private String queryVectorName; public NearestNeighbor(String docVectorName, String queryVectorName) { @@ -50,4 +48,5 @@ public class NearestNeighbor extends QueryChain { String s = Text.format("nearestNeighbor(%s, %s)", docVectorName, queryVectorName); return Text.format("([%s]%s)", annotation, s); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/NonEmpty.java b/client/src/main/java/ai/vespa/client/dsl/NonEmpty.java index 9206a0cc6e0..f9c82167645 100644 --- a/client/src/main/java/ai/vespa/client/dsl/NonEmpty.java +++ b/client/src/main/java/ai/vespa/client/dsl/NonEmpty.java @@ -3,7 +3,7 @@ package ai.vespa.client.dsl; public class NonEmpty extends QueryChain { - private Query query; + private final Query query; NonEmpty(Query query) { this.query = query; @@ -43,4 +43,5 @@ public class NonEmpty extends QueryChain { // TODO: implementation throw new UnsupportedOperationException("method not implemented"); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/Query.java b/client/src/main/java/ai/vespa/client/dsl/Query.java index b476f419acd..bc5be2280c4 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Query.java +++ b/client/src/main/java/ai/vespa/client/dsl/Query.java @@ -11,14 +11,14 @@ import java.util.stream.Collectors; */ public class Query extends QueryChain { - Annotation annotation; - Sources sources; - List<QueryChain> queries = new ArrayList<>(); + final List<QueryChain> queries = new ArrayList<>(); + private Annotation annotation; + private Sources sources; Query(Sources sources, QueryChain queryChain) { this.sources = sources; - queries.add(queryChain); - nonEmpty = queryChain.nonEmpty; + this.queries.add(queryChain); + this.nonEmpty = queryChain.nonEmpty; } Query(Sources sources) { @@ -355,4 +355,5 @@ public class Query extends QueryChain { && (!"andnot".equals(this.op) && hasNegativeInSubqueries) || ("andnot".equals(this.op) && hasPositiveInSubqueries); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/QueryChain.java b/client/src/main/java/ai/vespa/client/dsl/QueryChain.java index 86ab1887ce1..31b5220e871 100644 --- a/client/src/main/java/ai/vespa/client/dsl/QueryChain.java +++ b/client/src/main/java/ai/vespa/client/dsl/QueryChain.java @@ -49,4 +49,5 @@ public abstract class QueryChain { abstract boolean hasNegativeSearchField(String fieldName); abstract boolean hasNegativeSearchField(String fieldName, Object value); + } diff --git a/client/src/main/java/ai/vespa/client/dsl/Rank.java b/client/src/main/java/ai/vespa/client/dsl/Rank.java index a36c4caef92..86fe80b2909 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Rank.java +++ b/client/src/main/java/ai/vespa/client/dsl/Rank.java @@ -9,7 +9,7 @@ import java.util.stream.Stream; public class Rank extends QueryChain { - private List<Query> queries = new ArrayList<>(); + private final List<Query> queries = new ArrayList<>(); Rank(Query query, Query... ranks) { this.query = query; @@ -47,4 +47,5 @@ public class Rank extends QueryChain { boolean hasNegativeSearchField(String fieldName, Object value) { return queries.get(0).hasNegativeSearchField(fieldName, value); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/Select.java b/client/src/main/java/ai/vespa/client/dsl/Select.java index 31936e813a0..94cc85c8368 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Select.java +++ b/client/src/main/java/ai/vespa/client/dsl/Select.java @@ -8,7 +8,7 @@ import java.util.stream.Stream; public class Select { - private List<String> selectedFields = new ArrayList<>(); + private final List<String> selectedFields = new ArrayList<>(); Select(String fieldName) { selectedFields.add(fieldName); @@ -20,7 +20,7 @@ public class Select { } Select(List<String> fieldNames) { - selectedFields = new ArrayList<>(fieldNames); + selectedFields.addAll(fieldNames); } public Sources from(String sd) { @@ -35,4 +35,5 @@ public class Select { public String toString() { return selectedFields.isEmpty() ? "*" : String.join(", ", selectedFields); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/Sources.java b/client/src/main/java/ai/vespa/client/dsl/Sources.java index 9d4cff57d9e..a92cd736396 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Sources.java +++ b/client/src/main/java/ai/vespa/client/dsl/Sources.java @@ -11,11 +11,11 @@ import java.util.stream.Stream; public class Sources { final Select select; - final List<String> targetDocTypes; + private final List<String> targetDocTypes; Sources(Select select, List<String> searchDefinitions) { this.select = select; - targetDocTypes = new ArrayList<>(searchDefinitions); + this.targetDocTypes = new ArrayList<>(searchDefinitions); } Sources(Select select, String searchDefinition) { @@ -61,4 +61,5 @@ public class Sources { rank.setSources(this); return new EndQuery(rank); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/Text.java b/client/src/main/java/ai/vespa/client/dsl/Text.java index 34931b78d2f..359e82d1bb4 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Text.java +++ b/client/src/main/java/ai/vespa/client/dsl/Text.java @@ -11,7 +11,7 @@ import java.util.Locale; final class Text { public static String format(String format, Object... args) { - return String.format(Locale.US, format, args); + return String.format(Locale.US, format, args); } } diff --git a/client/src/main/java/ai/vespa/client/dsl/UserInput.java b/client/src/main/java/ai/vespa/client/dsl/UserInput.java index b6977853e84..f42b3d82b52 100644 --- a/client/src/main/java/ai/vespa/client/dsl/UserInput.java +++ b/client/src/main/java/ai/vespa/client/dsl/UserInput.java @@ -7,11 +7,11 @@ import java.util.UUID; public class UserInput extends QueryChain { - Annotation annotation; // accept only defaultIndex annotation - String value; - String indexField; - String placeholder; // for generating unique param - boolean setDefaultIndex; + private final Annotation annotation; // accept only defaultIndex annotation + private final String value; + private final String indexField; + private String placeholder; // for generating unique param + private boolean setDefaultIndex; UserInput(Sources sources, String value) { this(sources, A.empty(), value); @@ -23,9 +23,9 @@ public class UserInput extends QueryChain { this.value = value; this.nonEmpty = true; - if (annotation.annotations.containsKey("defaultIndex")) { + if (annotation.contains("defaultIndex")) { setDefaultIndex = true; - indexField = (String) annotation.annotations.get("defaultIndex"); + indexField = (String) annotation.get("defaultIndex"); } else { indexField = UUID.randomUUID().toString().substring(0, 5); } @@ -77,4 +77,5 @@ public class UserInput extends QueryChain { boolean hasNegativeSearchField(String fieldName, Object value) { return hasNegativeSearchField(fieldName) && this.value.equals(value); } + } diff --git a/client/src/main/java/ai/vespa/client/dsl/Wand.java b/client/src/main/java/ai/vespa/client/dsl/Wand.java index ebb9b023a0d..bda5e2d9802 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Wand.java +++ b/client/src/main/java/ai/vespa/client/dsl/Wand.java @@ -6,9 +6,9 @@ import java.util.Map; public class Wand extends QueryChain { - private String fieldName; + private final String fieldName; + private final Object value; private Annotation annotation; - private Object value; Wand(String fieldName, Map<String, Integer> weightedSet) { diff --git a/client/src/main/java/ai/vespa/client/dsl/WeakAnd.java b/client/src/main/java/ai/vespa/client/dsl/WeakAnd.java index 9c1fc790420..45a616b5a8a 100644 --- a/client/src/main/java/ai/vespa/client/dsl/WeakAnd.java +++ b/client/src/main/java/ai/vespa/client/dsl/WeakAnd.java @@ -5,8 +5,8 @@ import java.util.stream.Collectors; public class WeakAnd extends QueryChain { - private Annotation annotation; private final Query value; + private Annotation annotation; WeakAnd(Query value) { this.value = value; @@ -56,5 +56,5 @@ public class WeakAnd extends QueryChain { value.queries.stream().map(Object::toString).collect(Collectors.joining(", "))); return hasAnnotation ? Text.format("([%s]%s)", annotation, s) : s; } -} +}
\ No newline at end of file diff --git a/client/src/main/java/ai/vespa/client/dsl/WeightedSet.java b/client/src/main/java/ai/vespa/client/dsl/WeightedSet.java index 08a1138370a..e4162003451 100644 --- a/client/src/main/java/ai/vespa/client/dsl/WeightedSet.java +++ b/client/src/main/java/ai/vespa/client/dsl/WeightedSet.java @@ -5,8 +5,8 @@ import java.util.Map; public class WeightedSet extends QueryChain { - private String fieldName; - private Map<String, Integer> weightedSet; + private final String fieldName; + private final Map<String, Integer> weightedSet; WeightedSet(String fieldName, Map<String, Integer> weightedSet) { this.fieldName = fieldName; @@ -47,4 +47,5 @@ public class WeightedSet extends QueryChain { // TODO: implementation throw new UnsupportedOperationException("method not implemented"); } -} + +}
\ No newline at end of file diff --git a/client/src/test/java/ai/vespa/client/dsl/QTest.java b/client/src/test/java/ai/vespa/client/dsl/QTest.java index 08ab603fa04..a249bc91411 100644 --- a/client/src/test/java/ai/vespa/client/dsl/QTest.java +++ b/client/src/test/java/ai/vespa/client/dsl/QTest.java @@ -724,4 +724,5 @@ class QTest { m.put(k3, v3); return m; } + }
\ No newline at end of file |