浏览代码

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

Book Pauk 2 年之前
父节点
当前提交
fd66034ba9

+ 2 - 1
server/core/DbSearcher.js

@@ -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());

+ 21 - 6
server/core/opds/AuthorPage.js

@@ -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,
                     };
                 }
 

+ 2 - 0
server/core/opds/BasePage.js

@@ -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 = {

+ 8 - 2
server/core/opds/SeriesPage.js

@@ -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,
                     };
                 }
 

+ 8 - 2
server/core/opds/TitlePage.js

@@ -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,
                     };
                 }
 

+ 1 - 0
server/core/utils.js

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