Skip to content

Instantly share code, notes, and snippets.

Created June 23, 2015 16:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chriskaukis/34f56a2c36d529429635 to your computer and use it in GitHub Desktop.
Super Simple Fuzzy Search
def is_fuzzy_match(text, query):
# Location of last match.
# Initialize to -1 since no match yet.
# -1 also works well for our usage.
l = -1
t = text.lower()
q = query.lower()
# Iterate over each character in the query.
for c in q:
if c == ' ':
# Check if the character in the query exists in the text.
l = t.find(c, l + 1)
if l == -1:
# No, that character doesn't exist at all.
return False
# If we make it through our check to see if all the characters exist in
# the correct order we can say fuzzily that the query matches that string.
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment