Merge pull request #5 from nmemmert/claude/test-coverage-analysis-R2olv
Fix Greek lookup returning "Lookup failed"
This commit is contained in:
+25
-16
@@ -855,26 +855,35 @@ const App = () => {
|
|||||||
const isHebrewStrongNumber = (query) => /^H\d+$/i.test(query.trim());
|
const isHebrewStrongNumber = (query) => /^H\d+$/i.test(query.trim());
|
||||||
|
|
||||||
const fetchBollsDefinition = async (query) => {
|
const fetchBollsDefinition = async (query) => {
|
||||||
const encoded = encodeURIComponent(query.trim());
|
const isGreek = isGreekStrongNumber(query);
|
||||||
const dictUrl = `https://bolls.life/dictionary-definition/BDBT/${encoded}/`;
|
const isHebrew = isHebrewStrongNumber(query);
|
||||||
|
|
||||||
// Direct Strong's number lookup (G prefix = Greek/Thayer's, H prefix = Hebrew/BDB)
|
if (isGreek || isHebrew) {
|
||||||
if (isGreekStrongNumber(query) || isHebrewStrongNumber(query)) {
|
// The bolls.life API uses bare numbers in the URL (no G/H prefix).
|
||||||
const response = await fetch(dictUrl);
|
// We filter returned results by topic prefix to get the right language.
|
||||||
|
const bare = query.trim().replace(/^[GgHh]/, '');
|
||||||
|
const response = await fetch(`https://bolls.life/dictionary-definition/BDBT/${encodeURIComponent(bare)}/`);
|
||||||
if (!response.ok) return null;
|
if (!response.ok) return null;
|
||||||
const definitions = await response.json();
|
let defs;
|
||||||
return Array.isArray(definitions) && definitions.length > 0 ? definitions : null;
|
try { defs = await response.json(); } catch { return null; }
|
||||||
|
if (!Array.isArray(defs) || defs.length === 0) return null;
|
||||||
|
const prefix = isGreek ? 'G' : 'H';
|
||||||
|
const filtered = defs.filter((d) => String(d.topic ?? '').toUpperCase().startsWith(prefix));
|
||||||
|
return filtered.length > 0 ? filtered : defs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// English word — full-text search, then filter to Greek entries only
|
// English word — full-text search, filter to Greek entries only
|
||||||
const searchResponse = await fetch(`https://bolls.life/search-dictionaries/BDBT/${encoded}/`);
|
const encoded = encodeURIComponent(query.trim());
|
||||||
if (searchResponse.ok) {
|
try {
|
||||||
const results = await searchResponse.json();
|
const searchResponse = await fetch(`https://bolls.life/search-dictionaries/BDBT/${encoded}/`);
|
||||||
const greekResults = Array.isArray(results)
|
if (searchResponse.ok) {
|
||||||
? results.filter((r) => String(r.topic ?? '').startsWith('G'))
|
const results = await searchResponse.json();
|
||||||
: [];
|
const greekResults = Array.isArray(results)
|
||||||
if (greekResults.length > 0) return [greekResults[0]];
|
? results.filter((r) => String(r.topic ?? '').startsWith('G'))
|
||||||
}
|
: [];
|
||||||
|
if (greekResults.length > 0) return [greekResults[0]];
|
||||||
|
}
|
||||||
|
} catch { /* fall through */ }
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user