MCPcopy Index your code
hub / github.com/django-haystack/django-haystack / autocomplete

Method autocomplete

haystack/query.py:491–508  ·  view source on GitHub ↗

A shortcut method to perform an autocomplete search. Must be run against fields that are either ``NgramField`` or ``EdgeNgramField``.

(self, **kwargs)

Source from the content-addressed store, hash-verified

489 return self.filter(**kwargs)
490
491 def autocomplete(self, **kwargs):
492 """
493 A shortcut method to perform an autocomplete search.
494
495 Must be run against fields that are either ``NgramField`` or
496 ``EdgeNgramField``.
497 """
498 clone = self._clone()
499 query_bits = []
500
501 for field_name, query in kwargs.items():
502 for word in query.split(" "):
503 bit = clone.query.clean(word.strip())
504 if bit:
505 kwargs = {field_name: bit}
506 query_bits.append(SQ(**kwargs))
507
508 return clone.filter(reduce(operator.__and__, query_bits))
509
510 def using(self, connection_name):
511 """

Callers 7

test_autocompleteMethod · 0.45
test_autocompleteMethod · 0.45
test_autocompleteMethod · 0.45
test_autocompleteMethod · 0.45
test_autocompleteMethod · 0.45
test_extra_whitespaceMethod · 0.45

Calls 4

_cloneMethod · 0.95
SQClass · 0.90
cleanMethod · 0.45
filterMethod · 0.45

Tested by 7

test_autocompleteMethod · 0.36
test_autocompleteMethod · 0.36
test_autocompleteMethod · 0.36
test_autocompleteMethod · 0.36
test_autocompleteMethod · 0.36
test_extra_whitespaceMethod · 0.36