blob: 1b81b8a7a733559b78752189101248bd8db7f66b (
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/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
|