Улучшено отображение количества найденных результатов

This commit is contained in:
Book Pauk
2022-12-04 19:36:27 +07:00
parent c2e1d062e8
commit fd66034ba9
6 changed files with 42 additions and 11 deletions

View File

@@ -672,10 +672,11 @@ class DbSearcher {
const s = row.value.substring(0, depth);
let g = group.get(s);
if (!g) {
g = {id: row.id, name: row.name, value: s, count: 0};
g = {id: row.id, name: row.name, value: s, count: 0, bookCount: 0};
group.set(s, g);
}
g.count++;
g.bookCount += row.bookCount;
}
const result = Array.from(group.values());

View File

@@ -12,17 +12,22 @@ class AuthorPage extends BasePage {
sortBooks(bookList) {
//схлопывание серий
const books = [];
const seriesSet = new Set();
const seriesMap = new Map();
for (const book of bookList) {
if (book.series) {
if (!seriesSet.has(book.series)) {
let seriesIndex = seriesMap.get(book.series);
if (seriesIndex === undefined) {
seriesIndex = books.length;
books.push({
type: 'series',
book
book,
bookCount: 0,
});
seriesSet.add(book.series);
seriesMap.set(book.series, seriesIndex);
}
books[seriesIndex].bookCount++;
} else {
books.push({
type: 'book',
@@ -135,6 +140,10 @@ class AuthorPage extends BasePage {
link: this.navLink({
href: `/${this.id}?author=${encodeURIComponent(query.author)}` +
`&series=${encodeURIComponent(b.book.series)}&genre=${encodeURIComponent(query.genre)}`}),
content: {
'*ATTRS': {type: 'text'},
'*TEXT': `${b.bookCount} книг${utils.wordEnding(b.bookCount, 8)} по автору${(query.genre ? ' (в выбранном жанре)' : '')}`,
},
})
);
} else {
@@ -170,10 +179,16 @@ class AuthorPage extends BasePage {
link: this.navLink({href: `/${this.id}?author=${rec.q}&genre=${encodeURIComponent(query.genre)}`}),
};
if (rec.count) {
let countStr = '';
if (rec.count)
countStr = `${rec.count} автор${utils.wordEnding(rec.count, 0)}${(query.genre ? ' (в выбранном жанре)' : '')}`;
if (!countStr && rec.bookCount && !query.genre)
countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`;
if (countStr) {
e.content = {
'*ATTRS': {type: 'text'},
'*TEXT': `${rec.count} автор${utils.wordEnding(rec.count, 0)}`,
'*TEXT': countStr,
};
}

View File

@@ -140,6 +140,7 @@ class BasePage {
id: row.id,
title: (row[from] || 'Без автора'),
q: `=${encodeURIComponent(row[from])}`,
bookCount: row.bookCount,
};
result.push(rec);
@@ -171,6 +172,7 @@ class BasePage {
id: row.id,
title: row.name,
q: `=${encodeURIComponent(row.name)}`,
bookCount: row.bookCount,
};
} else {
rec = {

View File

@@ -103,10 +103,16 @@ class SeriesPage extends BasePage {
link: this.navLink({href: `/${this.id}?series=${rec.q}&genre=${encodeURIComponent(query.genre)}`}),
};
if (rec.count) {
let countStr = '';
if (rec.count)
countStr = `${rec.count} сери${utils.wordEnding(rec.count, 1)}${(query.genre ? ' (в выбранном жанре)' : '')}`;
if (!countStr && rec.bookCount && !query.genre)
countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`;
if (countStr) {
e.content = {
'*ATTRS': {type: 'text'},
'*TEXT': `${rec.count} сери${utils.wordEnding(rec.count, 1)}`,
'*TEXT': countStr,
};
}

View File

@@ -73,10 +73,16 @@ class TitlePage extends BasePage {
link: this.navLink({href: `/${this.id}?title=${rec.q}&genre=${encodeURIComponent(query.genre)}`}),
};
if (rec.count) {
let countStr = '';
if (rec.count)
countStr = `${rec.count} назван${utils.wordEnding(rec.count, 3)}${(query.genre ? ' (в выбранном жанре)' : '')}`;
if (!countStr && rec.bookCount && !query.genre)
countStr = `${rec.bookCount} книг${utils.wordEnding(rec.bookCount, 8)}`;
if (countStr) {
e.content = {
'*ATTRS': {type: 'text'},
'*TEXT': `${rec.count} назван${utils.wordEnding(rec.count, 3)}`,
'*TEXT': countStr,
};
}

View File

@@ -184,6 +184,7 @@ function wordEnding(num, type = 0) {
['ок', 'ка', 'ки', 'ки', 'ки', 'ок', 'ок', 'ок', 'ок', 'ок'],//5
['ых', 'ое', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых', 'ых'],//6
['о', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о', 'о'],//7
['', 'а', 'и', 'и', 'и', '', '', '', '', ''],//8
];
const deci = num % 100;
if (deci > 10 && deci < 20) {