Skip to content

Commit

Permalink
properly handle % and allow multiword search
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Aug 8, 2023
1 parent 44989b7 commit 45d2a9c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/searchindex_js.cpp
Expand Up @@ -111,7 +111,7 @@ static StringVector splitSearchTokens(std::string str)
{
for (auto& c : str)
{
if (c == '(' || c == ')' || c == ',' || c == '!' || c == '/' || c == '.')
if (c == '(' || c == ')' || c == ',' || c == '!' || c == '/' || c == '.' || c == '%')
{
c = ' ';
}
Expand All @@ -120,10 +120,25 @@ static StringVector splitSearchTokens(std::string str)
StringVector result = split(str, " ");
const auto remover = [](const auto& part)
{
return part.empty() || part[0] == '%';
return part.empty();
};
result.erase(std::remove_if(result.begin(),result.end(),remover),result.end());

if (result.size() > 1)
{
// Concatenate the words starting from the end to allow multiword search
auto rit = result.end();
const auto rend = result.begin();
auto prev = --rit;

do {
--rit;
rit->append(" ");
rit->append(*prev);
prev = rit;
} while (rit != rend);
}

return result;
}

Expand Down

0 comments on commit 45d2a9c

Please sign in to comment.