aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/vespa/searchsummary/docsummary/query_term_filter_factory.cpp
blob: d51ed6318f1dfcb42ee8367727727544d1008029 (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.

#include "query_term_filter_factory.h"
#include "query_term_filter.h"
#include <vespa/searchcommon/common/schema.h>
#include <vespa/vespalib/stllike/hash_map.hpp>
#include <vespa/vespalib/stllike/hash_set.hpp>

namespace search::docsummary {

QueryTermFilterFactory::QueryTermFilterFactory(const search::index::Schema& schema)
    : IQueryTermFilterFactory(),
      _view_map()
{
    for (uint32_t i = 0; i < schema.getNumFieldSets(); ++i) {
        auto& field_set = schema.getFieldSet(i);
        auto& fields = field_set.getFields();
        for (auto& field : fields) {
            auto& vec = _view_map[field];
            vec.emplace_back(field_set.getName());
        }
    }
}

QueryTermFilterFactory::~QueryTermFilterFactory() = default;

std::shared_ptr<const IQueryTermFilter>
QueryTermFilterFactory::make(vespalib::stringref input_field) const
{
    vespalib::hash_set<vespalib::string> views;
    views.insert(input_field);
    auto itr = _view_map.find(input_field);
    if (itr != _view_map.end()) {
        for (auto& index : itr->second) {
            views.insert(index);
        }
    }
    return std::make_shared<QueryTermFilter>(std::move(views));
}

}