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