Работа над 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))};
for (const id of ids) {
const row = @unsafeRow(id);
const s = row.name.substring(0, depth);
const s = row.value.substring(0, depth);
let g = group.get(s);
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);
}
g.count++;
}
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;
`
@@ -778,7 +778,7 @@ class DbSearcher {
if (delCount < 1)
return;
//выберем всех кандидатов на удаление
//выберем delCount кандидатов на удаление
rows = await db.select({
table: 'query_time',
rawResult: true,

View File

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