Преглед на файлове

Работа над расширенным поиском

Book Pauk преди 2 години
родител
ревизия
6160afa7f0
променени са 4 файла, в които са добавени 41 реда и са изтрити 3 реда
  1. 2 1
      server/config/base.js
  2. 1 0
      server/config/index.js
  3. 4 2
      server/core/DbCreator.js
  4. 34 0
      server/core/InpxParser.js

+ 2 - 1
server/config/base.js

@@ -12,6 +12,7 @@ module.exports = {
 
     accessPassword: '',
     accessTimeout: 0,
+    extendedSearch: true,
     bookReadLink: '',
     loggingEnabled: true,
 
@@ -30,7 +31,7 @@ module.exports = {
     lowMemoryMode: false,
     fullOptimization: false,
 
-    webConfigParams: ['name', 'version', 'branch', 'bookReadLink', 'dbVersion'],
+    webConfigParams: ['name', 'version', 'branch', 'bookReadLink', 'dbVersion', 'extendedSearch'],
 
     allowRemoteLib: false,
     remoteLib: false,

+ 1 - 0
server/config/index.js

@@ -7,6 +7,7 @@ const branchFilename = __dirname + '/application_env';
 const propsToSave = [
     'accessPassword',
     'accessTimeout',
+    'extendedSearch',
     'bookReadLink',
     'loggingEnabled',
     'dbCacheSize',

+ 4 - 2
server/core/DbCreator.js

@@ -261,7 +261,7 @@ class DbCreator {
 
         //парсинг
         const parser = new InpxParser();
-        await parser.parse(config.inpxFile, readFileCallback, parsedCallback);
+        await parser.parse(config.inpxFile, readFileCallback, parsedCallback);        
 
         //чистка памяти, ибо жрет как не в себя
         authorMap = null;
@@ -448,7 +448,9 @@ class DbCreator {
 
         const inpxInfo = (inpxFilter && inpxFilter.info ? inpxFilter.info : parser.info);
         inpxInfo.structure = parser.info.structure;
-        
+        if (!inpxInfo.version)
+            inpxInfo.version = parser.info.version;
+
         await db.insert({table: 'config', rows: [
             {id: 'inpxInfo', value: inpxInfo},
             {id: 'stats', value: stats},

+ 34 - 0
server/core/InpxParser.js

@@ -1,12 +1,32 @@
 const path = require('path');
 const crypto = require('crypto');
 const ZipReader = require('./ZipReader');
+const utils = require('./utils');
 
 const collectionInfo = 'collection.info';
 const structureInfo = 'structure.info';
 const versionInfo = 'version.info';
 
 const defaultStructure = 'AUTHOR;GENRE;TITLE;SERIES;SERNO;FILE;SIZE;LIBID;DEL;EXT;DATE;LANG;LIBRATE;KEYWORDS';
+//'AUTHOR;GENRE;TITLE;SERIES;SERNO;FILE;SIZE;LIBID;DEL;EXT;DATE;INSNO;FOLDER;LANG;LIBRATE;KEYWORDS;'
+const defaultRecStruct = {
+  author: 'S',
+  genre: 'S',
+  title: 'S',
+  series: 'S',
+  serno: 'N',
+  file: 'S',
+  size: 'N',
+  libid: 'S',
+  del: 'N',
+  ext: 'S',
+  date: 'S',
+  insno: 'N',
+  folder: 'S',
+  lang: 'S',
+  librate: 'N',
+  keywords: 'S',
+}
 
 class InpxParser {
     constructor() {
@@ -24,6 +44,18 @@ class InpxParser {
         return result;
     }
 
+    getRecStruct(structure) {
+        const result = {};
+        for (const field of structure)
+            if (utils.hasProp(defaultRecStruct, field))
+                result[field] = defaultRecStruct[field];
+
+        //folder есть всегда
+        result['folder'] = defaultRecStruct['folder'];
+
+        return result;
+    }
+
     async parse(inpxFile, readFileCallback, parsedCallback) {
         if (!readFileCallback)
             readFileCallback = async() => {};
@@ -65,6 +97,8 @@ class InpxParser {
                 info.structure = defaultStructure;
             const structure = info.structure.toLowerCase().split(';');
 
+            info.recStruct = this.getRecStruct(structure);
+
             //парсим inp-файлы
             this.chunk = [];
             for (const inpFile of inpFiles) {