aboutsummaryrefslogtreecommitdiffstats
path: root/streamingvisitors/src/vespa/vsm/searcher/utf8suffixstringfieldsearcher.cpp
blob: 8bbacf168cf943d589e68697d525a4aa5d7ba505 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "utf8suffixstringfieldsearcher.h"
#include "tokenizereader.h"

using search::byte;
using search::streaming::QueryTerm;
using search::streaming::QueryTermList;

namespace vsm {

std::unique_ptr<FieldSearcher>
UTF8SuffixStringFieldSearcher::duplicate() const
{
    return std::make_unique<UTF8SuffixStringFieldSearcher>(*this);
}

size_t
UTF8SuffixStringFieldSearcher::matchTerms(const FieldRef & f, size_t mintsz)
{
    (void) mintsz;
    termcount_t words = 0;
    if (f.size() >= _buf->size()) {
        _buf->reserve(f.size() + 1);
    }
    cmptype_t * dstbuf = &(*_buf.get())[0];

    TokenizeReader reader(reinterpret_cast<const byte *> (f.data()), f.size(), dstbuf);
    while ( reader.hasNext() ) {
        tokenize(reader);
        size_t tokenlen = reader.complete();
        for (auto qt : _qtl) {
            const cmptype_t * term;
            termsize_t tsz = qt->term(term);
            if (matchTermSuffix(term, tsz, dstbuf, tokenlen)) {
                addHit(*qt, words);
            }
        }
        words++;
    }
    return words;
}

size_t
UTF8SuffixStringFieldSearcher::matchTerm(const FieldRef & f, QueryTerm & qt)
{
    return matchTermSuffix(f, qt);
}

}