def build_query(self): filters = [] for the_filter in self.query_filters: filter_list = [] if the_filter.is_and(): filter_list.append("AND") elif the_filter.is_not(): filter_list.append("NOT") elif the_filter.is_or(): filter_list.append("OR") filter_list.append(FILTER_SEPARATOR.join((the_filter.field, the_filter.filter_type))) filter_list.append(the_filter.value) if not len(filters): del(filter_list[0]) filters.append(" ".join(filter_list)) query = " ".join(filters) if self.order_by: query = "%s ORDER BY %s" % (query, ", ".join(self.order_by)) return query
def __repr__(self): join = 'AND' if self.is_not(): join = 'NOT' if self.is_or(): join = 'OR' return '<QueryFilter: %s %s=%s>' % (join, FILTER_SEPARATOR.join((self.field, self.filter_type)), force_unicode(self.value).encode('utf8'))
def split_expression(self, expression): """Parses an expression and determines the field and filter type.""" parts = expression.split(FILTER_SEPARATOR) if len(parts) > 1 and parts[-1] in VALID_FILTERS: filter_type = parts.pop() else: filter_type = 'content' field = FILTER_SEPARATOR.join(parts) return (field, filter_type)
def build_query_fragment(self, field, filter_type, value): result = '' value = str(value) # Check to see if it's a phrase for an exact match. if ' ' in value: value = '"%s"' % value # 'content' is a special reserved word, much like 'pk' in # Django's ORM layer. It indicates 'no special field'. result = ' '.join([FILTER_SEPARATOR.join((field, filter_type)), value]) return result
def build_query_fragment(self, field, filter_type, value): result = '' value = force_unicode(value) # Check to see if it's a phrase for an exact match. if ' ' in value: value = '"%s"' % value index_fieldname = self.backend.site.get_index_fieldname(field) # 'content' is a special reserved word, much like 'pk' in # Django's ORM layer. It indicates 'no special field'. result = ' '.join([FILTER_SEPARATOR.join((index_fieldname, filter_type)), value]) return result
def build_query_fragment(self, field, filter_type, value): result = '' value = force_unicode(value) # Check to see if it's a phrase for an exact match. if ' ' in value: value = '"%s"' % value index_fieldname = self.backend.site.get_index_fieldname(field) # 'content' is a special reserved word, much like 'pk' in # Django's ORM layer. It indicates 'no special field'. result = ' '.join( [FILTER_SEPARATOR.join((index_fieldname, filter_type)), value]) return result