From e25bf087206a5a27016ebc2469a874ecc0cd1ebc Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 22 Nov 2025 08:21:39 -0500 Subject: [PATCH] Add comprehensive Bible concordance feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Concordance System: - Complete word occurrence index for entire KJV Bible - Shows all instances of any searched word with full context - Case-insensitive exact word matching with word boundaries - Results organized by biblical book for easy navigation - Each occurrence links directly to the verse Features: - Search any word to find all occurrences (e.g., "love" appears ~300 times) - Highlighted word in context for quick identification - Statistics showing total occurrences and books containing the word - Popular word suggestions (love, faith, LORD, God, Jesus, grace, etc.) - Grouped by book with occurrence counts per book - Full verse context provided for each occurrence - Mobile-responsive design UI Design: - Clean, Tufte CSS-styled interface - Popular concordance lookups grid - Usage tips for KJV-specific spellings - Search box prominently featured - Stats showing word frequency and distribution Implementation: - Route: /concordance with ?word= parameter - Word boundary regex matching for accuracy - Real-time highlighting of matched words - Complete Bible text scanning - Organized output by biblical book order Integration: - Added to homepage navigation under "Concordance and Search" - Standalone page with comprehensive instructions - Links from every occurrence to full verse pages Usage Notes: - Exact word matching (won't find inflected forms) - Case-insensitive search - Handles KJV archaic forms (loveth, cometh, etc.) - Proper nouns supported (Jesus, Moses, David) - Theological terms supported (justification, redemption) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- kjvstudy_org/server.py | 75 ++++++ kjvstudy_org/templates/concordance.html | 306 ++++++++++++++++++++++++ kjvstudy_org/templates/index.html | 2 +- 3 files changed, 382 insertions(+), 1 deletion(-) create mode 100644 kjvstudy_org/templates/concordance.html diff --git a/kjvstudy_org/server.py b/kjvstudy_org/server.py index f6d776e..87d46b4 100644 --- a/kjvstudy_org/server.py +++ b/kjvstudy_org/server.py @@ -493,6 +493,81 @@ def search_api(q: str = Query(..., description="Search query"), limit: Optional[ "is_direct_verse": is_direct_verse } + +@app.get("/concordance", response_class=HTMLResponse) +def concordance_page(request: Request, word: str = Query(None, description="Word to look up")): + """Concordance page showing all occurrences of a word""" + books = list(bible.iter_books()) + + if not word or len(word.strip()) < 2: + return templates.TemplateResponse( + "concordance.html", + { + "request": request, + "books": books, + "word": word or "", + "total_occurrences": 0, + "occurrences_by_book": {}, + "books_with_word": [] + } + ) + + search_word = word.strip() + occurrences = [] + occurrences_by_book = {} + books_with_word = set() + + # Search through all verses + import re + # Create a word boundary pattern for exact word matching + # This handles punctuation and word boundaries properly + pattern = re.compile(r'\b' + re.escape(search_word) + r'\b', re.IGNORECASE) + + for book in bible.iter_books(): + book_name = book.name + book_occurrences = [] + + for chapter_num in range(1, book.num_chapters + 1): + chapter = book.chapter(chapter_num) + + for verse in chapter.verses: + # Check if the word appears in this verse + if pattern.search(verse.text): + # Highlight the word in the text + highlighted_text = pattern.sub( + lambda m: f'{m.group()}', + verse.text + ) + + occurrence = { + 'book': book_name, + 'chapter': chapter_num, + 'verse': verse.verse, + 'text': verse.text, + 'highlighted_text': highlighted_text + } + + occurrences.append(occurrence) + book_occurrences.append(occurrence) + books_with_word.add(book_name) + + # Only add to occurrences_by_book if there are occurrences in this book + if book_occurrences: + occurrences_by_book[book_name] = book_occurrences + + return templates.TemplateResponse( + "concordance.html", + { + "request": request, + "books": books, + "word": search_word, + "total_occurrences": len(occurrences), + "occurrences_by_book": occurrences_by_book, + "books_with_word": sorted(books_with_word) + } + ) + + def parse_verse_reference(reference: str): """Parse a verse reference and return a URL for it. diff --git a/kjvstudy_org/templates/concordance.html b/kjvstudy_org/templates/concordance.html new file mode 100644 index 0000000..7712166 --- /dev/null +++ b/kjvstudy_org/templates/concordance.html @@ -0,0 +1,306 @@ +{% extends "base.html" %} + +{% block title %}{% if word %}Concordance: "{{ word }}" - {{ total_occurrences }} occurrences{% else %}Bible Concordance{% endif %} - KJV Study{% endblock %} +{% block description %}{% if word %}Complete concordance showing all {{ total_occurrences }} occurrences of "{{ word }}" in the King James Bible with context.{% else %}Search the complete KJV Bible concordance to find every occurrence of any word.{% endif %}{% endblock %} + +{% block head %} + +{% endblock %} + +{% block content %} +

Bible Concordance

+

Find every occurrence of any word in the King James Bible

+ +
+ + + {% if word %} + {% if total_occurrences > 0 %} +
+

The word "{{ word }}" appears {{ total_occurrences }} time{{ 's' if total_occurrences != 1 else '' }} in the King James Bible

+ {% if books_with_word %} +

Found in {{ books_with_word|length }} book{{ 's' if books_with_word|length != 1 else '' }}: {{ books_with_word|join(', ') }}

+ {% endif %} +
+ + {% if occurrences_by_book %} + {% for book_name, book_occurrences in occurrences_by_book.items() %} +
+

{{ book_name }} ({{ book_occurrences|length }} occurrence{{ 's' if book_occurrences|length != 1 else '' }})

+ +
+ {% for occurrence in book_occurrences %} +
+ +
{{ occurrence.highlighted_text | safe }}
+
+ {% endfor %} +
+
+ {% endfor %} + {% endif %} + {% else %} +
+

No occurrences found for "{{ word }}". Try a different word or check your spelling.

+

Note: The KJV uses older English spellings. Try words like "loveth" instead of "loves", "cometh" instead of "comes".

+
+ {% endif %} + {% endif %} + + {% if not word or total_occurrences == 0 %} + + +
+

Using the Concordance

+
    +
  • Case-insensitive - Search for "Love", "love", or "LOVE" - all work the same
  • +
  • Exact matches only - Searches for the exact word form (e.g., "love" won't find "loved" or "loveth")
  • +
  • Old English forms - The KJV uses archaic verb forms like "cometh", "goeth", "loveth"
  • +
  • Proper nouns - Search for names like "Jesus", "Moses", "David" to track their appearances
  • +
  • Theological terms - Look up "justification", "sanctification", "redemption", etc.
  • +
  • Context provided - Each occurrence shows the full verse for context
  • +
  • Organized by book - Results grouped by biblical book for easy navigation
  • +
+
+ {% endif %} +
+{% endblock %} diff --git a/kjvstudy_org/templates/index.html b/kjvstudy_org/templates/index.html index 45655c4..2645c57 100644 --- a/kjvstudy_org/templates/index.html +++ b/kjvstudy_org/templates/index.html @@ -522,7 +522,7 @@ document.addEventListener('keydown', function(e) {

Reading Plans — Structured Bible reading schedules for systematic Scripture study, including chronological, thematic, and testament-specific plans to guide sustained engagement with God's Word.

-

Concordance and Search — A comprehensive search facility allowing the reader to trace any word or phrase throughout the entire corpus of Scripture, after the manner of Cruden's Complete Concordance.

+

Concordance and Search — A comprehensive concordance showing every occurrence of any word in Scripture, and a search facility allowing the reader to trace any word or phrase throughout the entire corpus of Scripture, after the manner of Cruden's Complete Concordance.

Biblical Geography — Maps and descriptions of those places mentioned in Holy Writ, from the rivers of Babylon to the shores of Galilee, illuminating the geographical context of sacred history.