Пример #1
0
 def visitSEARCH_CLAUSE(self, node):
     # possible children:
     # CQL_QUERY
     # SEARCH_TERM
     # INDEX, RELATION, SEARCH_TERM
     firstChild = node.children[0].name
     results = CqlVisitor.visitSEARCH_CLAUSE(self, node)
     if firstChild == 'SEARCH_TERM':
         (unqualifiedRhs,) = results
         unqualifiedTermFields = [
             _formatBoost(_formatTerm(fieldname, unqualifiedRhs), boost) 
                 for fieldname, boost in self._unqualifiedTermFields
             ]
         if len(unqualifiedTermFields) == 1:
             return unqualifiedTermFields[0]
         return "(%s)" % ' OR '.join(unqualifiedTermFields)
     elif firstChild == 'INDEX':
         (index, (relation, boost), term) = results
         if relation in ['==', 'exact']:
             query = '%s:"%s"' % (index, term)
         elif relation == '=':
             query = _formatTerm(index, term)
         elif relation in ['>', '<', '>=', '<=']:
             query = _formatRangeTerm(index, relation, term)
         else:
             raise UnsupportedCQL("Only =, ==, exact, <, <=, > and >= are supported.")
         return _formatBoost(query, boost)
     else:
         ((query,),) = results
         return query
Пример #2
0
 def visitSEARCH_CLAUSE(self, node):
     # possible children:
     # CQL_QUERY
     # SEARCH_TERM
     # INDEX, RELATION, SEARCH_TERM
     firstChild = node.children[0].name
     results = CqlVisitor.visitSEARCH_CLAUSE(self, node)
     if firstChild == 'SEARCH_TERM':
         (unqualifiedRhs, ) = results
         unqualifiedTermFields = [
             _formatBoost(_formatTerm(fieldname, unqualifiedRhs), boost)
             for fieldname, boost in self._unqualifiedTermFields
         ]
         if len(unqualifiedTermFields) == 1:
             return unqualifiedTermFields[0]
         return "(%s)" % ' OR '.join(unqualifiedTermFields)
     elif firstChild == 'INDEX':
         (index, (relation, boost), term) = results
         if relation in ['==', 'exact']:
             query = '%s:"%s"' % (index, term)
         elif relation == '=':
             query = _formatTerm(index, term)
         elif relation in ['>', '<', '>=', '<=']:
             query = _formatRangeTerm(index, relation, term)
         else:
             raise UnsupportedCQL(
                 "Only =, ==, exact, <, <=, > and >= are supported.")
         return _formatBoost(query, boost)
     else:
         ((query, ), ) = results
         return query
Пример #3
0
 def visitSEARCH_CLAUSE(self, node):
     firstChild = node.children[0].name
     result = CqlVisitor.visitSEARCH_CLAUSE(self, node)
     if firstChild == 'SEARCH_TERM':
         self._logger(clause = result[0].lower())
     elif firstChild == 'INDEX':
         self._logger(clause = "%s %s %s" % (result[0], result[1], quot(result[2].lower())))
     return result
Пример #4
0
 def visitSCOPED_CLAUSE(self, node):
     clause = CqlVisitor.visitSCOPED_CLAUSE(self, node)
     if len(clause) == 1:
         return clause[0]
     lhs, operator, rhs = clause
     query = BooleanQuery()
     query.add(lhs, LHS_OCCUR[operator])
     query.add(rhs, RHS_OCCUR[operator])
     return query
Пример #5
0
 def visitSEARCH_CLAUSE(self, node):
     firstChild = node.children[0].name
     result = CqlVisitor.visitSEARCH_CLAUSE(self, node)
     if firstChild == 'SEARCH_TERM':
         self._logger(clause=result[0].lower())
     elif firstChild == 'INDEX':
         self._logger(clause="%s %s %s" %
                      (result[0], result[1], quot(result[2].lower())))
     return result
Пример #6
0
 def visitRELATION(self, node):
     results = CqlVisitor.visitRELATION(self, node)
     if len(results) == 1:
         relation = results[0]
         boost = 1.0
     else:
         (relation, (modifier, comparitor, value)) = results
         boost = float(value)
     return relation, boost
Пример #7
0
 def visitSCOPED_CLAUSE(self, node):
     clause = CqlVisitor.visitSCOPED_CLAUSE(self, node)
     if len(clause) == 1:
         return clause[0]
     lhs, operator, rhs = clause
     query = BooleanQuery()
     query.add(lhs, LHS_OCCUR[operator])
     query.add(rhs, RHS_OCCUR[operator])
     return query
Пример #8
0
 def visitRELATION(self, node):
     results = CqlVisitor.visitRELATION(self, node)
     if len(results) == 1:
         relation = results[0]
         boost = 1.0
     else:
         (relation, (modifier, comparitor, value)) = results
         boost = float(value)
     return relation, boost
