[ENH] Flatten the AND and OR queries to reduce query size (1 and 2 and 3) becomes and(1, 2, 3) instead of and(1, and(2, 3))

git-svn-id: file:///var/local/code.tiki.org/tikisvn/trunk@46291 b456876b-0849-0410-b77d-98878d47e9d5