What would libsearch
look like?
#4018
Replies: 2 comments
-
|
Beta Was this translation helpful? Give feedback.
-
To create a generic search library, we need to split all the specifics like My solution to this mirrors the ideas in #3937 Refactoring the Expandos. User wants to search the Alias Dialog. The Alias supports three Patterns: "From" (the alias name), "To" (email address), Comment. We might define these in the Alias code as: { 'f', ALIAS_PAT_FROM, PAT_REGEX, NULL },
{ 't', ALIAS_PAT_TO, PAT_REGEX, NULL },
{ 'c', ALIAS_PAT_COMMENT, PAT_REGEX, NULL }, The The Pattern code will have a set of functions to parse common types. When the user starts the search we ask the Pattern code to create a Pattern tree. pat = pattern_parse(alias_patterns, user_string); We'll cache this in case the user hits bool alias_pattern_callback(struct Pattern *pat, void *object)
{
struct Alias *a = object;
if (pat.type == ALIAS_PAT_FROM)
{
//...
}
//...
}
for (int i = 0; i < num_aliases; i++)
{
bool match = pattern_match(pat, aliases[i], callback_fn);
} |
Beta Was this translation helpful? Give feedback.
-
NeoMutt allows searching in most of its Dialogs.
This involves Patterns, regexes and lots of dependencies.
At the "top" of a search, we have Patterns.
At the "bottom" we generally have a Regex being matched against a string.
Patterns can also match numbers and dates.
Patterns can be grouped to create trees of logic:
~f john (~z >10K | ~s spam)
From "john" AND EITHER size greater than 10K OR subject "spam"
Each Pattern must be parsed into a tree and the Pattern operator, e.g.
~f
, looked up in theFlags
table.struct Pattern
will storeMUTT_PAT_FROM
plus the string the user supplied, "john".neomutt/pattern/flags.c
Lines 69 to 71 in a4cbbbb
Most Patterns match against members of
struct Email
orstruct Envelope
.To make a match the Pattern tree is traversed, each node is checked in
pattern_exec()
.It knows that
MUTT_PAT_FROM
means that we should checkEmail.Envelope.from
.Below is a list of how the searches work and how a generic search library might work.
Beta Was this translation helpful? Give feedback.
All reactions