Permalink
Browse files

search-notes.py: Also match substrings of keywords

  • Loading branch information...
1 parent 10d6e24 commit 679f7854097a6fff2f91a4821aba5ce9a023bc9c @xolox committed Nov 24, 2011
Showing with 11 additions and 4 deletions.
  1. +11 −4 misc/notes/search-notes.py
View
@@ -154,12 +154,19 @@ def delete_note(self, filename):
def search_index(self, keywords):
''' Return names of files containing all of the given keywords. '''
matches = None
- for kw in keywords:
- filenames = self.index['keywords'].get(kw, [])
+ for usr_kw in keywords:
+ submatches = set()
+ for db_kw in self.index['keywords']:
+ # Yes I'm using a nested for loop over all keywords in the index. If
+ # I really have to I'll probably come up with something more
+ # efficient, but really it doesn't seem to be needed -- I have over
+ # 850 notes (about 8 MB) and 25000 keywords and it's plenty fast.
+ if usr_kw in db_kw:
+ submatches.update(self.index['keywords'][db_kw])
if matches is None:
- matches = set(filenames)
+ matches = submatches
else:
- matches &= set(filenames)
+ matches &= submatches
return list(matches) if matches else []
def list_keywords(self, substring, limit=25):

0 comments on commit 679f785

Please sign in to comment.