O365 / python-o365

A simple python library to interact with Microsoft Graph and Office 365 API
Apache License 2.0
1.65k stars 419 forks source link

multiple negate() ordering in query #991

Open iamme9182 opened 1 year ago

iamme9182 commented 1 year ago

I am trying to build a query to exclude mail matching multiple subjects and am not clear on the behaviour here.

If I add a query like this:

query = query.chain('or')
query = query.negate().on_attribute('subject').contains('value1')
query = query.negate().on_attribute('subject').contains('value2')

The query gets built as:

Filter: not contains(subject, 'value1') or contains(subject, 'value2')

I was expecting to have a 'not' in front of both contains() in the output.

It looks like if I move the negate() to the end of the 'value2' line it has the behaviour I expected and if I add additional contains with negates It looks like I would need to alternate the location of the negate() for each line. Is there a better way to order these to have the behaviour I expected?

alejcas commented 11 months ago

To group sentences, use the Query functions "open_group" and "close_group". Those effectively adds groupings.