Fix for issue 613 including test cases; combining complex queries was totally broken

Combining non-trivial queries, for example

    <SQ: AND (content__contains=foo AND content__contains=bar)> | <SQ: AND (content__contains=bar AND author__contains=johnny)>

would give

    <SQ: AND (((content__contains=foo AND content__contains=bar) OR content__contains=bar) AND author__contains=johnny)>

which clearly is wrong. This commit fixes that and adds test cases for the problem.