diff options
author | Gio <sethg@ipi.org> | 2024-03-27 20:34:17 -0500 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-31 12:11:45 -0300 |
commit | a8005955e72998fffc50f5d1fc7ae55d42a4b945 (patch) | |
tree | 8e66b568ea74555a4ece02df5362f0701b79b63d | |
parent | 7f3a6ae47b3e9f7204e3e314d746f1b16661cbf4 (diff) |
search: remove document logic from mapper error handler
-rw-r--r-- | src/search.js | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/search.js b/src/search.js index 2f7718fd..b82a77b8 100644 --- a/src/search.js +++ b/src/search.js @@ -24,17 +24,11 @@ async function populateSearchIndexes(indexes, wikiData) { // Add a doc for mapper(thing) to index for each thing in collection. for (const thing of collection) { const reference = Thing.getReference(thing); + + // Get mapped fields from thing + let mappedResult; try { - const doc = { - reference, - ...mapper(thing) - }; - // Print description of output doc, if debugging enabled. - if (DEBUG_DOC_GEN && !haveLoggedDocOfThing[thing.constructor.name]) { - logInfo(JSON.stringify(doc, null, 2)); - haveLoggedDocOfThing[thing.constructor.name] = true; - } - index.add(doc); + mappedResult = mapper(thing); } catch (e) { // Enrich error context logError`Failed to write searchable doc for thing ${reference}`; @@ -45,6 +39,18 @@ async function populateSearchIndexes(indexes, wikiData) { logError("Availible properties: " + JSON.stringify(thingSchemaSummary, null, 2)); throw e; } + + // Build doc and add to index + const doc = { + reference, + ...mappedResult + } + // Print description of an output doc, if debugging enabled. + if (DEBUG_DOC_GEN && !haveLoggedDocOfThing[thing.constructor.name]) { + logInfo(JSON.stringify(doc, null, 2)); + haveLoggedDocOfThing[thing.constructor.name] = true; + } + index.add(doc); } } |