Пример #9
0
    def visitSEARCH_CLAUSE(self, node):
        # possible children:
        # CQL_QUERY
        # SEARCH_TERM
        # INDEX, RELATION, SEARCH_TERM
        firstChild = node.children[0].name
        results = CqlVisitor.visitSEARCH_CLAUSE(self, node)
        if firstChild == 'SEARCH_TERM':
            (unqualifiedRhs, ) = results
            if unqualifiedRhs == '*':
                return MatchAllDocsQuery()
            subQueries = []
            for fieldname, boost in self._unqualifiedTermFields:
                subQuery = self._termOrPhraseQuery(fieldname, unqualifiedRhs)
                if isinstance(
                        subQuery, PhraseQuery
                ) and not self._fieldRegistry.phraseQueryPossible(fieldname):
                    continue
                subQuery.setBoost(boost)
                subQueries.append(subQuery)
            if len(subQueries) == 1:
                query = subQueries[0]
            else:
                query = BooleanQuery()
                for subQuery in subQueries:
                    query.add(subQuery, BooleanClause.Occur.SHOULD)
            return query
        elif firstChild == 'INDEX':
            (left, (relation, boost), right) = results
            if relation in [
                    '==', 'exact'
            ] or (relation == '=' and self._fieldRegistry.isUntokenized(left)):
                query = TermQuery(self._createTerm(left, right))
            elif relation == '=':
                query = self._termOrPhraseQuery(left, right)
            elif relation in ['<', '<=', '>=', '>']:
                query = self._termRangeQuery(left, relation, right)
            else:
                raise UnsupportedCQL("'%s' not supported for the field '%s'" %
                                     (relation, left))

            query.setBoost(boost)
            return query
        else:
            ((query, ), ) = results
            return query
Пример #10
0
    def visitSEARCH_CLAUSE(self, node):
        # possible children:
        # CQL_QUERY
        # SEARCH_TERM
        # INDEX, RELATION, SEARCH_TERM
        firstChild = node.children[0].name
        results = CqlVisitor.visitSEARCH_CLAUSE(self, node)
        if firstChild == 'SEARCH_TERM':
            (unqualifiedRhs,) = results
            if unqualifiedRhs == '*':
                return MatchAllDocsQuery()
            subQueries = []
            for fieldname, boost in self._unqualifiedTermFields:
                subQuery = self._termOrPhraseQuery(fieldname, unqualifiedRhs)
                if isinstance(subQuery, PhraseQuery) and not self._fieldRegistry.phraseQueryPossible(fieldname):
                    continue
                subQuery.setBoost(boost)
                subQueries.append(subQuery)
            if len(subQueries) == 1:
                query = subQueries[0]
            else:
                query = BooleanQuery()
                for subQuery in subQueries:
                    query.add(subQuery, BooleanClause.Occur.SHOULD)
            return query
        elif firstChild == 'INDEX':
            (left, (relation, boost), right) = results
            if relation in ['==', 'exact'] or (relation == '=' and self._fieldRegistry.isUntokenized(left)):
                query = TermQuery(self._createTerm(left, right))
            elif relation == '=':
                query = self._termOrPhraseQuery(left, right)
            elif relation in ['<','<=','>=','>']:
                query = self._termRangeQuery(left, relation, right)
            else:
                raise UnsupportedCQL("'%s' not supported for the field '%s'" % (relation, left))

            query.setBoost(boost)
            return query
        else:
            ((query,),) = results
            return query
Пример #11
0
 def visitRELATION(self, node):
     result = CqlVisitor.visitRELATION(self, node)
     if len(result) == 1:
         return result[0]
     relation, (modifier, comparitor, value) = result
     return "%s/%s%s%s" % (relation, modifier, comparitor, value)
Пример #12
0
 def __init__(self, astTree, logger):
     CqlVisitor.__init__(self, astTree)
     self._logger = logger
Пример #13
0
 def __init__(self, unqualifiedTermFields, node, analyzer, fieldRegistry):
     CqlVisitor.__init__(self, node)
     self._unqualifiedTermFields = unqualifiedTermFields
     self._analyzer = analyzer
     self._fieldRegistry = fieldRegistry
Пример #14
0
 def visitRELATION(self, node):
     result = CqlVisitor.visitRELATION(self, node)
     if len(result) == 1:
         return result[0]
     relation, (modifier, comparitor, value) = result
     return "%s/%s%s%s" % (relation, modifier, comparitor, value)
Пример #15
0
 def visitINDEX(self, node):
     results = CqlVisitor.visitINDEX(self, node)
     return results.replace(':', '\\:')
Пример #16
0
 def __init__(self, ast, unqualifiedTermFields):
     CqlVisitor.__init__(self, ast)
     self._unqualifiedTermFields = unqualifiedTermFields
Пример #17
0
 def visitSCOPED_CLAUSE(self, node):
     clause = CqlVisitor.visitSCOPED_CLAUSE(self, node)
     if len(clause) == 1:
         return clause[0]
     return "(%s)" % ' '.join(clause)
Пример #18
0
 def visitINDEX(self, node):
     results = CqlVisitor.visitINDEX(self, node)
     return results.replace(':', '\\:')
Пример #19
0
 def __init__(self, unqualifiedTermFields, node, analyzer, fieldRegistry):
     CqlVisitor.__init__(self, node)
     self._unqualifiedTermFields = unqualifiedTermFields
     self._analyzer = analyzer
     self._fieldRegistry = fieldRegistry
Пример #20
0
 def __init__(self, ast, unqualifiedTermFields):
     CqlVisitor.__init__(self, ast)
     self._unqualifiedTermFields = unqualifiedTermFields
Пример #21
0
 def visitSCOPED_CLAUSE(self, node):
     clause = CqlVisitor.visitSCOPED_CLAUSE(self, node)
     if len(clause) == 1:
         return clause[0]
     return "(%s)" % ' '.join(clause)
Пример #22
0
 def __init__(self, astTree, logger):
     CqlVisitor.__init__(self, astTree)
     self._logger = logger