aboutsummaryrefslogtreecommitdiffstats
path: root/client/src/main/java/ai/vespa/client/dsl/Wand.java
blob: a1006c43331f2443b7663cd1ad390cb6c9cefac3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.client.dsl;

import java.util.List;
import java.util.Map;

public class Wand extends QueryChain {

    private final String fieldName;
    private final Object value;
    private Annotation annotation;


    Wand(String fieldName, Map<String, Integer> weightedSet) {
        this.fieldName = fieldName;
        this.value = weightedSet;
        this.nonEmpty = true;
    }

    Wand(String fieldName, List<List<Integer>> numeric) {
        boolean invalid = numeric.stream().anyMatch(range -> range.size() != 2);
        if (invalid) {
            throw new IllegalArgumentException("incorrect range format");
        }

        this.fieldName = fieldName;
        this.value = numeric;
        this.nonEmpty = true;
    }

    public Wand annotate(Annotation annotation) {
        this.annotation = annotation;
        return this;
    }

    @Override
    public Select getSelect() {
        return sources.select;
    }

    @Override
    boolean hasPositiveSearchField(String fieldName) {
        // TODO: implementation
        throw new UnsupportedOperationException("method not implemented");
    }

    @Override
    boolean hasPositiveSearchField(String fieldName, Object value) {
        // TODO: implementation
        throw new UnsupportedOperationException("method not implemented");
    }

    @Override
    boolean hasNegativeSearchField(String fieldName) {
        // TODO: implementation
        throw new UnsupportedOperationException("method not implemented");
    }

    @Override
    boolean hasNegativeSearchField(String fieldName, Object value) {
        // TODO: implementation
        throw new UnsupportedOperationException("method not implemented");
    }

    @Override
    public String toString() {
        boolean hasAnnotation = A.hasAnnotation(annotation);
        String s = Text.format("wand(%s, %s)", fieldName, Q.toJson(value));
        return hasAnnotation ? Text.format("(%s%s)", annotation, s) : s;
    }

}