"Search with ndx seems good enough for now"

This commit is contained in:
Cris Stringfellow 2021-12-18 14:47:03 +08:00
parent 5f9a536119
commit a81a29b936
2 changed files with 12 additions and 12 deletions

View File

@ -55,6 +55,7 @@
let Id; let Id;
const NDX_FIELDS = ndxDocFields(); const NDX_FIELDS = ndxDocFields();
const NDX_FTSIndex = new NDXIndex(NDX_FIELDS); const NDX_FTSIndex = new NDXIndex(NDX_FIELDS);
console.log(NDX_FTSIndex);
// module state: constants and variables // module state: constants and variables
// cache is a simple map // cache is a simple map
@ -239,11 +240,11 @@ export default Archivist;
async function reindexOnTitleChange({titleChange}) { async function reindexOnTitleChange({titleChange}) {
const {currentTitle, url, sessionId} = titleChange; const {currentTitle, url, sessionId} = titleChange;
console.log('Received titleChange', titleChange); DEBUG && console.log('Received titleChange', titleChange);
const latestTargetInfo = clone(await untilHas(Targets, sessionId)); const latestTargetInfo = clone(await untilHas(Targets, sessionId));
latestTargetInfo.title = currentTitle; latestTargetInfo.title = currentTitle;
Targets.set(sessionId, latestTargetInfo); Targets.set(sessionId, latestTargetInfo);
console.log('Updated stored target info', latestTargetInfo); DEBUG && console.log('Updated stored target info', latestTargetInfo);
indexURL({targetInfo:latestTargetInfo}); indexURL({targetInfo:latestTargetInfo});
} }
@ -256,15 +257,15 @@ export default Archivist;
function updateTargetInfo({targetInfo}) { function updateTargetInfo({targetInfo}) {
if ( targetInfo.type === 'page' ) { if ( targetInfo.type === 'page' ) {
const sessionId = Sessions.get(targetInfo.targetId); const sessionId = Sessions.get(targetInfo.targetId);
console.log('Updating target info', targetInfo, sessionId); DEBUG && console.log('Updating target info', targetInfo, sessionId);
if ( sessionId ) { if ( sessionId ) {
const existingTargetInfo = Targets.get(sessionId); const existingTargetInfo = Targets.get(sessionId);
// if we have an existing target info for this URL and have saved an updated title // if we have an existing target info for this URL and have saved an updated title
console.log('Existing target info', existingTargetInfo); DEBUG && console.log('Existing target info', existingTargetInfo);
if ( existingTargetInfo && existingTargetInfo.url === targetInfo.url ) { if ( existingTargetInfo && existingTargetInfo.url === targetInfo.url ) {
// keep that title (because targetInfo does not reflect the latest title) // keep that title (because targetInfo does not reflect the latest title)
if ( existingTargetInfo.title !== existingTargetInfo.url ) { if ( existingTargetInfo.title !== existingTargetInfo.url ) {
console.log('Setting title to existing', existingTargetInfo); DEBUG && console.log('Setting title to existing', existingTargetInfo);
targetInfo.title = existingTargetInfo.title; targetInfo.title = existingTargetInfo.title;
} }
} }
@ -378,7 +379,7 @@ export default Archivist;
const res = NDX_FTSIndex.add(doc); const res = NDX_FTSIndex.add(doc);
UpdatedKeys.add(info.url); UpdatedKeys.add(info.url);
console.log({title, url, indexed: true, searchable: true, indexType: 'full text and full content', res, doc}); console.log({id: doc.id, title, url, indexed: true});
State.Indexing.delete(info.targetId); State.Indexing.delete(info.targetId);
} }
@ -669,7 +670,7 @@ export default Archivist;
const url = State.Index.get(id); const url = State.Index.get(id);
console.log(id, url); console.log(id, url);
const {title} = State.Index.get(url); const {title} = State.Index.get(url);
return {url, title}; return {url, title, id};
} }
function handlePathChanged() { function handlePathChanged() {
@ -854,7 +855,6 @@ export default Archivist;
} }
function loadNDXIndex(ndxFTSIndex) { function loadNDXIndex(ndxFTSIndex) {
const DEBUG = true;
try { try {
const indexContent = Fs.readFileSync( const indexContent = Fs.readFileSync(
Path.resolve(NDX_FTS_INDEX_DIR(), 'index.ndx'), Path.resolve(NDX_FTS_INDEX_DIR(), 'index.ndx'),

View File

@ -184,9 +184,9 @@ function IndexView(urls) {
</form> </form>
<ul> <ul>
${ ${
urls.map(([url,{title}]) => ` urls.map(([url,{title, id}]) => `
<li> <li>
<a target=_blank href=${url}>${title||url}</a> ${DEBUG ? id + ':' : ''} <a target=_blank href=${url}>${title||url}</a>
</li> </li>
`).join('\n') `).join('\n')
} }
@ -247,9 +247,9 @@ function SearchResultView({results, query}) {
</p> </p>
<ol> <ol>
${ ${
results.map(({url,title}) => ` results.map(({url,title,id}) => `
<li> <li>
<a target=_blank href=${url}>${title||url}</a> ${DEBUG ? id + ':' : ''}: <a target=_blank href=${url}>${title||url}</a>
</li> </li>
`).join('\n') `).join('\n')
} }