aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/multi_term_hash_filter.hpp
blob: e67bda147d70a8d3d520c46c48d1cd33e4b6ce73 (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "multi_term_hash_filter.h"
#include <vespa/searchlib/common/bitvector.h>
#include <vespa/searchlib/fef/termfieldmatchdata.h>

namespace search::attribute {

template <typename WrapperType>
MultiTermHashFilter<WrapperType>::MultiTermHashFilter(fef::TermFieldMatchData& tfmd,
                                                      WrapperType attr,
                                                      TokenMap&& map)
    : _tfmd(tfmd),
      _attr(attr),
      _map(std::move(map)),
      _weight(0)
{
}

template <typename WrapperType>
void
MultiTermHashFilter<WrapperType>::and_hits_into(BitVector& result, uint32_t begin_id)
{
    auto end = _map.end();
    result.foreach_truebit([&, end](uint32_t key) { if ( _map.find(_attr.getToken(key)) == end) { result.clearBit(key); }}, begin_id);
}

template <typename WrapperType>
void
MultiTermHashFilter<WrapperType>::doSeek(uint32_t docId)
{
    auto pos = _map.find(_attr.getToken(docId));
    if (pos != _map.end()) {
        _weight = pos->second;
        setDocId(docId);
    }
}

template <typename WrapperType>
void
MultiTermHashFilter<WrapperType>::doUnpack(uint32_t docId)
{
    if constexpr (unpack_weights) {
        _tfmd.reset(docId);
        fef::TermFieldMatchDataPosition pos;
        pos.setElementWeight(_weight);
        _tfmd.appendPosition(pos);
    } else {
        _tfmd.resetOnlyDocId(docId);
    }
}
    
}