1
0
mirror of https://github.com/c9fe/22120.git synced 2024-11-13 22:42:34 +01:00
This commit is contained in:
Cris Stringfellow 2021-12-19 16:45:07 +08:00
parent de3633a7c7
commit dec0d8bd6a
2 changed files with 9 additions and 7 deletions

View File

@ -43,6 +43,7 @@
const USE_FLEX = true;
const FTS_INDEX_DIR = args.fts_index_dir;
const NDX_FTS_INDEX_DIR = args.ndx_fts_index_dir;
const URI_SPLIT = /[\/.]/g;
// natural (NLP tools -- stemmers and tokenizers, etc)
const Tokenizer = new Nat.WordTokenizer();
@ -55,15 +56,17 @@
// FlexSearch
const {Index: FTSIndex, registerCharset, registerLanguage} = FlexSearch;
const FLEX_OPTS = {
charset: "utf8",
context: true,
language: "en",
tokenize: s => words(s).map(w => termFilter(w))
tokenize: "reverse"
};
const Flex = new FTSIndex(FLEX_OPTS);
DEBUG && console.log({Flex});
// NDX
let Id;
const NDXRemoved = new Set();
const REMOVED_CAP_TO_VACUUM_NDX = 10;
const NDX_FIELDS = ndxDocFields();
const NDX_FTSIndex = new NDXIndex(NDX_FIELDS);
@ -81,7 +84,6 @@
const UpdatedKeys = new Set();
const Cache = new Map();
const Index = new Map();
const NDX_Removed = new Set();
const Indexing = new Set();
const State = {
Indexing,
@ -393,8 +395,8 @@ export default Archivist;
State.Index.set(url, {id:doc.id, title});
State.Index.set(doc.id, url);
//Old Flex code
Flex.update(doc.id, doc.title + ' ' + doc.content);
//Flex code
Flex.update(doc.id, doc.title + ' ' + doc.content + ' ' + doc.url.split(URI_SPLIT).join(' '));
//New NDX code
const res = NDX_FTSIndex.add(doc);
@ -989,7 +991,8 @@ export default Archivist;
id = id || Id++;
return {
id,
url, title,
url: url.split(URI_SPLIT).join(' '),
title,
content: pageText
};
}

View File

@ -103,7 +103,6 @@ function addHandlers() {
const change = args.updateBasePath(base_path);
if ( change ) {
res.send(`Changing base path. See the console for progress.`);
await Archivist.handlePathChanged();
Server.close(async () => {
running = false;
@ -113,7 +112,7 @@ function addHandlers() {
start({server_port:port});
console.log(`Server restarting.`);
});
res.end(`Base path set to ${base_path} and saved to preferences. Server restarting...`);
res.end(`Base path set to ${base_path} and saved to preferences. See console for progress. Server restarting...`);
} else {
res.end(`Base path not changed.`);
}