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 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)
def testPrecedenceAndOr2(self): answer = CQL_QUERY( SCOPED_CLAUSE( SEARCH_CLAUSE( CQL_QUERY( SCOPED_CLAUSE( SCOPED_CLAUSE( SEARCH_CLAUSE(SEARCH_TERM(TERM('term')))), BOOLEAN('and'), SEARCH_CLAUSE( parseString( 'term2 and term3 and term4 and term5'))))), BOOLEAN('or'), SCOPED_CLAUSE(SEARCH_CLAUSE(SEARCH_TERM(TERM('term6')))))) r = parseString( 'term and (term2 and term3 and term4 and term5) or term6') self.assertEqualsCQL(answer, r)
def addFilter(self, field, term): self._addFilter(SEARCH_CLAUSE( INDEX(TERM(field)), RELATION(COMPARITOR('exact')), SEARCH_TERM(TERM(term)) ))
def addTermFilter(self, term): self._addFilter(SEARCH_CLAUSE( SEARCH_TERM( TERM(term) ) ))