Skip to content

Commit

Permalink
fix 'coffe' autocorrect to 'coffee' bug
Browse files Browse the repository at this point in the history
  • Loading branch information
capjamesg committed Nov 18, 2024
1 parent f529624 commit 8840005
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion jamesql/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,22 @@ def autosuggest(self, query: str, match_full_record=False, limit=5) -> List[str]
continue
results.append(i)

# get word counts of each
wcs = {word: self.word_counts[word] for word in results}

# order by wc in descending order
results = sorted(wcs, key=wcs.get, reverse=True)

return results[0:limit]
else:
try:
return self.autosuggest_index.keys(prefix=query.lower())[0:limit]
candidates = self.autosuggest_index.keys(prefix=query.lower())[0:limit]

wcs = {word: self.word_counts[word] for word in candidates}

candidates = sorted(wcs, key=wcs.get, reverse=True)

return candidates
except KeyError:
return []

Expand Down

0 comments on commit 8840005

Please sign in to comment.