diff --git a/archivist.js b/archivist.js index acebe00..61b9e7b 100644 --- a/archivist.js +++ b/archivist.js @@ -90,7 +90,7 @@ }; const HIGHLIGHT_OPTIONS_FUZZY = { - minimum_match: 3.0 + minimum_match: 2.0 }; const FUZZ_OPTS = { keys: ndxDocFields({namesOnly:true}) @@ -721,6 +721,7 @@ export default Archivist; try { State.Cache = new Map(JSON.parse(Fs.readFileSync(cacheFile))); } catch(e) { + console.warn(e+''); State.Cache = new Map(); someError = true; } @@ -728,6 +729,7 @@ export default Archivist; try { State.Index = new Map(JSON.parse(Fs.readFileSync(indexFile))); } catch(e) { + console.warn(e+''); State.Index = new Map(); someError = true; } @@ -742,18 +744,21 @@ export default Archivist; }); DEBUG && console.log('Flex loaded'); } catch(e) { + console.warn(e+''); someError = true; } try { loadNDXIndex(NDX_FTSIndex); } catch(e) { + console.warn(e+''); someError = true; } try { loadFuzzy(); } catch(e) { + console.warn(e+''); someError = true; } @@ -807,7 +812,7 @@ export default Archivist; } Id = Math.round(State.Index.size / 2) + 3; - NDXId = State.Index.has(NDX_ID_KEY) ? State.Index.get(NDX_ID_KEY) + 3000 : (Id + 1000000); + NDXId = State.Index.has(NDX_ID_KEY) ? State.Index.get(NDX_ID_KEY) + 1003000 : (Id + 1000000); if ( !Number.isInteger(NDXId) ) NDXId = Id; DEBUG && console.log({firstFreeId: Id, firstFreeNDXId: NDXId}); @@ -840,6 +845,7 @@ export default Archivist; function saveFiles({useState: useState = false, forceSave:forceSave = false} = {}) { clearSavers(); + if ( State.Index.size === 0 ) return; State.Index.set(NDX_ID_KEY, NDXId); if ( useState ) { // saves the old cache path diff --git a/highlighter.js b/highlighter.js index a886e5b..ae85093 100644 --- a/highlighter.js +++ b/highlighter.js @@ -27,6 +27,7 @@ export function highlight(query, doc, { doc = doc.slice(0, maxLength); } const highlights = []; + const extra = chunkSize; // use array from then length rather than string length to // give accurate length for all unicode const qLength = Array.from(query).length; @@ -67,7 +68,6 @@ export function highlight(query, doc, { let better = Array.from(highlights).slice(0, 10); better = better.map(hl => { const length = Array.from(hl.fragment.text).length; - const extra = Math.round(length/2); let {offset, symbols} = hl.fragment; const newText = symbols.slice(Math.max(0,offset - extra), offset).join('') + hl.fragment.text + symbols.slice(offset + length, offset + length + extra).join(''); DEBUG && console.log({newText, oldText:hl.fragment.text, p:[Math.max(0,offset-extra), offset, offset+length, offset+length+extra], trueText: symbols.slice(offset, offset+length).join('')}); diff --git a/libraryServer.js b/libraryServer.js index a3e0b04..136dd73 100644 --- a/libraryServer.js +++ b/libraryServer.js @@ -64,7 +64,7 @@ function addHandlers() { }, null, 2)); } else { results.forEach(r => { - r.snippet = highlight(query, r.content, {maxLength:MAX_HIGHLIGHTABLE_LENGTH}) + r.snippet = '... ' + highlight(query, r.content, {maxLength:MAX_HIGHLIGHTABLE_LENGTH}) .sort(({fragment:{offset:a}}, {fragment:{offset:b}}) => a-b) .map(hl => Archivist.findOffsets(query, hl.fragment.text)) .join(' ... '); @@ -134,40 +134,7 @@ function IndexView(urls) { Your HTML Library - +

22120

Internet Offline Library

Archive Index

@@ -195,43 +162,7 @@ function SearchResultView({results, query, HL}) { ${query} - 22120 search results - +

22120

Search results

Or view your index. diff --git a/lib/fuzzy.js b/old-lib/fuzzy.js similarity index 100% rename from lib/fuzzy.js rename to old-lib/fuzzy.js diff --git a/lib/fz.js b/old-lib/fz.js similarity index 100% rename from lib/fz.js rename to old-lib/fz.js diff --git a/lib/ndx.js b/old-lib/ndx.js similarity index 100% rename from lib/ndx.js rename to old-lib/ndx.js diff --git a/lib/testFuzzy.js b/old-lib/testFuzzy.js similarity index 100% rename from lib/testFuzzy.js rename to old-lib/testFuzzy.js diff --git a/public/index.html b/public/index.html index 779c02c..1f6f8a1 100644 --- a/public/index.html +++ b/public/index.html @@ -1,40 +1,7 @@ Your HTML Library - +

22120

Internet Offline Library

diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..60b2ba6 --- /dev/null +++ b/public/style.css @@ -0,0 +1,36 @@ + + :root { + font-family: sans-serif; + background: lavenderblush; + } + body { + display: table; + margin: 0 auto; + background: silver; + padding: 0.5em; + box-shadow: 0 1px 1px purple; + } + form { + } + fieldset { + border: thin solid purple; + } + button, input, output { + } + input.long { + width: 100%; + min-width: 250px; + } + output { + font-size: smaller; + color: purple; + } + h1 { + margin: 0; + } + h2 { + margin-top: 0; + } + small.url { + word-break: break-all; + } diff --git a/todo b/todo index 7515fcf..16050c2 100644 --- a/todo +++ b/todo @@ -1,11 +1,11 @@ - linting - Improve search page look - search improvements + - implement trigram index - use different min score options for different sources (noticed URL not match meghan highlight for hello mag even tho query got megan and did match and highlight queen in url) - get snippets earlier (before rendering in lib server) and use to add to signal - if we have multiple query terms (multiple determined by some form of tokenization) then try to show all terms present in the snippet. even tho one term may be higher scoring. Should we do multiple passes of ukkonen distance one for whole query and one for each term? This will be easier / faster with trigrams I guess. Basically we want snippet to be a relevant summary that provides signal. - Another way to improve snippet highlight is to 'revert back' the highlighted text, and calculate their match/ukkonen on the query term. So e.g. if we get q:'israle beverly', hl:['beverly', 'beverly'], it's good overlap, but if we get hl:['is it really'] even tho that might score ok for israle, it's not a good match. so can we 'score that back' if we go match('is it really', 'israel') and see it is low, so we exclude it? - - implement trigram index - try an exact match on the query term if possible for highlight. first one. - we could also add signal from the highlighting to just in time alter the order (e.g. 'hell wiki' search brings google search to top rank, but the Hell wikipedia page has more highlight visible) - Create instant search (or at least instant queries (so search over previous queries -- not results necessarily))