GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SearchResultSet.__getitem__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 2
rs 10
cc 1
1
from simple_forums.utils import get_setting, string_to_class
2
3
4
def get_search_class():
5
    """ Get the search backend class """
6
    backend_info = get_setting('search_backend', {})
7
8
    return string_to_class(
9
        backend_info.get(
10
            'search_class',
11
            'simple_forums.backends.search.SimpleSearch'))
12
13
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
36
37
# Make module classes easily accessible
38
from simple_forums.backends.search.base_search import BaseSearch        # noqa
39
from simple_forums.backends.search.elastic_search import ElasticSearch  # noqa
40
from simple_forums.backends.search.simple_search import SimpleSearch    # noqa
41