blob: 377e8e35d24f1e2f0faf357309df418093aff460 (
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
|
#pragma once
#include "indexer/search_delimiters.hpp"
namespace search
{
template <typename LowTokensIterType, typename F>
void SearchStringTokensIntersectionRanges(string const & s, LowTokensIterType itLowBeg, LowTokensIterType itLowEnd, F f)
{
// split input query by tokens and prefix
search::Delimiters delimsTest;
size_t pos = 0;
strings::UniString const str = strings::MakeUniString(s);
size_t const strLen = str.size();
while (pos < strLen)
{
// skip delimeters
while (pos < strLen && delimsTest(str[pos]))
++pos;
size_t const beg = pos;
// find token
while (pos < strLen && !delimsTest(str[pos]))
++pos;
strings::UniString subStr;
subStr.assign(str.begin() + beg, str.begin() + pos);
size_t maxCount = 0;
pair<uint16_t, uint16_t> result(0, 0);
for (LowTokensIterType itLow = itLowBeg; itLow != itLowEnd; ++itLow)
{
size_t const cnt = strings::CountNormLowerSymbols(subStr, *itLow);
if (cnt > maxCount)
{
maxCount = cnt;
result.first = beg;
result.second = cnt;
}
}
if (result.second != 0)
f(result);
}
}
}
|