MCPcopy Create free account
hub / github.com/django-haystack/django-haystack / as_query_string

Method as_query_string

haystack/backends/__init__.py:404–428  ·  view source on GitHub ↗

Produces a portion of the search query from the current SQ and its children.

(self, query_fragment_callback)

Source from the content-addressed store, hash-verified

402 return "%s%s%s=%s" % (field, FILTER_SEPARATOR, filter_type, force_str(value))
403
404 def as_query_string(self, query_fragment_callback):
405 """
406 Produces a portion of the search query from the current SQ and its
407 children.
408 """
409 result = []
410
411 for child in self.children:
412 if hasattr(child, "as_query_string"):
413 result.append(child.as_query_string(query_fragment_callback))
414 else:
415 expression, value = child
416 field, filter_type = self.split_expression(expression)
417 result.append(query_fragment_callback(field, filter_type, value))
418
419 conn = " %s " % self.connector
420 query_string = conn.join(result)
421
422 if query_string:
423 if self.negated:
424 query_string = "NOT (%s)" % query_string
425 elif len(self.children) != 1:
426 query_string = "(%s)" % query_string
427
428 return query_string
429
430 def split_expression(self, expression):
431 """Parses an expression and determines the field and filter type."""

Callers 3

__repr__Method · 0.95
narrowMethod · 0.80
build_queryMethod · 0.80

Calls 1

split_expressionMethod · 0.95

Tested by

no test coverage detected