diff options
author | Jon Bratseth <bratseth@oath.com> | 2021-10-20 20:51:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-20 20:51:47 +0200 |
commit | 1b42761c7c06c6b7bb983cd075901075613e3f40 (patch) | |
tree | 599e6159c6f668ae6e4b8fbcb4b1c474548c18bc /client | |
parent | 4a1b2d527216a4ad8270d3f173f095cd81c11024 (diff) | |
parent | 23d17b88d0aeda62e4621f80dfe65b1924278aa3 (diff) |
Merge pull request #19658 from vespa-engine/bratseth/no-field-in-weakand
WeakAnd has no field
Diffstat (limited to 'client')
4 files changed, 19 insertions, 15 deletions
diff --git a/client/src/main/java/ai/vespa/client/dsl/Q.java b/client/src/main/java/ai/vespa/client/dsl/Q.java index 32b79c84458..a709ec826fc 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Q.java +++ b/client/src/main/java/ai/vespa/client/dsl/Q.java @@ -162,12 +162,17 @@ public final class Q { * Weakand weak and. * https://docs.vespa.ai/en/reference/query-language-reference.html#weakand * - * @param field the field * @param query the query * @return the weak and query */ - public static WeakAnd weakand(String field, Query query) { - return new WeakAnd(field, query); + public static WeakAnd weakand(Query query) { + return new WeakAnd(query); + } + + /** @deprecated use weakand(query) */ + @Deprecated // Remove on Vespa 8 + public static WeakAnd weakand(String ignored, Query query) { + return new WeakAnd(query); } /** 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 aca43d40b6a..34931b78d2f 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Text.java +++ b/client/src/main/java/ai/vespa/client/dsl/Text.java @@ -1,15 +1,17 @@ // 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.Locale; /** * Text utility functions. + * * @author arnej - **/ + */ final class Text { + public static String format(String format, Object... args) { return String.format(Locale.US, format, args); } + } 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 3059e4adea1..cbd796a6ad5 100644 --- a/client/src/main/java/ai/vespa/client/dsl/WeakAnd.java +++ b/client/src/main/java/ai/vespa/client/dsl/WeakAnd.java @@ -5,13 +5,10 @@ import java.util.stream.Collectors; public class WeakAnd extends QueryChain { - private String fieldName; private Annotation annotation; - private Query value; + private final Query value; - - WeakAnd(String fieldName, Query value) { - this.fieldName = fieldName; + WeakAnd(Query value) { this.value = value; this.nonEmpty = true; } @@ -55,8 +52,8 @@ public class WeakAnd extends QueryChain { boolean hasAnnotation = A.hasAnnotation(annotation); String s = - Text.format("weakAnd(%s, %s)", fieldName, - value.queries.stream().map(Object::toString).collect(Collectors.joining(", "))); + Text.format("weakAnd(%s)", + value.queries.stream().map(Object::toString).collect(Collectors.joining(", "))); return hasAnnotation ? Text.format("([%s]%s)", annotation, s) : s; } } diff --git a/client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy b/client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy index 1bada4e8f59..1040202f761 100644 --- a/client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy +++ b/client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy @@ -233,15 +233,15 @@ class QTest extends Specification { given: def q = Q.select("*") .from("sd1") - .where(Q.weakand("f1", Q.p("f1").contains("v1").and("f2").contains("v2"))) - .and(Q.weakand("f3", Q.p("f1").contains("v1").and("f2").contains("v2")) + .where(Q.weakand(Q.p("f1").contains("v1").and("f2").contains("v2"))) + .and(Q.weakand(Q.p("f1").contains("v1").and("f2").contains("v2")) .annotate(A.a("scoreThreshold", 0.13)) ) .semicolon() .build() expect: - q == """yql=select * from sd1 where weakAnd(f1, f1 contains "v1", f2 contains "v2") and ([{"scoreThreshold":0.13}]weakAnd(f3, f1 contains "v1", f2 contains "v2"));""" + q == """yql=select * from sd1 where weakAnd(f1 contains "v1", f2 contains "v2") and ([{"scoreThreshold":0.13}]weakAnd(f1 contains "v1", f2 contains "v2"));""" } def "geo location"() { |