summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/memoryindex/document_inverter_context.h
blob: 54a1fff90a45f51ab5b00766794fb571593a2d02 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/index/schema_index_fields.h>
#include "invert_context.h"
#include "push_context.h"
#include <memory>
#include <vector>

namespace document {
class DataType;
class Document;
class DocumentType;
class Field;
class FieldValue;
}

namespace search::memoryindex {

class IFieldIndexCollection;

/*
 * Class containing shared context for document inverters that changes
 * rarely (type dependent data, wiring).
 */
class DocumentInverterContext {
    using IndexedFields = std::vector<std::unique_ptr<document::Field>>;
    const index::Schema&              _schema;
    IndexedFields                     _indexed_fields;
    const document::DataType*         _data_type;
    index::SchemaIndexFields          _schema_index_fields;
    vespalib::ISequencedTaskExecutor& _invert_threads;
    vespalib::ISequencedTaskExecutor& _push_threads;
    IFieldIndexCollection&            _field_indexes;
    std::vector<InvertContext>        _invert_contexts;
    std::vector<PushContext>          _push_contexts;
    void add_field(const document::DocumentType& doc_type, uint32_t fieldId);
    void build_fields(const document::DocumentType& doc_type, const document::DataType* data_type);
    void setup_contexts();
public:
    DocumentInverterContext(const index::Schema &schema,
                            vespalib::ISequencedTaskExecutor &invert_threads,
                            vespalib::ISequencedTaskExecutor &push_threads,
                            IFieldIndexCollection& field_indexes);
    ~DocumentInverterContext();
    void set_data_type(const document::Document& doc);
    const index::Schema& get_schema() const noexcept { return _schema; }
    const index::SchemaIndexFields& get_schema_index_fields() const noexcept { return _schema_index_fields; }
    vespalib::ISequencedTaskExecutor& get_invert_threads() noexcept { return _invert_threads; }
    vespalib::ISequencedTaskExecutor& get_push_threads() noexcept { return _push_threads; }
    IFieldIndexCollection& get_field_indexes() noexcept { return _field_indexes; }
    std::unique_ptr<document::FieldValue> get_field_value(const document::Document& doc, uint32_t field_id) const;
    const std::vector<InvertContext>& get_invert_contexts() const noexcept { return _invert_contexts; }
    const std::vector<PushContext>& get_push_contexts() const noexcept { return _push_contexts; }
};

}