core.utils.bible_keyword_searcher
- File:
EuljiroWorship/core/utils/bible_keyword_searcher.py
- Author:
Benjamin Jaedon Choi - https://github.com/saintbenjamin
- Affiliated Church:
The Eulji-ro Presbyterian Church [대한예수교장로회(통합) 을지로교회]
- Address:
The Eulji-ro Presbyterian Church, 24-10, Eulji-ro 20-gil, Jung-gu, Seoul 04549, South Korea
- Telephone:
+82-2-2266-3070
- E-mail:
euljirochurch [at] G.M.A.I.L. (replace [at] with @ and G.M.A.I.L as you understood.)
- License:
MIT License with Attribution Requirement (see LICENSE file for details); Copyright (c) 2025 The Eulji-ro Presbyterian Church.
Performs keyword-based search on Bible text files for EuljiroBible/EuljiroWorship.
This module provides lightweight, in-memory keyword search functionality over a single Bible version JSON file. It is designed for fast interactive search in both CLI and GUI contexts.
Supported search modes include:
Word-based AND search
Whitespace-insensitive (compact) substring search
Search results include both raw verse text and HTML-highlighted text for immediate display use.
- class core.utils.bible_keyword_searcher.BibleKeywordSearcher(version='개역개정')[source]
Bases:
objectKeyword-based Bible verse search engine.
This class loads a single Bible version into memory and provides multiple keyword-based search strategies over verse text, including word-based AND search and whitespace-insensitive (compact) substring search.
Search results are returned as structured dictionaries containing verse location metadata and both raw and highlighted text, making them suitable for direct rendering in GUI table models, delegates, or CLI output.
- Parameters:
version (str)
- version
Bible version key currently loaded (e.g., “개역개정”, “NKRV”). This corresponds to the JSON filename without extension.
- Type:
str
- data
Parsed Bible text data loaded from
<version>.json. Structure is typically:data[book][chapter][verse] = verse_text.- Type:
dict
- name_map
Parsed content of
standard_book.json. Used to resolve canonical or localized book names when needed by UI or higher-level logic.- Type:
dict
Note
The Bible data for the selected version is fully loaded at initialization time (not lazily).
Highlighting is performed using simple HTML
<span>tags, assuming downstream renderers support HTML (e.g., QTextDocument).This class is used by both GUI (TabKeyword) and CLI search paths.
- __init__(version='개역개정')[source]
Initialize the keyword searcher with a specific Bible version.
The corresponding Bible JSON file is loaded into memory at initialization time.
- Parameters:
version (str) – Bible version name without file extension (e.g., “개역개정”, “NKRV”).
- Returns:
None
- Raises:
FileNotFoundError – If the specified Bible version file does not exist.
- search_compact_string(keyword, limit=100)[source]
Perform whitespace-insensitive substring search.
All whitespace is removed from both the keyword and verse text before matching, allowing detection of continuous phrases regardless of spacing differences.
- Parameters:
keyword (str) – Input search string.
limit (int, optional) – Maximum number of results to return. Defaults to 100.
- Returns:
List of matching verse dictionaries, each containing: - book - chapter - verse - text - highlighted
- Return type:
list[dict]
- search_wordwise_and(keyword, limit=100)[source]
Perform word-based AND search.
All whitespace-separated words in the keyword must appear somewhere in the verse text for a match to occur.
- Parameters:
keyword (str) – Space-separated search terms.
limit (int, optional) – Maximum number of results to return. Defaults to 100.
- Returns:
List of matching verse dictionaries with highlighted terms.
- Return type:
list[dict]
- search(keyword, limit=100, mode='and')[source]
Unified keyword search interface.
This method dispatches to the appropriate search strategy based on the selected mode.
- Parameters:
keyword (str) – Input keyword or phrase.
limit (int, optional) – Maximum number of results to return.
mode (str, optional) – Search mode selector. - “and”: word-based AND search (default) - “compact”: whitespace-insensitive substring search
- Returns:
Search result list.
- Return type:
list[dict]
- count_keywords(results, keywords)[source]
Count total occurrences of each keyword across search results.
This method performs full regex-based counting (case-insensitive) over the raw verse text of each search result.
- Parameters:
results (list[dict]) – List of verse dictionaries returned from a search.
keywords (list[str]) – List of keywords to count.
- Returns:
Mapping of keyword -> total occurrence count.
- Return type:
dict[str, int]