From b9ca04f9e93d40f7a03477c3d6b7650ec3350421 Mon Sep 17 00:00:00 2001 From: Cris Stringfellow <22254235+crislin2046@users.noreply.github.com> Date: Thu, 16 Dec 2021 13:57:29 +0800 Subject: [PATCH] "Added ability to export flexsearch FTS data" --- archivist.js | 20 +++++++++----------- args.js | 6 ++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/archivist.js b/archivist.js index 07269bf..1299797 100644 --- a/archivist.js +++ b/archivist.js @@ -81,7 +81,6 @@ const UNCACHED = { body:UNCACHED_BODY, responseCode:UNCACHED_CODE, responseHeaders:UNCACHED_HEADERS } - export default Archivist; async function collect({chrome_port:port, mode} = {}) { @@ -284,13 +283,14 @@ async function collect({chrome_port:port, mode} = {}) { } async function indexURL({targetInfo:info = {}, sessionId, waitingForDebugger} = {}) { - console.log('Index URL called', info); if ( Mode == 'serve' ) return; if ( info.type != 'page' ) return; if ( ! info.url || info.url == 'about:blank' ) return; if ( info.url.startsWith('chrome') ) return; if ( dontCache(info) ) return; + console.log('Index URL called', info); + if ( State.Indexing.has(info.targetId) ) return; State.Indexing.add(info.targetId); @@ -670,31 +670,29 @@ async function saveFTS(path) { clearTimeout(State.ftsIndexSaver); - const DEBUG = true; if ( context == 'node' ) { DEBUG && console.log("Writing FTS index to", path || FTS_INDEX_DIR()); const dir = path || FTS_INDEX_DIR(); if ( UpdatedKeys.size ) { - let writeCount = 0; + DEBUG && console.log(`${UpdatedKeys.size} keys updated since last write`); Flex.export((key, data) => { - if ( UpdatedKeys.has(key) ) { + try { Fs.writeFileSync( - /* haha .flx file extensionf or flexsearch index date file */ - Path.resolve(dir, `${hash(key, HASH_OPTS)}.flx`), + Path.resolve(dir, key), data ); - UpdatedKeys.delete(key); - writeCount++; + } catch(e) { + console.error('Error writing full text search index', e); } }); - DEBUG && console.log("Wrote FTS index: ", writeCount, "files"); + UpdatedKeys.clear(); } else { DEBUG && console.log("No FTS keys updated, no writes needed this time."); } } - State.ftsIndexSaver = setTimeout(saveIndex, 31001); + State.ftsIndexSaver = setTimeout(saveFTS, 31001); State.ftsSaveInProgress = false; } diff --git a/args.js b/args.js index 70221e5..859e1b8 100644 --- a/args.js +++ b/args.js @@ -71,6 +71,12 @@ function updateBasePath(new_base_path) { console.log(`Created!`); } + if ( !fs.existsSync(fts_index_dir()) ) { + console.log(`FTS Index directory does not exist, creating...`); + fs.mkdirSync(fts_index_dir(), {recursive:true}); + console.log(`Created!`); + } + console.log(`Base path updated to: ${BasePath}. Saving to preferences...`); Pref.BasePath = BasePath; savePref();