def score_query(self, query, k=3):
    scores = {}
    preprocessed_query = preprocess_text(query, tokens_only=True)
    for query_term in preprocessed_query:
        if (query_term in self.inverted_index.term_dictionary):
            term_frequencies = self.inverted_index.term_dictionary[query_term]
            for term_frequency in term_frequencies:
                if (term_frequency['document'] not in scores):
                    scores[term_frequency['document']] = 0
                scores[term_frequency['document']] += self.bm25_score(term_frequency['frequency'], len(term_frequency), term_frequency['document_length'])
    scores = dict(sorted(sorted(scores.items(), key=(lambda x: x[1]))))
    if (k > len(scores.keys())):
        k = len(scores.keys())
    return list(scores.keys())[:k]
def score_query(self, query, k=3):
    scores = {}
    preprocessed_query = preprocess_text(query, tokens_only=True)
    for query_term in preprocessed_query:
        if (query_term in self.inverted_index.term_dictionary):
            term_frequencies = self.inverted_index.term_dictionary[query_term]
            for term_frequency in term_frequencies:
                if (term_frequency['document'] not in scores):
                    scores[term_frequency['document']] = 0
                scores[term_frequency['document']] += self.bm25_score(term_frequency['frequency'], len(term_frequency), term_frequency['document_length'])
    scores = dict(sorted(sorted(scores.items(), key=(lambda x: x[1]))))
    if (k > len(scores.keys())):
        k = len(scores.keys())
    return list(scores.keys())[:k]