mirror of https://github.com/djcb/mu.git
store::for_each_term: use field-id
We were trying to convert a field (string) to a xapian prefix back to a field (enum). That's unnecessarily complicated and worse, step 2 won't work.
This commit is contained in:
parent
0368a48149
commit
056fecd6aa
|
@ -200,7 +200,7 @@ Parser::Private::process_regex(const std::string& field_str,
|
|||
const auto field{message_field(*id_opt)};
|
||||
const auto prefix{field.xapian_term()};
|
||||
std::vector<std::string> terms;
|
||||
store_.for_each_term(prefix, [&](auto&& str) {
|
||||
store_.for_each_term(field.id, [&](auto&& str) {
|
||||
if (std::regex_search(str.c_str() + 1, rx)) // avoid copy
|
||||
terms.emplace_back(str);
|
||||
return true;
|
||||
|
|
|
@ -604,7 +604,7 @@ Store::commit()
|
|||
}
|
||||
|
||||
std::size_t
|
||||
Store::for_each_term(const std::string& field_name, Store::ForEachTermFunc func) const
|
||||
Store::for_each_term(Message::Field::Id field_id, Store::ForEachTermFunc func) const
|
||||
{
|
||||
size_t n{};
|
||||
|
||||
|
@ -613,20 +613,8 @@ Store::for_each_term(const std::string& field_name, Store::ForEachTermFunc func)
|
|||
* Do _not_ take a lock; this is only called from
|
||||
* the message parser which already has the lock
|
||||
*/
|
||||
|
||||
/* get id from name or shortcut */
|
||||
const auto id_opt = std::invoke([&]()->std::optional<MessageField::Id> {
|
||||
if (field_name.length() == 1)
|
||||
return message_field_id(field_name[0]);
|
||||
else
|
||||
return message_field_id(field_name);
|
||||
});
|
||||
|
||||
if (!id_opt)
|
||||
return;
|
||||
|
||||
const auto prefix{std::string{1, message_field(*id_opt).xapian_prefix()}};
|
||||
std::vector<std::string> terms;
|
||||
const auto prefix{message_field(field_id).xapian_term()};
|
||||
for (auto it = priv_->db().allterms_begin(prefix);
|
||||
it != priv_->db().allterms_end(prefix); ++it) {
|
||||
if (!func(*it))
|
||||
|
|
|
@ -282,12 +282,12 @@ public:
|
|||
* takes a lock on the store, so the func should _not_ call any other
|
||||
* Store:: methods.
|
||||
*
|
||||
* @param a prefix
|
||||
* @param id the field id
|
||||
* @param func a Callable invoked for each message.
|
||||
*
|
||||
* @return the number of times func was invoked
|
||||
*/
|
||||
size_t for_each_term(const std::string& prefix, ForEachTermFunc func) const;
|
||||
size_t for_each_term(Message::Field::Id id, ForEachTermFunc func) const;
|
||||
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue