Работа над новым поиском

This commit is contained in:
Book Pauk
2022-10-30 15:21:10 +07:00
parent 1210e5bd8a
commit 75cb5444b2

View File

@@ -122,83 +122,13 @@ class DbSearcher {
idsArr.push(ids); idsArr.push(ids);
} }
/*
//серии
if (query.series && query.series !== '*') {
const seriesKеy = `author-ids-series-${query.series}`;
let seriesIds = await this.getCached(seriesKеy);
if (seriesIds === null) {
const where = this.getWhere(query.series);
const seriesRows = await db.select({
table: 'series',
rawResult: true,
where: `
const ids = ${where};
const result = new Set();
for (const id of ids) {
const row = @unsafeRow(id);
for (const authorId of row.authorId)
result.add(authorId);
}
return Array.from(result);
`
});
seriesIds = seriesRows[0].rawResult;
await this.putCached(seriesKеy, seriesIds);
}
idsArr.push(seriesIds);
}
//названия
if (query.title && query.title !== '*') {
const titleKey = `author-ids-title-${query.title}`;
let titleIds = await this.getCached(titleKey);
if (titleIds === null) {
const where = this.getWhere(query.title);
let titleRows = await db.select({
table: 'title',
rawResult: true,
where: `
const ids = ${where};
const result = new Set();
for (const id of ids) {
const row = @unsafeRow(id);
for (const authorId of row.authorId)
result.add(authorId);
}
return Array.from(result);
`
});
titleIds = titleRows[0].rawResult;
await this.putCached(titleKey, titleIds);
}
idsArr.push(titleIds);
//чистки памяти при тяжелых запросах
if (this.config.lowMemoryMode && query.title[0] == '*') {
utils.freeMemory();
await db.freeMemory();
}
}
//жанры //жанры
if (query.genre) { if (query.genre) {
const genreKey = `author-ids-genre-${query.genre}`; const key = `book-ids-genre-${query.genre}`;
let genreIds = await this.getCached(genreKey); let ids = await this.getCached(key);
if (genreIds === null) { if (ids === null) {
const genreRows = await db.select({ const genreRows = await db.select({
table: 'genre', table: 'genre',
rawResult: true, rawResult: true,
@@ -214,27 +144,27 @@ class DbSearcher {
const result = new Set(); const result = new Set();
for (const id of ids) { for (const id of ids) {
const row = @unsafeRow(id); const row = @unsafeRow(id);
for (const authorId of row.authorId) for (const bookId of row.bookIds)
result.add(authorId); result.add(bookId);
} }
return Array.from(result); return Array.from(result);
` `
}); });
genreIds = genreRows[0].rawResult; ids = genreRows[0].rawResult;
await this.putCached(genreKey, genreIds); await this.putCached(key, ids);
} }
idsArr.push(genreIds); idsArr.push(ids);
} }
//языки //языки
if (query.lang) { if (query.lang) {
const langKey = `author-ids-lang-${query.lang}`; const key = `book-ids-lang-${query.lang}`;
let langIds = await this.getCached(langKey); let ids = await this.getCached(key);
if (langIds === null) { if (ids === null) {
const langRows = await db.select({ const langRows = await db.select({
table: 'lang', table: 'lang',
rawResult: true, rawResult: true,
@@ -250,89 +180,56 @@ class DbSearcher {
const result = new Set(); const result = new Set();
for (const id of ids) { for (const id of ids) {
const row = @unsafeRow(id); const row = @unsafeRow(id);
for (const authorId of row.authorId) for (const bookId of row.bookIds)
result.add(authorId); result.add(bookId);
} }
return Array.from(result); return Array.from(result);
` `
}); });
langIds = langRows[0].rawResult; ids = langRows[0].rawResult;
await this.putCached(langKey, langIds); await this.putCached(key, ids);
} }
idsArr.push(langIds); idsArr.push(ids);
} }
//удаленные //удаленные
if (query.del !== undefined) { if (query.del !== undefined) {
const delKey = `author-ids-del-${query.del}`; const key = `book-ids-del-${query.del}`;
let delIds = await this.getCached(delKey); let ids = await this.getCached(key);
if (delIds === null) { if (ids === null) {
const delRows = await db.select({ ids = await tableBookIds('del', `@indexLR('value', ${db.esc(query.del)}, ${db.esc(query.del)})`);
table: 'del',
rawResult: true,
where: `
const ids = @indexLR('value', ${db.esc(query.del)}, ${db.esc(query.del)});
const result = new Set();
for (const id of ids) {
const row = @unsafeRow(id);
for (const authorId of row.authorId)
result.add(authorId);
}
return Array.from(result); await this.putCached(key, ids);
`
});
delIds = delRows[0].rawResult;
await this.putCached(delKey, delIds);
} }
idsArr.push(delIds); idsArr.push(ids);
} }
//дата поступления //дата поступления
if (query.date) { if (query.date) {
const dateKey = `author-ids-date-${query.date}`; const key = `book-ids-date-${query.date}`;
let dateIds = await this.getCached(dateKey); let ids = await this.getCached(key);
if (dateIds === null) { if (ids === null) {
let [from = '', to = ''] = query.date.split(','); let [from = '', to = ''] = query.date.split(',');
ids = await tableBookIds('date', `@indexLR('value', ${db.esc(from)} || undefined, ${db.esc(to)} || undefined)`);
const dateRows = await db.select({ await this.putCached(key, ids);
table: 'date',
rawResult: true,
where: `
const ids = @indexLR('value', ${db.esc(from)} || undefined, ${db.esc(to)} || undefined);
const result = new Set();
for (const id of ids) {
const row = @unsafeRow(id);
for (const authorId of row.authorId)
result.add(authorId);
}
return Array.from(result);
`
});
dateIds = dateRows[0].rawResult;
await this.putCached(dateKey, dateIds);
} }
idsArr.push(dateIds); idsArr.push(ids);
} }
//оценка //оценка
if (query.librate) { if (query.librate) {
const librateKey = `author-ids-librate-${query.librate}`; const key = `book-ids-librate-${query.librate}`;
let librateIds = await this.getCached(librateKey); let ids = await this.getCached(key);
if (librateIds === null) { if (ids === null) {
const dateRows = await db.select({ const dateRows = await db.select({
table: 'librate', table: 'librate',
rawResult: true, rawResult: true,
@@ -348,21 +245,21 @@ class DbSearcher {
const result = new Set(); const result = new Set();
for (const id of ids) { for (const id of ids) {
const row = @unsafeRow(id); const row = @unsafeRow(id);
for (const authorId of row.authorId) for (const bookId of row.bookIds)
result.add(authorId); result.add(bookId);
} }
return Array.from(result); return Array.from(result);
` `
}); });
librateIds = dateRows[0].rawResult; ids = dateRows[0].rawResult;
await this.putCached(librateKey, librateIds); await this.putCached(key, ids);
} }
idsArr.push(librateIds); idsArr.push(ids);
} }
*/
if (idsArr.length > 1) { if (idsArr.length > 1) {
//ищем пересечение множеств //ищем пересечение множеств
let proc = 0; let proc = 0;
@@ -624,10 +521,10 @@ class DbSearcher {
let books; let books;
if (rows.length && rows[0].rawResult.length) { if (rows.length && rows[0].rawResult.length) {
//выборка книг серии //выборка книг серии
const rows = await this.restoreBooks('series', [rows[0].rawResult[0]]) const bookRows = await this.restoreBooks('series', [rows[0].rawResult[0]])
if (rows.length) if (bookRows.length)
books = rows[0].books; books = bookRows[0].books;
} }
return {books: (books && books.length ? JSON.stringify(books) : '')}; return {books: (books && books.length ? JSON.stringify(books) : '')};