Ticket #13033: admin-fulltext-12288.diff

File admin-fulltext-12288.diff, 1.4 KB (added by simon29, 5 years ago)
  • contrib/admin/views/main.py

     
    229229                return "%s__icontains" % field_name
    230230
    231231        if self.search_fields and self.query:
    232             for bit in self.query.split():
    233                 or_queries = [models.Q(**{construct_search(str(field_name)): bit}) for field_name in self.search_fields]
    234                 qs = qs.filter(reduce(operator.or_, or_queries))
     232            bits = self.query.split()
     233            or_fields = [ f for f in self.search_fields if f[0] != '@' ]
     234            ft_fields = [ f[1:] for f in self.search_fields if f[0] == '@' ]
     235            if ft_fields:
     236                match = ', '.join([ "`%s`.`%s`" % (self.opts.db_table, f) for f in ft_fields ])
     237                sql = 'MATCH (%s) AGAINST (%%s IN BOOLEAN MODE)' % match
     238                qs = qs.extra(where=[sql], params=[self.query])
     239            for bit in bits:
     240                or_queries = [ models.Q(**{construct_search(str(field_name)): bit})
     241                               for field_name in or_fields ]
     242                if or_queries:
     243                    qs = qs.filter(reduce(operator.or_, or_queries))
    235244            for field_name in self.search_fields:
    236245                if '__' in field_name:
    237246                    qs = qs.distinct()
Back to Top