Skip to content

Commit 9dee37d

Browse files
committed
Improve example and sorting of docs for token
1 parent 5522ae7 commit 9dee37d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Diff for: example_1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
my_index = index.Index()
44

5-
my_index.index('1', 'hello, my world! going to work :(')
5+
my_index.index('1', 'hello, my world! going to work world! :(')
66
my_index.index('2', 'bye bye world, going to sleep :)')
7-
print(my_index)
7+
print(my_index.get_docs_for_token('world'))

Diff for: index/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import operator
12
import pickle
23

34
from nltk.tokenize import RegexpTokenizer
@@ -73,6 +74,6 @@ def from_file(filename):
7374

7475
def get_docs_for_token(self, token, count=None):
7576
docs = self._inverted_index[token]['frequency']
76-
sorted_docs = sorted(docs.items(), key=lambda k, v: (v, k))
77+
sorted_docs = sorted(docs.items(), key=operator.itemgetter(1), reverse=True)
7778
doc_list = list(sorted_docs)
7879
return doc_list if count is None else doc_list[:count]

0 commit comments

Comments
 (0)