blob: 6e4a12f1e6a0e4e619ef7072f5b3fc0e5e1f85c7 (
plain)
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
56
57
|
#pragma once
#include "search/common.hpp"
#include "base/string_utils.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"
namespace search
{
class KeywordMatcher
{
public:
typedef strings::UniString StringT;
class ScoreT
{
public:
ScoreT();
bool operator < (ScoreT const & s) const;
bool LessInTokensLength(ScoreT const & s) const;
bool IsQueryMatched() const { return m_bFullQueryMatched; }
private:
friend class KeywordMatcher;
friend string DebugPrint(ScoreT const & score);
uint32_t m_sumTokenMatchDistance;
uint32_t m_nameTokensMatched;
uint32_t m_nameTokensLength;
uint8_t m_numQueryTokensAndPrefixMatched;
bool m_bFullQueryMatched : 1;
bool m_bPrefixMatched : 1;
};
KeywordMatcher();
void Clear();
/// Internal copy of keywords is made.
void SetKeywords(StringT const * keywords, size_t count, StringT const & prefix);
/// @return Score of the name (greater is better).
//@{
ScoreT Score(string const & name) const;
ScoreT Score(StringT const & name) const;
ScoreT Score(StringT const * tokens, size_t count) const;
//@}
private:
vector<StringT> m_keywords;
StringT m_prefix;
};
} // namespace search
|