Работа над opds

This commit is contained in:
Book Pauk
2022-11-24 16:36:40 +07:00
parent 95da605cb9
commit 4371e1a641
2 changed files with 23 additions and 25 deletions

View File

@@ -567,17 +567,17 @@ class DbSearcher {
const ids = ${db.esc(Array.from(ids))}; const ids = ${db.esc(Array.from(ids))};
for (const id of ids) { for (const id of ids) {
const row = @unsafeRow(id); const row = @unsafeRow(id);
const s = row.name.substring(0, depth); const s = row.value.substring(0, depth);
let g = group.get(s); let g = group.get(s);
if (!g) { if (!g) {
g = {id: row.id, name: s, count: 0}; g = {id: row.id, name: row.name, value: s, count: 0};
group.set(s, g); group.set(s, g);
} }
g.count++; g.count++;
} }
const result = Array.from(group.values()); const result = Array.from(group.values());
result.sort((a, b) => a.name.localeCompare(b.name)); result.sort((a, b) => a.value.localeCompare(b.value));
return result; return result;
` `
@@ -778,7 +778,7 @@ class DbSearcher {
if (delCount < 1) if (delCount < 1)
return; return;
//выберем всех кандидатов на удаление //выберем delCount кандидатов на удаление
rows = await db.select({ rows = await db.select({
table: 'query_time', table: 'query_time',
rawResult: true, rawResult: true,

View File

@@ -150,35 +150,33 @@ class BasePage {
//конец навигации //конец навигации
return await this.search(from, query); return await this.search(from, query);
} else { } else {
const names = new Set();
let len = 0; let len = 0;
for (const row of queryRes.found) { for (const row of queryRes.found) {
const name = row.name.toUpperCase(); const value = row.value;
const lowName = row.name.toLowerCase(); len += value.length;
len += name.length;
if (lowName == query[from]) { let rec;
//конец навигации, результат содержит запрос if (row.count == 1) {
return await this.search(from, query); rec = {
}
if (!names.has(name)) {
const rec = {
id: row.id, id: row.id,
title: name.replace(/ /g, spaceChar), title: row.name,
q: encodeURIComponent(lowName), q: `=${encodeURIComponent(row.name)}`,
count: row.count,
}; };
if (query.depth > 1 || enru.has(lowName[0])) { } else {
result.push(rec); rec = {
} else { id: row.id,
others.push(rec); title: `${value.toUpperCase().replace(/ /g, spaceChar)}~`,
} q: encodeURIComponent(value),
names.add(name); };
}
if (query.depth > 1 || enru.has(value[0])) {
result.push(rec);
} else {
others.push(rec);
} }
} }
if (query[from] && query.depth > 1 && result.length < 20 && len > prevLen) { if (query[from] && query.depth > 1 && result.length < 10 && len > prevLen) {
//рекурсия, с увеличением глубины, для облегчения навигации //рекурсия, с увеличением глубины, для облегчения навигации
const newQuery = _.cloneDeep(query); const newQuery = _.cloneDeep(query);
newQuery.depth++; newQuery.depth++;