Skip to content

Commit

Permalink
Allow duplicate items in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jul 23, 2014
1 parent 6dfb3e0 commit 5a22c11
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Binary file modified alfred-workflow.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ def test_filter_empty_query_words(self):
results = self.wf.filter(' ', data)
self.assertEquals(len(results), 0)

def test_filter_identical_items(self):
"""Filter: identical items are not discarded"""
data = ['bob', 'bob', 'bob']
results = self.wf.filter('bob', data)
self.assertEquals(len(results), len(data))

def test_icons(self):
"""Icons"""
import workflow
Expand Down
2 changes: 1 addition & 1 deletion workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def main(wf):
"""

__version__ = '1.6.1'
__version__ = '1.6.2'

from .workflow import Workflow, PasswordNotFound, KeychainError
from .workflow import (ICON_ERROR, ICON_WARNING, ICON_NOTE, ICON_INFO,
Expand Down
10 changes: 5 additions & 5 deletions workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ def filter(self, query, items, key=lambda x: x, ascending=False,
fold_diacritics = self.settings.get('__workflows_diacritic_folding',
fold_diacritics)

results = {}
results = []

for i, item in enumerate(items):
skip = False
Expand All @@ -1117,12 +1117,12 @@ def filter(self, query, items, key=lambda x: x, ascending=False,
# use "reversed" `score` (i.e. highest becomes lowest) and
# `value` as sort key. This means items with the same score
# will be sorted in alphabetical not reverse alphabetical order
results[(100.0 / score, value.lower(), score)] = (item, score,
r)
results.append(((100.0 / score, value.lower(), score),
(item, score, r)))

# sort on keys, then discard the keys
keys = sorted(results.keys(), reverse=ascending)
results = [results.get(k) for k in keys]
results.sort(reverse=True)
results = [t[1] for t in results]

if max_results and len(results) > max_results:
results = results[:max_results]
Expand Down

0 comments on commit 5a22c11

Please sign in to comment.