From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/2] lib: Add regexp searching for mid: prefix
Date: Fri, 24 Mar 2017 09:14:35 -0300 [thread overview]
Message-ID: <20170324121436.28978-2-david@tethera.net> (raw)
In-Reply-To: <20170324121436.28978-1-david@tethera.net>
The bulk of the change is passing in the field options to the regexp
field processor, so that we can properly handle the
fallback (non-regexp case).
---
doc/man7/notmuch-search-terms.rst | 26 +++++++++++++++-----------
lib/database.cc | 6 ++++--
lib/regexp-fields.cc | 22 +++++++++++++++++-----
lib/regexp-fields.h | 4 +++-
test/T650-regexp-query.sh | 16 ++++++++++++++++
5 files changed, 55 insertions(+), 19 deletions(-)
diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst
index 47cab48d..a8ba5e02 100644
--- a/doc/man7/notmuch-search-terms.rst
+++ b/doc/man7/notmuch-search-terms.rst
@@ -50,6 +50,10 @@ indicate user-supplied values):
- id:<message-id>
+- mid:<message-id>
+
+- mid:/<regex>/
+
- thread:<thread-id>
- folder:<maildir-folder>
@@ -75,15 +79,6 @@ subject of an email. Searching for a phrase in the subject is supported
by including quotation marks around the phrase, immediately following
**subject:**.
-If notmuch is built with **Xapian Field Processors** (see below) the
-**from:** and **subject** prefix can be also used to restrict the
-results to those whose from/subject value matches a regular expression
-(see **regex(7)**) delimited with //.
-
-::
-
- notmuch search 'from:/bob@.*[.]example[.]com/'
-
The **attachment:** prefix can be used to search for specific filenames
(or extensions) of attachments to email messages.
@@ -95,8 +90,8 @@ For **tag:** and **is:** valid tag values include **inbox** and
**unread** by default for new messages added by **notmuch new** as well
as any other tag values added manually with **notmuch tag**.
-For **id:**, message ID values are the literal contents of the
-Message-ID: header of email messages, but without the '<', '>'
+For **id:** and **mid**, message ID values are the literal contents of
+the Message-ID: header of email messages, but without the '<', '>'
delimiters.
The **thread:** prefix can be used with the thread ID values that are
@@ -159,6 +154,15 @@ The **property:** prefix searches for messages with a particular
(and extensions) to add metadata to messages. A given key can be
present on a given message with several different values.
+If notmuch is built with **Xapian Field Processors** (see below) the
+**from:**, **mid:** (but not **id:**), and **subject** prefix can be
+also used to restrict the results to those whose from/subject value
+matches a regular expression (see **regex(7)**) delimited with //.
+
+::
+
+ notmuch search 'from:/bob@.*[.]example[.]com/'
+
Operators
---------
diff --git a/lib/database.cc b/lib/database.cc
index 5bc131a3..49b3849c 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -262,7 +262,8 @@ prefix_t prefix_table[] = {
{ "tag", "K", NOTMUCH_FIELD_EXTERNAL },
{ "is", "K", NOTMUCH_FIELD_EXTERNAL },
{ "id", "Q", NOTMUCH_FIELD_EXTERNAL },
- { "mid", "Q", NOTMUCH_FIELD_EXTERNAL },
+ { "mid", "Q", NOTMUCH_FIELD_EXTERNAL |
+ NOTMUCH_FIELD_PROCESSOR },
{ "path", "P", NOTMUCH_FIELD_EXTERNAL },
{ "property", "XPROPERTY", NOTMUCH_FIELD_EXTERNAL },
/*
@@ -313,7 +314,8 @@ _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch)
else if (STRNCMP_LITERAL(prefix->name, "query") == 0)
fp = (new QueryFieldProcessor (*notmuch->query_parser, notmuch))->release ();
else
- fp = (new RegexpFieldProcessor (prefix->name, *notmuch->query_parser, notmuch))->release ();
+ fp = (new RegexpFieldProcessor (prefix->name, prefix->flags,
+ *notmuch->query_parser, notmuch))->release ();
/* we treat all field-processor fields as boolean in order to get the raw input */
notmuch->query_parser->add_boolean_prefix (prefix->name, fp);
diff --git a/lib/regexp-fields.cc b/lib/regexp-fields.cc
index 08c6ccb5..fb1e951f 100644
--- a/lib/regexp-fields.cc
+++ b/lib/regexp-fields.cc
@@ -135,21 +135,33 @@ static inline Xapian::valueno _find_slot (std::string prefix)
return NOTMUCH_VALUE_FROM;
else if (prefix == "subject")
return NOTMUCH_VALUE_SUBJECT;
+ else if (prefix == "mid")
+ return NOTMUCH_VALUE_MESSAGE_ID;
else
throw Xapian::QueryParserError ("unsupported regexp field '" + prefix + "'");
}
-RegexpFieldProcessor::RegexpFieldProcessor (std::string prefix, Xapian::QueryParser &parser_, notmuch_database_t *notmuch_)
- : slot (_find_slot (prefix)), term_prefix (_find_prefix (prefix.c_str ())),
- parser (parser_), notmuch (notmuch_)
+RegexpFieldProcessor::RegexpFieldProcessor (std::string prefix,
+ notmuch_field_flag_t options_,
+ Xapian::QueryParser &parser_,
+ notmuch_database_t *notmuch_)
+ : slot (_find_slot (prefix)),
+ term_prefix (_find_prefix (prefix.c_str ())),
+ options (options_),
+ parser (parser_),
+ notmuch (notmuch_)
{
};
Xapian::Query
RegexpFieldProcessor::operator() (const std::string & str)
{
- if (str.size () == 0)
- return Xapian::Query::MatchAll;
+ if (str.size () == 0) {
+ if (options & NOTMUCH_FIELD_PROBABILISTIC)
+ return Xapian::Query::MatchAll;
+ else
+ return Xapian::Query(term_prefix);
+ }
if (str.at (0) == '/') {
if (str.at (str.size () - 1) == '/'){
diff --git a/lib/regexp-fields.h b/lib/regexp-fields.h
index a4ba7ad8..d5f93445 100644
--- a/lib/regexp-fields.h
+++ b/lib/regexp-fields.h
@@ -65,11 +65,13 @@ class RegexpFieldProcessor : public Xapian::FieldProcessor {
protected:
Xapian::valueno slot;
std::string term_prefix;
+ notmuch_field_flag_t options;
Xapian::QueryParser &parser;
notmuch_database_t *notmuch;
public:
- RegexpFieldProcessor (std::string prefix, Xapian::QueryParser &parser_, notmuch_database_t *notmuch_);
+ RegexpFieldProcessor (std::string prefix, notmuch_field_flag_t options,
+ Xapian::QueryParser &parser_, notmuch_database_t *notmuch_);
~RegexpFieldProcessor () { };
diff --git a/test/T650-regexp-query.sh b/test/T650-regexp-query.sh
index 05c244c9..5bd24086 100755
--- a/test/T650-regexp-query.sh
+++ b/test/T650-regexp-query.sh
@@ -94,4 +94,20 @@ Query string was: from:/unbalanced[/
EOF
test_expect_equal_file EXPECTED OUTPUT
+test_begin_subtest "empty mid search"
+notmuch search --output=messages mid:yoom > OUTPUT
+cp /dev/null EXPECTED
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "non-empty mid regex search"
+notmuch search --output=messages mid:/yoom/ > OUTPUT
+test_expect_equal_file cworth.msg-ids OUTPUT
+
+test_begin_subtest "combine regexp mid and subject"
+notmuch search subject:/-C/ and mid:/y..m/ | notmuch_search_sanitize > OUTPUT
+cat <<EOF > EXPECTED
+thread:XXX 2009-11-18 [1/2] Carl Worth| Jan Janak; [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
test_done
--
2.11.0
next prev parent reply other threads:[~2017-03-24 12:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-24 12:14 regexp search for more things David Bremner
2017-03-24 12:14 ` David Bremner [this message]
2017-03-24 12:14 ` [PATCH 2/2] lib: Add regexp expansion for for tags and paths David Bremner
2017-03-30 0:46 ` v2 regexp search for mid/folder/path David Bremner
2017-03-30 0:46 ` [PATCH 1/2] lib: Add regexp searching for mid: prefix David Bremner
2017-03-30 0:46 ` [PATCH 2/2] lib: Add regexp expansion for for tags and paths David Bremner
2022-05-27 15:29 ` searching to doesn't support regexes ? erik colson
2022-05-27 17:37 ` David Bremner
2022-05-27 19:35 ` erik colson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170324121436.28978-2-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).