diff --git a/backend/src/buildSearchIndex.js b/backend/src/buildSearchIndex.js index 7efef7c9..9114e17b 100644 --- a/backend/src/buildSearchIndex.js +++ b/backend/src/buildSearchIndex.js @@ -10,16 +10,17 @@ class SearchIndexBuilder { this.startTime = null; } - // Parse verses from markdown content (same logic as BibleSearchEngine) + // Parse verses from markdown content (handles multi-line verses) parseVersesFromMarkdown(content, book, chapter, version) { const verses = []; const lines = content.split('\n'); + let currentVerse = null; - for (let i = 0; i < lines.length; i++) { - const line = lines[i].trim(); + for (const line of lines) { + const trimmedLine = line.trim(); // Skip empty lines and headers - if (!line || line.startsWith('#')) { + if (!trimmedLine || trimmedLine.startsWith('#')) { continue; } @@ -27,22 +28,35 @@ class SearchIndexBuilder { // - "1. In the beginning..." (numbered list format) // - "1 In the beginning..." (simple number format) // - "**1** In the beginning..." (bold number format) - const verseMatch = line.match(/^(\*\*)?(\d+)(\*\*)?[.\s]\s*(.+)$/); + const verseMatch = trimmedLine.match(/^(\*\*)?(\d+)(\*\*)?[.\s]\s*(.*)$/); if (verseMatch) { + // If a new verse is found, save the previous one + if (currentVerse) { + verses.push(currentVerse); + } + const verseNumber = parseInt(verseMatch[2]); const verseText = verseMatch[4]; - verses.push({ + currentVerse = { book, chapter, verse: verseNumber, text: verseText, version - }); + }; + } else if (currentVerse) { + // If it's a continuation of the current verse, append the text + currentVerse.text += ` ${trimmedLine}`; } } + // Add the last verse + if (currentVerse) { + verses.push(currentVerse); + } + return verses; }