Parsing a Conditional statement with Python
You can use the builtin function all() here to check phrases in a subquery are part of the string passed.

def get_sub_queries(query):
    for subquery in query.split(' OR '):
        yield subquery


def get_phrases(subquery):
    for phrase in subquery.split(' AND '):
        yield phrase


def find(query, string):
    for subquery in get_sub_queries(query):
        if all(phrase in string for phrase in get_phrases(subquery)):
            return True
    return False


Try to use better variable names(I know it's hard though :-)).

Apart from these I have broken your code into 3 functions now.


Contains logic to split queries to subqueries
Contains logic to split subquery to get phrases
Actual find() functionality


The reason behind this is that if the logic related to anyone of them changes later on then it won't complicate your search functionality and you can write separate tests for each of the three functionalities.



If you're on Python 3.3+ then use could also use yield from.