diff options
Diffstat (limited to '97suifangqa/apps/utils')
-rw-r--r-- | 97suifangqa/apps/utils/search_tools.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/97suifangqa/apps/utils/search_tools.py b/97suifangqa/apps/utils/search_tools.py new file mode 100644 index 0000000..ff304f7 --- /dev/null +++ b/97suifangqa/apps/utils/search_tools.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +""" +tools for haystack search +""" + +from haystack.query import SearchQuerySet + +import itertools + + +def objects_of_sqs(sqs): + """ + return the corresponding model set of the SearchQuerySet + """ + if isinstance(sqs, SearchQuerySet): + return itertools.imap(lambda x: x.object, sqs) + else: + return sqs + +def limit(seq, count=None): + """ + return the first 'count' items in 'seq' + if 'count=None', then all items returned + """ + return itertools.islice(seq, count) + + |