nsAbQueryStringToExpression::CreateBooleanConditionString does not support Exists and DoesNotExist provided by nsIAbBooleanExpression
Categories
(Thunderbird :: Address Book, enhancement)
Tracking
(Not tracked)
People
(Reporter: TbSync, Assigned: TbSync)
Details
Attachments
(1 file, 1 obsolete file)
1.12 KB,
patch
|
jorgk-bmo
:
review+
|
Details | Diff | Splinter Review |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134 Steps to reproduce: I want to search for contacts/Cards not having a Attribute, like cards without the field "categories". Searching for an empty field using this search query does not work: let searchstring = abURI + "?(or(categories,=,))"; Probably this does not work, because the field is not empty, but does not exists at all. In https://searchfox.org/comm-central/source/mailnews/addrbook/public/nsIAbBooleanExpression.idl there is the condition type "DoesNotExist" which is however not avail in https://dxr.mozilla.org/comm-central/source/comm/mailnews/addrbook/src/nsAbQueryStringToExpression.cpp#258 I think I need the condition DoesNotExist to solve my issue, but it is not avail. Actual results: Search does not return anything. Expected results: Search should return all cards without any value in the querried field and without having that field at all.
Comment 1•6 years ago
|
||
Can you provide a patch?
Assignee | ||
Comment 2•6 years ago
|
||
I can try, but it would be my first ever patch for Thunderbird. Currently I fail to build TB60 from sources, because of some issue with rust...
Comment 3•6 years ago
|
||
Developers only build trunk from sources on our machines. For TB60 you need "old" versions of everything, so we just push patches to the try server for building.
Assignee | ||
Comment 4•5 years ago
|
||
Assignee | ||
Comment 5•5 years ago
|
||
It turns out to be a very small patch. The actual logic is already implemented here:
https://searchfox.org/comm-central/source/mailnews/addrbook/src/nsAbDirectoryQuery.cpp#464
but until now it was not possible to actually use DoesNotExist.
The attached patch is adding the "!ex" command.
How to proceed? Can I just add "review? Jorg" to this bug?
Comment 6•5 years ago
|
||
Comment on attachment 9056419 [details] [diff] [review] bug1497822.patch I'm not a great connoisseur of that address book stuff. So maybe on of the other guys can take a more qualified look. That said, can you add a test for this stuff?
Assignee | ||
Comment 7•5 years ago
|
||
Is there a tutorial on how to create tests? This is my second patch I have send in and my first actual bugfix, this is all new to me.
I tested this patch by using the new !ex command from an AddOn.
Comment 8•5 years ago
|
||
Usually you can just extend an existing test. I had a look, but only found test_searchAddressInAb.js which is doing something else. The code you're touching here is parsing some stuff from some AB URI. I guess we'll just accept it "as is". Let's see what the reviewers say.
Comment 9•5 years ago
•
|
||
Comment on attachment 9056419 [details] [diff] [review] bug1497822.patch Review of attachment 9056419 [details] [diff] [review]: ----------------------------------------------------------------- I'm happy with this, but while you're here, please add Exists as well as DoesNotExist. I can't find any tests for this stuff (surprise, surprise) so as long as it works, we'll have it…
Updated•5 years ago
|
Assignee | ||
Comment 10•5 years ago
|
||
Updated the patch to also include nsIAbBooleanConditionTypes::Exists.
If it is extra work, I do not need this backported to TB60. Having it in TB68 will be enough for me. Thanks for accepting this.
Comment 11•5 years ago
|
||
Comment on attachment 9056464 [details] [diff] [review] bug1497822.patch I'll land it with r=darktrojan :-)
Comment 12•5 years ago
|
||
Pushed by mozilla@jorgk.com:
https://hg.mozilla.org/comm-central/rev/a4a9ee36c20d
Support Exists and DoesNotExist nsAbQueryStringToExpression::CreateBooleanConditionString(). r=darktrojan
Comment 13•5 years ago
|
||
Can you please provide a complete HG header (with author's e-mail address) and a decent commit message next time.
Anyway, first patch, right? So thank you for your contribution.
This can easily be backported, just let me know.
Comment 14•5 years ago
|
||
I was hoping for the nsAbDirectoryQuery.cpp
part too. Never mind.
Comment 15•5 years ago
|
||
Oh, scratch that, it's done further down.
Comment 16•5 years ago
|
||
I would welcome a test here as it seems we have none for the various query keywords.
I can look into that.
As noticed in comment 0, checking empty fields with '=' or actually any other operator does not work.
It is due to the code at https://searchfox.org/comm-central/source/mailnews/addrbook/src/nsAbDirectoryQuery.cpp#462, where an empty value in AbCard (not query) returns a match only with the operator DoesNotExist (which wasn't accessible until now). Otherwise the result is false (no match) and no further operators are tested.
It could be argued (field,=,string) [Is] or (field,!=,string) [Isnt] could return a useful result too. E.g. if a card doesn't have 'field' defined, why would it NOT match (field,!=,string) ? Right now you have to always use (or(field,!=,string),(field,!ex,)) ???
Also, if we just created the 'ex' and '!ex' query keywords right now, I wonder where all the keywords are documented and we should add the new ones to the list.
Comment 17•5 years ago
|
||
The documentation points to this part of the source code.
Assignee | ||
Comment 18•5 years ago
|
||
As noticed in comment 0, checking empty fields with '=' or actually any other operator does not work.
It is due to the code at https://searchfox.org/comm-central/source/mailnews/addrbook/src/nsAbDirectoryQuery.cpp#462, where an empty value in AbCard (not query) returns a match only with the operator DoesNotExist (which wasn't accessible until now). Otherwise the result is false (no match) and no further operators are tested.
That is correct.
It could be argued (field,=,string) [Is] or (field,!=,string) [Isnt] could return a useful result too. E.g. if a card doesn't have 'field' defined, why would it NOT match (field,!=,string) ? Right now you have to always use (or(field,!=,string),(field,!ex,)) ???
Hm, that looks also correct. I will test that. But under the assumption, that "!=" only checks existing strings, having to test for (or(field,!=,string),(field,!ex,)) is straight forward.
It must be documented of course. When I started to work with this search syntax, I had to look it up in the source. Can I contribute to the doc?
Anyhow, I did not want to modify the standard behaviour of "=" and "!=" because it might break stuff. Since there where special implementations for Exists and DoesNotExists, I just wanted to makle those accessible.
Assignee | ||
Comment 19•5 years ago
|
||
Right now you have to always use (or(field,!=,string),(field,!ex,))
Since the code returns early at line #462 if the field is empty, this is true. I also run a few tests to verify that. For me, this is not an issue, if it gets documented. Ping me, if I can contribute to the docs.
Description
•