Compare commits
No commits in common. "88812800c058d9c9cd92d2c85dbea35e94693e58" and "d83c28e5fc5d74689b226b015a9bbfaa2cb27bf7" have entirely different histories.
88812800c0
...
d83c28e5fc
1 changed files with 9 additions and 18 deletions
27
script.js
27
script.js
|
|
@ -282,16 +282,6 @@
|
||||||
return `${hz.toLocaleString()} Hz`;
|
return `${hz.toLocaleString()} Hz`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeSqlText(value) {
|
|
||||||
return `'${String(value).replace(/'/g, "''")}'`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyFtsMatch(sql, matchExpr) {
|
|
||||||
const placeholder = 'MATCH ?';
|
|
||||||
if (!sql.includes(placeholder)) throw new Error('Expected FTS MATCH placeholder');
|
|
||||||
return sql.replace(placeholder, `MATCH ${escapeSqlText(matchExpr)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function unzipSqlite(zipBytes) {
|
async function unzipSqlite(zipBytes) {
|
||||||
loader.setStep('Unpacking database…');
|
loader.setStep('Unpacking database…');
|
||||||
loader.setDetail('Decompressing ZIP');
|
loader.setDetail('Decompressing ZIP');
|
||||||
|
|
@ -960,10 +950,11 @@
|
||||||
try {
|
try {
|
||||||
console.debug('[Search] Preparing count query', {
|
console.debug('[Search] Preparing count query', {
|
||||||
sql: countSql.trim(),
|
sql: countSql.trim(),
|
||||||
ftsExpr: matchExpr,
|
params: [matchExpr],
|
||||||
chars: Array.from(matchExpr).map((ch) => ch.codePointAt(0)),
|
chars: Array.from(matchExpr).map((ch) => ch.codePointAt(0)),
|
||||||
});
|
});
|
||||||
const countStmt = db.prepare(applyFtsMatch(countSql, matchExpr));
|
const countStmt = db.prepare(countSql);
|
||||||
|
countStmt.bind([matchExpr]);
|
||||||
if (countStmt.step()) {
|
if (countStmt.step()) {
|
||||||
const row = countStmt.getAsObject();
|
const row = countStmt.getAsObject();
|
||||||
total = Number(row.count) || 0;
|
total = Number(row.count) || 0;
|
||||||
|
|
@ -980,14 +971,13 @@
|
||||||
state.page = Math.max(1, Math.ceil(total / state.pageSize));
|
state.page = Math.max(1, Math.ceil(total / state.pageSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchParams = [state.pageSize, (state.page - 1) * state.pageSize];
|
const searchParams = [matchExpr, state.pageSize, (state.page - 1) * state.pageSize];
|
||||||
console.debug('[Search] Preparing row query', {
|
console.debug('[Search] Preparing row query', {
|
||||||
sql: effectiveSearchSql.trim(),
|
sql: effectiveSearchSql.trim(),
|
||||||
ftsExpr: matchExpr,
|
|
||||||
params: searchParams,
|
params: searchParams,
|
||||||
chars: Array.from(matchExpr).map((ch) => ch.codePointAt(0)),
|
chars: Array.from(matchExpr).map((ch) => ch.codePointAt(0)),
|
||||||
});
|
});
|
||||||
const searchStmt = db.prepare(applyFtsMatch(effectiveSearchSql, matchExpr));
|
const searchStmt = db.prepare(effectiveSearchSql);
|
||||||
searchStmt.bind(searchParams);
|
searchStmt.bind(searchParams);
|
||||||
const nextRows = [];
|
const nextRows = [];
|
||||||
while (searchStmt.step()) {
|
while (searchStmt.step()) {
|
||||||
|
|
@ -1194,14 +1184,15 @@
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ftsMatch) {
|
if (ftsMatch) {
|
||||||
const ftsCountStmt = db.prepare(applyFtsMatch(ftsCountSql, ftsMatch));
|
const ftsCountStmt = db.prepare(ftsCountSql);
|
||||||
|
ftsCountStmt.bind([ftsMatch]);
|
||||||
if (ftsCountStmt.step()) total = Number(ftsCountStmt.getAsObject().count) || 0;
|
if (ftsCountStmt.step()) total = Number(ftsCountStmt.getAsObject().count) || 0;
|
||||||
ftsCountStmt.free();
|
ftsCountStmt.free();
|
||||||
|
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
if (offset >= total) state.page = Math.max(1, Math.ceil(total / state.pageSize));
|
if (offset >= total) state.page = Math.max(1, Math.ceil(total / state.pageSize));
|
||||||
const ftsRowsStmt = db.prepare(applyFtsMatch(ftsRowsSql, ftsMatch));
|
const ftsRowsStmt = db.prepare(ftsRowsSql);
|
||||||
ftsRowsStmt.bind([state.pageSize, (state.page - 1) * state.pageSize]);
|
ftsRowsStmt.bind([ftsMatch, state.pageSize, (state.page - 1) * state.pageSize]);
|
||||||
while (ftsRowsStmt.step()) rows.push(ftsRowsStmt.getAsObject());
|
while (ftsRowsStmt.step()) rows.push(ftsRowsStmt.getAsObject());
|
||||||
ftsRowsStmt.free();
|
ftsRowsStmt.free();
|
||||||
usedFts = true;
|
usedFts = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue