Esempio n. 1
0
 def __init__(self, *expressions, **extra):
     super(SearchVector, self).__init__(*expressions, **extra)
     self.source_expressions = [
         Coalesce(expression, Value(''))
         for expression in self.source_expressions
     ]
     self.config = self.extra.get('config', self.config)
     weight = self.extra.get('weight')
     if weight is not None and not hasattr(weight, 'resolve_expression'):
         weight = Value(weight)
     self.weight = weight
Esempio n. 2
0
 def batch_process_rhs(self, compiler, connection, rhs=None):
     if rhs is None:
         rhs = self.rhs
     if self.bilateral_transforms:
         sqls, sqls_params = [], []
         for p in rhs:
             value = Value(p, output_field=self.lhs.output_field)
             value = self.apply_bilateral_transforms(value)
             value = value.resolve_expression(compiler.query)
             sql, sql_params = compiler.compile(value)
             sqls.append(sql)
             sqls_params.extend(sql_params)
     else:
         _, params = self.get_db_prep_lookup(rhs, connection)
         sqls, sqls_params = ['%s'] * len(params), params
     return sqls, sqls_params
Esempio n. 3
0
 def __init__(self, expression, string, **extra):
     if not hasattr(string, 'resolve_expression'):
         string = Value(string)
     super(TrigramBase, self).__init__(expression,
                                       string,
                                       output_field=FloatField(),
                                       **extra)
Esempio n. 4
0
 def __init__(self, vector, query, **extra):
     if not hasattr(vector, 'resolve_expression'):
         vector = SearchVector(vector)
     if not hasattr(query, 'resolve_expression'):
         query = SearchQuery(query)
     weights = extra.get('weights')
     if weights is not None and not hasattr(weights, 'resolve_expression'):
         weights = Value(weights)
     self.weights = weights
     super(SearchRank, self).__init__(vector, query, **extra)
Esempio n. 5
0
 def process_rhs(self, compiler, connection):
     value = self.rhs
     if self.bilateral_transforms:
         if self.rhs_is_direct_value():
             # Do not call get_db_prep_lookup here as the value will be
             # transformed before being used for lookup
             value = Value(value, output_field=self.lhs.output_field)
         value = self.apply_bilateral_transforms(value)
         value = value.resolve_expression(compiler.query)
     # Due to historical reasons there are a couple of different
     # ways to produce sql here. get_compiler is likely a Query
     # instance, _as_sql QuerySet and as_sql just something with
     # as_sql. Finally the value can of course be just plain
     # Python value.
     if hasattr(value, 'get_compiler'):
         value = value.get_compiler(connection=connection)
     if hasattr(value, 'as_sql'):
         sql, params = compiler.compile(value)
         return '(' + sql + ')', params
     if hasattr(value, '_as_sql'):
         sql, params = value._as_sql(connection=connection)
         return '(' + sql + ')', params
     else:
         return self.get_db_prep_lookup(value, connection)
Esempio n. 6
0
 def resolve_expression(self,
                        query=None,
                        allow_joins=True,
                        reuse=None,
                        summarize=False,
                        for_save=False):
     resolved = super(SearchVector,
                      self).resolve_expression(query, allow_joins, reuse,
                                               summarize, for_save)
     if self.config:
         if not hasattr(self.config, 'resolve_expression'):
             resolved.config = Value(self.config).resolve_expression(
                 query, allow_joins, reuse, summarize, for_save)
         else:
             resolved.config = self.config.resolve_expression(
                 query, allow_joins, reuse, summarize, for_save)
     return resolved