aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/vespa/juniper/reducematcher.h
blob: eccb3a56ba20b333a33bdc99389d6051a9480531 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "rewriter.h"
#include "querymodifier.h"
#include "simplemap.h"

namespace juniper
{

using string_match_table = std::map<std::string, std::vector<QueryTerm*> >;

class string_matcher
{
public:
    explicit string_matcher(Rewriter* rw) : _rewriter(rw), _table() {}

    void add_term(QueryTerm* t);

    inline string_match_table::iterator lookup(std::string& key)
    { return _table.find(key); }
    inline Rewriter* rewriter() const { return _rewriter; }
    inline string_match_table& table() { return _table; }

    inline bool operator==(const string_matcher& m) { return _rewriter == m.rewriter(); }
    std::string dump(); // for debugging
private:
    Rewriter* _rewriter;
    string_match_table _table;

    string_matcher(string_matcher &);
    string_matcher &operator=(string_matcher &);
};

class ReduceMatcher
{
public:
    ReduceMatcher();
    ~ReduceMatcher();
    string_matcher* find(Rewriter* rw);
    const std::vector<QueryTerm*>* match(uint32_t langid, const char* term, size_t len);
private:
    simplemap<Rewriter*, string_matcher*> _matchers;
};

} // end namespace juniper