edelight / chef-solo-search

Data bag search for Chef Solo
Apache License 2.0
177 stars 2 forks source link

Update NOT query documentation in README.md #46

Closed leonardsocialcodeinc closed 10 years ago

leonardsocialcodeinc commented 10 years ago

The NOT condition in queries listed as supported in the README:

search(:users, "children:tom NOT gender:female")

fails.

The actual query format used in the test cases is:

search(:users, "children:tom AND (NOT gender:female)")

tobami commented 10 years ago

Well there is a test using that syntax and it passes: https://github.com/edelight/chef-solo-search/blob/master/tests/test_search.rb#L65

The NOT test does use AND (NOT though: https://github.com/edelight/chef-solo-search/blob/master/tests/test_search.rb#L105

I guess it doesn't hurt to change the README, though if you have more info as to it failing it would be nice.

leonardsocialcodeinc commented 10 years ago

With chef-client "A NOT B" and "A AND NOT B" are equivalent.

$ sudo knife search users "groups:sysadmin NOT action:remove" 10 items found

$ sudo knife search users "groups:sysadmin AND NOT action:remove" 10 items found

On the other hand, with chef-solo-search the results of the search "A NOT B" seems to be equivalent to just "A". e.g. "groups:sysadmin NOT action:remove" returns all items in the users data-bag with the sysadmin groups attribute.

The old NOT testcase (changed in https://github.com/edelight/chef-solo-search/commit/edfc64b) would fail now. It was probably an oversight that the query syntax and testcases were changed, but the documentation was not.

def test_old_NOT_condition nodes = search(:users, "children:tom NOT gender:female") assert nodes.length == 1 nodes = search(:users, "children:tom NOT gender:female AND age:42") assert nodes.length == 1 nodes = search(:users, "children:tom NOT gender:female NOT age:42") assert nodes.length == 0 end

Here's a link to the Lucene NOT syntax: http://lucene.apache.org/core/2_9_4/queryparsersyntax.html#NOT In Lucene (though not Solr) I believe that "A AND NOT B" is actually invalid syntax since NOT is a binary operator and 'cannot be used with just one term'