aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/vespa/searchsummary/docsummary/matched_elements_filter_dfw.h
blob: fed634239a4e4dc7d33113e8af74602e640f39f7 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "docsum_field_writer.h"
#include <memory>
#include <vector>

namespace search { class MatchingElementsFields; }

namespace search::attribute { class IAttributeContext; }

namespace search::docsummary {

/**
 * Field writer that filters matched elements (according to the query) from a multi-value or complex field
 * (array of primitive, weighted set of primitive, map of primitives, map of struct, array of struct)
 * that is retrieved from the document store.
 */
class MatchedElementsFilterDFW : public DocsumFieldWriter {
private:
    std::string _input_field_name;
    std::shared_ptr<MatchingElementsFields> _matching_elems_fields;

    const std::vector<uint32_t>& get_matching_elements(uint32_t docid, GetDocsumsState& state) const;

public:
    MatchedElementsFilterDFW(const std::string& input_field_name,
                             std::shared_ptr<MatchingElementsFields> matching_elems_fields);
    static std::unique_ptr<DocsumFieldWriter> create(const std::string& input_field_name,
                                                     std::shared_ptr<MatchingElementsFields> matching_elems_fields);
    static std::unique_ptr<DocsumFieldWriter> create(const std::string& input_field_name,
                                                     search::attribute::IAttributeContext& attr_ctx,
                                                     std::shared_ptr<MatchingElementsFields> matching_elems_fields);
    ~MatchedElementsFilterDFW() override;
    bool isGenerated() const override { return false; }
    void insertField(uint32_t docid, const IDocsumStoreDocument* doc, GetDocsumsState& state,
                     vespalib::slime::Inserter& target) const override;
};

}