def testTwoTerms(self): expected = CQL_QUERY( SCOPED_CLAUSE( SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term1'))), ), BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('term2'))))) r = parseString('term1 and term2') self.assertEqualsCQL(expected, r)
def testBooleansAreCaseInsensitive(self): self.assertEqualsCQL( CQL_QUERY( SCOPED_CLAUSE( SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term')))), BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('term2'))))), parseString('term AnD term2'))
def testPrecedenceOrAnd(self): answer = CQL_QUERY( SCOPED_CLAUSE( SEARCH_CLAUSE(SEARCH_TERM(TERM('term1'))), BOOLEAN('or'), SCOPED_CLAUSE( SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term2')))), BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('term3')))))) self.assertEqualsCQL(answer, parseString('term1 or term2 and term3'))
def _addFilter(self, filterQuery): self._filters.append(filterQuery) insertOriginalAst = SCOPED_CLAUSE(SEARCH_CLAUSE(self.ast)) if len(self._filters) == 1 else self.ast.children[0] self.ast = CQL_QUERY( SCOPED_CLAUSE( insertOriginalAst, BOOLEAN('and'), filterQuery ) )
def testPrecedenceAndAndAnd(self): expected = CQL_QUERY( SCOPED_CLAUSE( SCOPED_CLAUSE( SCOPED_CLAUSE( SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('a'))), ), BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('b')))), BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('c')))), BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('d'))))) r = parseString("a and b and c and d") self.assertEqualsCQL(expected, r)
def testOneTerm(self): self.assertEqualsCQL( CQL_QUERY(SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term'))))), parseString('term')) self.assertEqualsCQL( CQL_QUERY( SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM( TERM('white space'))))), parseString('"white space"')) self.assertEqualsCQL( CQL_QUERY( SCOPED_CLAUSE( SEARCH_CLAUSE(SEARCH_TERM(TERM('string "quotes"'))))), parseString(r'"string \"quotes\""'))
def testPrecedenceAndOr(self): answer = CQL_QUERY( SCOPED_CLAUSE( SEARCH_CLAUSE( CQL_QUERY( SCOPED_CLAUSE( SCOPED_CLAUSE( SEARCH_CLAUSE(SEARCH_TERM(TERM('term')))), BOOLEAN('and'), SEARCH_CLAUSE(SEARCH_TERM(TERM('term2')))))), BOOLEAN('or'), SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term3')))))) result = parseString('term and term2 or term3') self.assertEqualsCQL(answer, result)