diff --git a/app.py b/app.py index af917e5..f812c69 100644 --- a/app.py +++ b/app.py @@ -774,9 +774,46 @@ def search(): results = lookup_fts(cleaned_keywords) if not results: h = hunspell.HunSpell("data/kjv.dic", "data/kjv.aff") + + # Split query into words and correct each one + words = cleaned_keywords.split() + corrected_words = [] + had_corrections = False + + for word in words: + if h.spell(word): + # Word is spelled correctly + corrected_words.append(word) + else: + # Word is misspelled, get suggestions + word_suggestions = h.suggest(word) + if word_suggestions: + corrected_words.append(word_suggestions[0]) + had_corrections = True + else: + # No suggestions, keep original + corrected_words.append(word) + + if had_corrections: + corrected_keyword = " ".join(corrected_words) + results = lookup_fts(corrected_keyword) + if results: + # Prepend correction notice to results + response_list = scripture_response(results) + correction_notice = f"