mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 23:51:59 +03:00
Merge 577d7a3516 into 37cfd2144b
This commit is contained in:
commit
b3d36bf49c
1 changed files with 16 additions and 4 deletions
|
|
@ -33,6 +33,18 @@ export interface SearchController {
|
||||||
const $ = <T extends HTMLElement>(sel: string): T =>
|
const $ = <T extends HTMLElement>(sel: string): T =>
|
||||||
document.querySelector(sel) as T;
|
document.querySelector(sel) as T;
|
||||||
|
|
||||||
|
const lineCache = new Map<string, { text: string; lines: string[]; lowerLines: string[] }>();
|
||||||
|
|
||||||
|
function getCachedDocLines(id: string, text: string): { lines: string[]; lowerLines: string[] } {
|
||||||
|
let cached = lineCache.get(id);
|
||||||
|
if (cached && cached.text === text) return cached;
|
||||||
|
const lines = text.split("\n");
|
||||||
|
const lowerLines = text.toLowerCase().split("\n");
|
||||||
|
cached = { text, lines, lowerLines };
|
||||||
|
lineCache.set(id, cached);
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
export function parseResultQuery(
|
export function parseResultQuery(
|
||||||
engine: SumEngine,
|
engine: SumEngine,
|
||||||
q: string,
|
q: string,
|
||||||
|
|
@ -81,7 +93,7 @@ export function searchAllSheets(deps: SearchDeps, query: string): SearchHit[] {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (match) {
|
if (match) {
|
||||||
if (!lines) lines = doc.text.split("\n");
|
if (!lines) lines = getCachedDocLines(doc.id, doc.text).lines;
|
||||||
hits.push({
|
hits.push({
|
||||||
docId: doc.id,
|
docId: doc.id,
|
||||||
docTitle: doc.title,
|
docTitle: doc.title,
|
||||||
|
|
@ -98,9 +110,9 @@ export function searchAllSheets(deps: SearchDeps, query: string): SearchHit[] {
|
||||||
const ql = q.toLowerCase();
|
const ql = q.toLowerCase();
|
||||||
const hits: SearchHit[] = [];
|
const hits: SearchHit[] = [];
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
const lines = doc.text.split("\n");
|
const { lines, lowerLines } = getCachedDocLines(doc.id, doc.text);
|
||||||
for (let i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lowerLines.length; i++) {
|
||||||
if (lines[i].toLowerCase().includes(ql)) {
|
if (lowerLines[i].includes(ql)) {
|
||||||
hits.push({
|
hits.push({
|
||||||
docId: doc.id,
|
docId: doc.id,
|
||||||
docTitle: doc.title,
|
docTitle: doc.title,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue