Работа над проектом
This commit is contained in:
@@ -46,8 +46,13 @@
|
|||||||
|
|
||||||
<div class="q-mx-xs" />
|
<div class="q-mx-xs" />
|
||||||
<div class="row items-center q-mt-xs">
|
<div class="row items-center q-mt-xs">
|
||||||
|
<div v-show="queryFound > 0">
|
||||||
Показаны {{ queryFound }} из {{ totalFound }} найденных авторов
|
Показаны {{ queryFound }} из {{ totalFound }} найденных авторов
|
||||||
</div>
|
</div>
|
||||||
|
<div v-show="queryFound == 0">
|
||||||
|
Ничего не найдено
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="q-mx-xs" />
|
<div class="q-mx-xs" />
|
||||||
<div class="col row justify-end q-mt-xs">
|
<div class="col row justify-end q-mt-xs">
|
||||||
@@ -135,7 +140,7 @@ class Search {
|
|||||||
limit = 100;
|
limit = 100;
|
||||||
|
|
||||||
//stuff
|
//stuff
|
||||||
queryFound = 0;
|
queryFound = -1;
|
||||||
totalFound = 0;
|
totalFound = 0;
|
||||||
|
|
||||||
limitOptions = [
|
limitOptions = [
|
||||||
|
|||||||
14
package-lock.json
generated
14
package-lock.json
generated
@@ -15,7 +15,7 @@
|
|||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"jembadb": "^4.0.0",
|
"jembadb": "^4.1.0",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimist": "^1.2.6",
|
"minimist": "^1.2.6",
|
||||||
@@ -5103,9 +5103,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/jembadb": {
|
"node_modules/jembadb": {
|
||||||
"version": "4.0.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-4.1.0.tgz",
|
||||||
"integrity": "sha512-FLOL1uBhtUSOy/NngbzIsKSHaM6DISSNHpCT+NApsPj1ExCWnXsym0rs9TJum75Hdu48HP34UUtfQKyFo2Sseg==",
|
"integrity": "sha512-0A35t0S/ofTkTa5++gWtL1ctTimYgvcs84IV3TL5TFQzGmv2OFhIy8FVz0chBwcb6aTp161ec/yFSzN4ISySAA==",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.16.0"
|
"node": ">=16.16.0"
|
||||||
}
|
}
|
||||||
@@ -12577,9 +12577,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"jembadb": {
|
"jembadb": {
|
||||||
"version": "4.0.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/jembadb/-/jembadb-4.1.0.tgz",
|
||||||
"integrity": "sha512-FLOL1uBhtUSOy/NngbzIsKSHaM6DISSNHpCT+NApsPj1ExCWnXsym0rs9TJum75Hdu48HP34UUtfQKyFo2Sseg=="
|
"integrity": "sha512-0A35t0S/ofTkTa5++gWtL1ctTimYgvcs84IV3TL5TFQzGmv2OFhIy8FVz0chBwcb6aTp161ec/yFSzN4ISySAA=="
|
||||||
},
|
},
|
||||||
"jest-worker": {
|
"jest-worker": {
|
||||||
"version": "27.5.1",
|
"version": "27.5.1",
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
"compression": "^1.7.4",
|
"compression": "^1.7.4",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
"jembadb": "^4.0.0",
|
"jembadb": "^4.1.0",
|
||||||
"localforage": "^1.10.0",
|
"localforage": "^1.10.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimist": "^1.2.6",
|
"minimist": "^1.2.6",
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
|
||||||
const maxUtf8Char = String.fromCodePoint(0xFFFFF);
|
const maxUtf8Char = String.fromCodePoint(0xFFFFF);
|
||||||
|
const ruAlphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
|
||||||
|
const enAlphabet = 'abcdefghijklmnopqrstuvwxyz';
|
||||||
|
const enruArr = (ruAlphabet + enAlphabet).split('');
|
||||||
|
|
||||||
class DbSearcher {
|
class DbSearcher {
|
||||||
constructor(config, db) {
|
constructor(config, db) {
|
||||||
@@ -16,31 +19,53 @@ class DbSearcher {
|
|||||||
this.periodicCleanCache();//no await
|
this.periodicCleanCache();//no await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getWhere(a) {
|
||||||
|
const db = this.db;
|
||||||
|
let where;
|
||||||
|
|
||||||
|
//особая обработка префиксов
|
||||||
|
if (a[0] == '=') {
|
||||||
|
a = a.substring(1);
|
||||||
|
where = `@@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a)});`;
|
||||||
|
} else if (a[0] == '*') {
|
||||||
|
a = a.substring(1);
|
||||||
|
where = `@@indexIter('value', (v) => (v.indexOf(${db.esc(a)}) >= 0) );`;
|
||||||
|
} else if (a[0] == '#') {
|
||||||
|
a = a.substring(1);
|
||||||
|
where = `@@indexIter('value', (v) => {
|
||||||
|
const enru = new Set(${db.esc(enruArr)});
|
||||||
|
return !v || !enru.has(v[0].toLowerCase());
|
||||||
|
});`;
|
||||||
|
} else {
|
||||||
|
where = `@@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a + maxUtf8Char)});`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return where;
|
||||||
|
}
|
||||||
|
|
||||||
async selectAuthorIds(query) {
|
async selectAuthorIds(query) {
|
||||||
const db = this.db;
|
const db = this.db;
|
||||||
|
|
||||||
let authorRows;
|
|
||||||
let authorIds = new Set();
|
let authorIds = new Set();
|
||||||
|
|
||||||
//сначала выберем все id авторов по фильтру
|
//сначала выберем все id авторов по фильтру
|
||||||
//порядок id соответсвует ASC-сортировке по author
|
//порядок id соответсвует ASC-сортировке по author
|
||||||
if (query.author) {
|
if (query.author && query.author !== '*') {
|
||||||
const a = query.author.toLowerCase(query.author);
|
const where = this.getWhere(query.author.toLowerCase());
|
||||||
|
|
||||||
authorRows = await db.select({
|
const authorRows = await db.select({
|
||||||
table: 'author',
|
table: 'author',
|
||||||
map: `(r) => ({id: r.id})`,
|
dirtyIdsOnly: true,
|
||||||
where: `
|
where
|
||||||
@@dirtyIndexLR('value', ${db.esc(a)}, ${db.esc(a + maxUtf8Char)})
|
|
||||||
`,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const row of authorRows)
|
for (const row of authorRows)
|
||||||
authorIds.add(row.id);
|
authorIds.add(row.id);
|
||||||
} else {//все авторы
|
} else {//все авторы
|
||||||
if (!db.searchCache.authorIdsAll) {
|
if (!db.searchCache.authorIdsAll) {
|
||||||
authorRows = await db.select({
|
const authorRows = await db.select({
|
||||||
table: 'author',
|
table: 'author',
|
||||||
map: `(r) => ({id: r.id})`,
|
dirtyIdsOnly: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
db.searchCache.authorIdsAll = [];
|
db.searchCache.authorIdsAll = [];
|
||||||
@@ -59,7 +84,45 @@ class DbSearcher {
|
|||||||
idsArr.push(authorIds);
|
idsArr.push(authorIds);
|
||||||
|
|
||||||
//серии
|
//серии
|
||||||
|
if (query.series && query.series !== '*') {
|
||||||
|
const where = this.getWhere(query.series.toLowerCase());
|
||||||
|
|
||||||
|
const seriesRows = await db.select({
|
||||||
|
table: 'series',
|
||||||
|
map: `(r) => ({authorId: r.authorId})`,
|
||||||
|
where
|
||||||
|
});
|
||||||
|
|
||||||
|
let ids = new Set();
|
||||||
|
for (const row of seriesRows) {
|
||||||
|
for (const id of row.authorId)
|
||||||
|
ids.add(id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
idsArr.push(ids);
|
||||||
|
}
|
||||||
|
|
||||||
//названия
|
//названия
|
||||||
|
if (query.title && query.title !== '*') {
|
||||||
|
const where = this.getWhere(query.title.toLowerCase());
|
||||||
|
|
||||||
|
const seriesRows = await db.select({
|
||||||
|
table: 'title',
|
||||||
|
map: `(r) => ({authorId: r.authorId})`,
|
||||||
|
where
|
||||||
|
});
|
||||||
|
|
||||||
|
let ids = new Set();
|
||||||
|
for (const row of seriesRows) {
|
||||||
|
for (const id of row.authorId)
|
||||||
|
ids.add(id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
idsArr.push(ids);
|
||||||
|
}
|
||||||
|
|
||||||
//жанры
|
//жанры
|
||||||
//языки
|
//языки
|
||||||
|
|
||||||
@@ -69,7 +132,7 @@ class DbSearcher {
|
|||||||
//сортировка
|
//сортировка
|
||||||
authorIds = Array.from(authorIds);
|
authorIds = Array.from(authorIds);
|
||||||
|
|
||||||
authorIds.sort((a, b) => a > b);
|
authorIds.sort((a, b) => a - b);
|
||||||
|
|
||||||
return authorIds;
|
return authorIds;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user