From c0d95115eaba9769fe83e83c9fe8a319554ce210 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 19 Aug 2022 18:04:46 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Search/Search.vue | 20 +++++++++++++++++++- server/core/DbCreator.js | 5 +++++ server/core/DbSearcher.js | 19 ++++++++----------- server/core/WebWorker.js | 2 +- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/client/components/Search/Search.vue b/client/components/Search/Search.vue index 5974d06..9e7a592 100644 --- a/client/components/Search/Search.vue +++ b/client/components/Search/Search.vue @@ -83,6 +83,24 @@ const componentOptions = { config() { this.makeTitle(); }, + author() { + this.refresh(); + }, + series() { + this.refresh(); + }, + title() { + this.refresh(); + }, + genre() { + this.refresh(); + }, + lang() { + this.refresh(); + }, + limit() { + this.refresh(); + }, }, }; class Search { @@ -92,7 +110,7 @@ class Search { //input field consts inputMaxLength = 1000; - inputDebounce = 400; + inputDebounce = 200; //search fields author = ''; diff --git a/server/core/DbCreator.js b/server/core/DbCreator.js index 4e925b0..86a8f37 100644 --- a/server/core/DbCreator.js +++ b/server/core/DbCreator.js @@ -86,6 +86,11 @@ class DbCreator { authorCount++; } + //это нужно для того, чтобы имя автора начиналось с заглавной + if (a[0].toUpperCase() === a[0]) + authorRec.author = a; + + //ссылки на книги authorRec.bookId.push(id); } } diff --git a/server/core/DbSearcher.js b/server/core/DbSearcher.js index a3675bf..a7e06cb 100644 --- a/server/core/DbSearcher.js +++ b/server/core/DbSearcher.js @@ -2,6 +2,8 @@ const utils = require('./utils'); +const maxUtf8Char = String.fromCodePoint(0xFFFFF); + class DbSearcher { constructor(config, db) { this.config = config; @@ -22,9 +24,14 @@ class DbSearcher { //сначала выберем все id авторов по фильтру //порядок id соответсвует ASC-сортировке по author if (query.author) { + const a = query.author.toLowerCase(query.author); + authorRows = await db.select({ table: 'author', map: `(r) => ({id: r.id})`, + where: ` + @@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a + maxUtf8Char)}) + `, }); for (const row of authorRows) @@ -136,17 +143,7 @@ class DbSearcher { let result = await db.select({ table: 'author', map: `(r) => ({id: r.id, author: r.author})`, - where: ` - const all = @all(); - const ids = new Set(); - let n = 0; - for (const id of all) { - if (++n > ${db.esc(limit)}) - break; - ids.add(id); - } - return ids; - ` + where: `@@id(${db.esc(authorIds.slice(0, limit))})` }); return {result, totalFound}; diff --git a/server/core/WebWorker.js b/server/core/WebWorker.js index 2ce6b14..1cfd38c 100644 --- a/server/core/WebWorker.js +++ b/server/core/WebWorker.js @@ -144,7 +144,7 @@ class WebWorker { db.wwCache = {}; this.db = db; - log('Searcher DB is ready'); + log('Searcher DB ready'); } catch (e) { log(LM_FATAL, e.message); ayncExit.exit(1);