diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-05-13 09:02:11 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-31 12:11:52 -0300 |
commit | 5038549631b0413552fe6589e7c77f66e53e7bcd (patch) | |
tree | c0a5d8cece358918e12be5c0a504f409ccf0b45f /src/util | |
parent | b6d09fa09a731f21cb35861715cf076f49460e28 (diff) |
upd8, search: pass urls & thumbs utils into search spec process
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/search-spec.js | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/util/search-spec.js b/src/util/search-spec.js index 08717d92..92ed4dec 100644 --- a/src/util/search-spec.js +++ b/src/util/search-spec.js @@ -222,7 +222,34 @@ export function makeSearchIndex(descriptor, {FlexSearch}) { }); } -export function populateSearchIndex(index, descriptor, {wikiData}) { +// TODO: This function basically mirrors bind-utilities.js, which isn't +// exactly robust, but... binding might need some more thought across the +// codebase in *general.* +function bindSearchUtilities({ + checkIfImagePathHasCachedThumbnails, + getThumbnailEqualOrSmaller, + thumbsCache, + urls, +}) { + const bound = { + urls, + }; + + bound.checkIfImagePathHasCachedThumbnails = + (imagePath) => + checkIfImagePathHasCachedThumbnails(imagePath, thumbsCache); + + bound.getThumbnailEqualOrSmaller = + (preferred, imagePath) => + getThumbnailEqualOrSmaller(preferred, imagePath, thumbsCache); + + return bound; +} + +export function populateSearchIndex(index, descriptor, opts) { + const {wikiData} = opts; + const bound = bindSearchUtilities(opts); + const collection = descriptor.query(wikiData); for (const thing of collection) { @@ -230,7 +257,7 @@ export function populateSearchIndex(index, descriptor, {wikiData}) { let processed; try { - processed = descriptor.process(thing); + processed = descriptor.process(thing, bound); } catch (caughtError) { throw new Error( `Failed to process searchable thing ${reference}`, |