summaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/common/attribute_updater.h
blob: 01be629969298a4da0310e4b6f92330f00e95e56 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/document/fieldvalue/fieldvalue.h>
#include <vespa/document/update/documentupdate.h>
#include <vespa/searchlib/attribute/attribute.h>
#include <vespa/vespalib/util/exception.h>

namespace search {

class PredicateAttribute;

namespace tensor { class TensorAttribute; }
namespace attribute {class ReferenceAttribute; }

VESPA_DEFINE_EXCEPTION(UpdateException, vespalib::Exception);

/**
 * Class used to apply (document) field values and field updates to attribute vectors.
 */
class AttributeUpdater {
    using Field = document::Field;
    using FieldValue = document::FieldValue;
    using FieldUpdate = document::FieldUpdate;
    using ValueUpdate = document::ValueUpdate;

public:
    static void handleUpdate(AttributeVector & vec, uint32_t lid, const FieldUpdate & upd);
    static void handleValue(AttributeVector & vec, uint32_t lid, const FieldValue & val);

private:
    template <typename V>
    static void handleUpdate(V & vec, uint32_t lid, const ValueUpdate & upd);
    template <typename V, typename Accessor>
    static void handleValueT(V & vec, Accessor ac, uint32_t lid, const FieldValue & val);
    template <typename V, typename Accessor>
    static void handleUpdateT(V & vec, Accessor ac, uint32_t lid, const ValueUpdate & val);
    template <typename V, typename Accessor>
    static void appendValue(V & vec, uint32_t lid, Accessor & ac);
    static void appendValue(IntegerAttribute & vec, uint32_t lid, const FieldValue & val, int weight=1);
    static void removeValue(IntegerAttribute & vec, uint32_t lid, const FieldValue & val);
    static void updateValue(IntegerAttribute & vec, uint32_t lid, const FieldValue & val);
    static void appendValue(FloatingPointAttribute & vec, uint32_t lid, const FieldValue & val, int weight=1);
    static void removeValue(FloatingPointAttribute & vec, uint32_t lid, const FieldValue & val);
    static void updateValue(FloatingPointAttribute & vec, uint32_t lid, const FieldValue & val);
    static void appendValue(StringAttribute & vec, uint32_t lid, const FieldValue & val, int weight=1);
    static void removeValue(StringAttribute & vec, uint32_t lid, const FieldValue & val);
    static void updateValue(StringAttribute & vec, uint32_t lid, const FieldValue & val);
    static void updateValue(PredicateAttribute & vec, uint32_t lid, const FieldValue & val);
    static void updateValue(tensor::TensorAttribute & vec, uint32_t lid, const FieldValue & val);
    static void updateValue(attribute::ReferenceAttribute & vec, uint32_t lid, const FieldValue & val);
};

}