lib: improve xapianizer / xapian_term
This commit is contained in:
@ -79,17 +79,15 @@ Mu::field_is_combi(const std::string& name)
|
||||
std::string
|
||||
Field::xapian_term(const std::string& s) const
|
||||
{
|
||||
const auto start{std::string(1U, xapian_prefix())};
|
||||
if (const auto& size = s.size(); size == 0)
|
||||
return start;
|
||||
auto res{std::string(1U, xapian_prefix())};
|
||||
if (s.empty())
|
||||
return res;
|
||||
|
||||
std::string res{start};
|
||||
res.reserve(s.size() + 10);
|
||||
|
||||
/* slightly optimized common pure-ascii. */
|
||||
if (G_LIKELY(g_str_is_ascii(s.c_str()))) {
|
||||
res += s;
|
||||
for (auto i = 1; res[i]; ++i)
|
||||
for (auto i = 1U; i != res.length(); ++i)
|
||||
res[i] = g_ascii_tolower(res[i]);
|
||||
} else
|
||||
res += utf8_flatten(s);
|
||||
|
||||
@ -109,17 +109,18 @@ phrase(const Field& field, Sexp&& s)
|
||||
static Result<Xapian::Query>
|
||||
regex(const Store& store, const Field& field, const std::string& rx_str)
|
||||
{
|
||||
auto&& str{utf8_flatten(rx_str)};
|
||||
auto&& rx{Regex::make(str, G_REGEX_OPTIMIZE)};
|
||||
const auto str{utf8_flatten(rx_str)};
|
||||
const auto rx{Regex::make(str, G_REGEX_OPTIMIZE)};
|
||||
if (!rx) {
|
||||
mu_warning("invalid regexp: '{}': {}", str, rx.error().what());
|
||||
return Xapian::Query::MatchNothing;
|
||||
}
|
||||
|
||||
std::vector<Xapian::Query> rxvec;
|
||||
store.for_each_term(field.id, [&](auto&& str) {
|
||||
if (auto&& val{str.data() + 1}; rx->matches(val))
|
||||
rxvec.emplace_back(field.xapian_term(std::string_view{val}));
|
||||
store.for_each_term(field.id, [&](const auto& term) {
|
||||
std::string val{term.data() + 1};
|
||||
if (rx->matches(val))
|
||||
rxvec.emplace_back(field.xapian_term(val));
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user