Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion recent_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ def create_json(projects):
AlfredOutput([AlfredItem(project.name, project.path, project.path) for project in projects]))


def match_fuzzy(chars, string):
index = 0
for char in chars:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after having a second look at this, I believe this algorithm is too permissive. For example, it would find my-awesome-project by querying with ywp. I'd like to keep matching by first letters of each word in the name

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alswl this comment is still not addressed I believe

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alswl tagging you in the pending comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the search algorithm is by design. Maybe I can make it more strict: only match the left letters of eatch word. For eg: my-awesome-projct will matching the patterns:

  • map -> yes
  • myawp -> yes
  • mawpr -> yes
  • awp -> yes
  • mwr -> no
  • ywp -> no

What's your opinion?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what I had in mind, yes! Please make sure to extend the unit tests to cover these new cases

if char not in string[index:]:
return False
index = string.index(char, index) + 1
return True


class Project:
def __init__(self, path):
self.path = os.path.expanduser(path)
Expand Down Expand Up @@ -60,7 +69,8 @@ def abbreviate(self):
return abbreviation

def matches_query(self, query):
return query in self.path.lower() or query in self.abbreviation.lower() or query in self.name.lower()
splits = filter(lambda x: x.strip() != '', query)
return match_fuzzy(splits, self.name.lower())

def sort_on_match_type(self, query):
if query == self.abbreviation:
Expand Down