Re: [PATCH] add has: query prefix to search for specific properties

Subject: Re: [PATCH] add has: query prefix to search for specific properties

Date: Sat, 16 Jul 2016 21:39:53 -0300

To: Daniel Kahn Gillmor, Notmuch Mail

Cc:

From: David Bremner


Daniel Kahn Gillmor <dkg@fifthhorseman.net> writes:

> We want to be able to query the properties directly, like:
>
>    notmuch count has:foo=bar
>
> which should return a count of messages where the property with key
> "foo" has value equal to "bar".
>
> This patch could be improved:
>
> If no = sign is present (e.g. "has:foo"), it'd be nice to just match
>  on every message that has property "foo", regardless of value.

At the moment I can't think of a nice easy way to do this.  It could do
something like that proposed for "tag:*", namely expand it internally
into an or query, by traversing the
db->allterms_begin("XPROPERTY"). 

> It would also be good to include some tests.

and update notmuch-search-terms(7) ?

>   *	TIMESTAMP:	The time_t value corresponding to the message's
> @@ -260,6 +263,7 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
>      { "is",			"K" },
>      { "id",			"Q" },
>      { "path",			"P" },
> +    { "has",			"XPROPERTY" },
>      /*
>       * Without the ":", since this is a multi-letter prefix, Xapian
>       * will add a colon itself if the first letter of the path is

Do we want to have the same prefix listed in BOOLEAN_PREFIX_INTERNAL and
BOOLEAN_PREFIX_EXTERNAL? this seems quite fragile. If we don't though,
we have to use the same prefix name for queries as in the code (which is
already sprinkled with _find_prefix ("property") ).

Thread: