Total Complexity | 6 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | from functools import reduce |
||
9 | class SimpleSearch(BaseSearch): |
||
10 | """ Simple ORM based search """ |
||
11 | |||
12 | def add(self, object): |
||
13 | """ Not implemented in this backend """ |
||
14 | |||
15 | def remove(self, object): |
||
16 | """ Not implemented in this backend """ |
||
17 | |||
18 | def search(self, query_string): |
||
19 | """ Search all thread instances for the given query string """ |
||
20 | threads = models.Thread.objects.filter( |
||
21 | reduce( |
||
22 | lambda q, f: q & Q(title__icontains=f), |
||
23 | query_string.split(), |
||
24 | Q())) |
||
25 | |||
26 | result_set = SearchResultSet() |
||
27 | for thread in threads: |
||
28 | result_set.add(thread) |
||
29 | |||
30 | return result_set |
||
31 | |||
32 | def wipe(self): |
||
33 | """ Not implemented in this backend """ |
||
34 |