Total Complexity | 6 |
Total Lines | 21 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from simple_forums.utils import get_setting, string_to_class |
||
14 | class SearchResultSet: |
||
15 | """ Contains objects that are the results of a search """ |
||
16 | |||
17 | def __init__(self): |
||
18 | """ Create blank list of results """ |
||
19 | self.results = [] |
||
20 | |||
21 | def __getitem__(self, key): |
||
22 | return self.results[key] |
||
23 | |||
24 | def __iter__(self): |
||
25 | """ Iterate over results """ |
||
26 | return iter(self.results) |
||
27 | |||
28 | def add(self, obj, score=0): |
||
29 | """ Add the given object to the result set """ |
||
30 | self.results.append((obj, score)) |
||
31 | |||
32 | def get_sorted(self): |
||
33 | """ Get the result set ordered by score, descending """ |
||
34 | return sorted(self.results, key=lambda item: item[1], reverse=True) |
||
35 | |||
41 |