boolean text search in python
It would be pretty lucky to find a pre-existing library that happens to be ready to parse the example expression that you provided. I recommend making your expression format a bit more machine readable, while retaining all of its clarity. A Lisp S-expression (which uses prefix notation) is compact and clear:
(and "president" (or "ronald" "george" "sally"))
Writing a parser for this format is easier than for your format. Or you could just switch to Lisp and it will parse it natively. :)
Side note: I assume you didn't mean to make your "NOT" operator binary, right?
DISCLAIMER: I am the creator of the package presented below.
For the people who might come to this page: I built a package to do just that (still in beta).
pip install eldar
Your query would be translated in the following code:
from eldar import Query
eldar = Query('"president" AND ("ronald" OR ("george" AND NOT "bush"))')
print(eldar("President Bush"))
# >>> False
print(eldar("President George"))
# >>> True
You can use it on some pandas dataframe as well, check the git page for more info: https://github.com/kerighan/eldar