Skip to content

Instantly share code, notes, and snippets.

@Ignas
Last active August 29, 2015 14:03
Show Gist options
  • Save Ignas/0d94ea2d63f3d52cef30 to your computer and use it in GitHub Desktop.
Save Ignas/0d94ea2d63f3d52cef30 to your computer and use it in GitHub Desktop.
indices = [candidate.index(/\b#{this_query_char}/),
candidate.index(this_query_char)]
scores = [1, indices[1] + 1]
indices.zip(scores).map { |index, score_delta|
if index
candidate_remainder = candidate[(index + 1)..-1]
score = score_substring(candidate_remainder, query_remainder)
if score
score + score_delta
end
end
}.compact.min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment