-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_docs.py
31 lines (21 loc) · 895 Bytes
/
sort_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Sorts:
def __init__(self, indexer, ):
self.indexer = indexer
def sort_by_time(self, relevant_docs):
time_relevant_dict = {}
for doc in relevant_docs:
info_doc = self.indexer.docs_dict[doc]
time_relevant_dict[doc] = info_doc[2]
sorted_doc = sorted(time_relevant_dict.items(), key=lambda item: item[1], reverse=True)
return sorted_doc
def sort_by_pop(self,relevant_docs):
pop_relevant_dict = {}
for doc in relevant_docs:
pop_dict = self.indexer.pop_dict
if doc in pop_dict.keys():
pop_doc = self.indexer.pop_dict[doc]
pop_relevant_dict[doc] = pop_doc
else:
pop_relevant_dict[doc] = 0
sorted_doc = sorted(pop_relevant_dict.items(), key=lambda item: item[1], reverse=True)
return sorted_doc