浏览代码

Работа над проектом

Book Pauk 2 年之前
父节点
当前提交
c0d95115ea
共有 4 个文件被更改,包括 33 次插入13 次删除
  1. 19 1
      client/components/Search/Search.vue
  2. 5 0
      server/core/DbCreator.js
  3. 8 11
      server/core/DbSearcher.js
  4. 1 1
      server/core/WebWorker.js

+ 19 - 1
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 = '';

+ 5 - 0
server/core/DbCreator.js

@@ -86,6 +86,11 @@ class DbCreator {
                             authorCount++;
                     }
 
+                    //это нужно для того, чтобы имя автора начиналось с заглавной
+                    if (a[0].toUpperCase() === a[0])
+                        authorRec.author = a;
+                    
+                    //ссылки на книги
                     authorRec.bookId.push(id);
                 }
             }

+ 8 - 11
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};

+ 1 - 1
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);