aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/test/string_field_builder.h
blob: 13a3b16db852fdae6f8851e7298efedd4b98c9fd (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/vespalib/stllike/string.h>
#include <vespa/document/repo/fixedtyperepo.h>
#include <memory>

namespace document {
class SpanList;
struct SpanNode;
class SpanTree;
class StringFieldValue;
}

namespace search::test {

class DocBuilder;

/*
 * Helper class to build annotated string field.
 */
class StringFieldBuilder {
    vespalib::string    _value;
    size_t              _span_start;
    document::SpanList* _span_list;  // owned by _span_tree
    std::unique_ptr<document::SpanTree> _span_tree;
    const document::SpanNode* _last_span;
    const document::FixedTypeRepo _repo;
    void start_annotate();
    void add_span();
public:
    StringFieldBuilder(const DocBuilder& doc_builder);
    ~StringFieldBuilder();
    StringFieldBuilder& token(const vespalib::string& val, bool is_word);
    StringFieldBuilder& word(const vespalib::string& val) { return token(val, true); }
    StringFieldBuilder& space() { return token(" ", false); }
    StringFieldBuilder& tokenize(const vespalib::string& val);
    StringFieldBuilder& alt_word(const vespalib::string& val);
    document::StringFieldValue build();
};

}