diff options
Diffstat (limited to 'src/server/ApiManagers/SearchManager.ts')
-rw-r--r-- | src/server/ApiManagers/SearchManager.ts | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/server/ApiManagers/SearchManager.ts b/src/server/ApiManagers/SearchManager.ts index 92c10975f..684b49eaf 100644 --- a/src/server/ApiManagers/SearchManager.ts +++ b/src/server/ApiManagers/SearchManager.ts @@ -1,6 +1,7 @@ +/* eslint-disable no-use-before-define */ import { exec } from 'child_process'; import { cyan, green, red, yellow } from 'colors'; -import { log_execution } from '../ActionUtilities'; +import { logExecution } from '../ActionUtilities'; import { Method } from '../RouteManager'; import RouteSubscriber from '../RouteSubscriber'; import { Search } from '../Search'; @@ -17,8 +18,10 @@ export class SearchManager extends ApiManager { switch (action) { case 'start': case 'stop': - const status = req.params.action === 'start'; - SolrManager.SetRunning(status); + { + const status = req.params.action === 'start'; + SolrManager.SetRunning(status); + } break; case 'update': await SolrManager.update(); @@ -35,7 +38,9 @@ export class SearchManager extends ApiManager { subscription: '/dashsearch', secureHandler: async ({ req, res }) => { const solrQuery: any = {}; - ['q', 'fq', 'start', 'rows', 'sort', 'hl.maxAnalyzedChars', 'hl', 'hl.fl'].forEach(key => (solrQuery[key] = req.query[key])); + ['q', 'fq', 'start', 'rows', 'sort', 'hl.maxAnalyzedChars', 'hl', 'hl.fl'].forEach(key => { + solrQuery[key] = req.query[key]; + }); if (solrQuery.q === undefined) { res.send([]); return; @@ -66,13 +71,13 @@ export namespace SolrManager { export async function update() { console.log(green('Beginning update...')); - await log_execution<void>({ + await logExecution<void>({ startMessage: 'Clearing existing Solr information...', endMessage: 'Solr information successfully cleared', action: Search.clear, color: cyan, }); - const cursor = await log_execution({ + const cursor = await logExecution({ startMessage: 'Connecting to and querying for all documents from database...', endMessage: ({ result, error }) => { const success = error === null && result !== undefined; @@ -95,30 +100,30 @@ export namespace SolrManager { if (doc.__type !== 'Doc') { return; } - const fields = doc.fields; + const { fields } = doc; if (!fields) { return; } - const update: any = { id: doc._id }; + const update2: any = { id: doc._id }; let dynfield = false; - for (const key in fields) { + fields.forEach((key: any) => { const value = fields[key]; const term = ToSearchTerm(value); if (term !== undefined) { - const { suffix, value } = term; + const { suffix, value: tvalue } = term; if (key.endsWith('modificationDate')) { - update['modificationDate' + suffix] = value; + update2['modificationDate' + suffix] = tvalue; } - update[key + suffix] = value; + update2[key + suffix] = value; dynfield = true; } - } + }); if (dynfield) { - updates.push(update); + updates.push(update2); } } await cursor?.forEach(updateDoc); - const result = await log_execution({ + const result = await logExecution({ startMessage: `Dispatching updates for ${updates.length} documents`, endMessage: 'Dispatched updates complete', action: () => Search.updateDocuments(updates), @@ -156,6 +161,7 @@ export namespace SolrManager { '_l', list => { const results = []; + // eslint-disable-next-line no-restricted-syntax for (const value of list.fields) { const term = ToSearchTerm(value); if (term) { @@ -167,14 +173,15 @@ export namespace SolrManager { ], }; - function ToSearchTerm(val: any): { suffix: string; value: any } | undefined { + function ToSearchTerm(valIn: any): { suffix: string; value: any } | undefined { + let val = valIn; if (val === null || val === undefined) { - return; + return undefined; } const type = val.__type || typeof val; let suffix = suffixMap[type]; if (!suffix) { - return; + return undefined; } if (Array.isArray(suffix)) { @@ -184,6 +191,7 @@ export namespace SolrManager { } else { val = val[accessor]; } + // eslint-disable-next-line prefer-destructuring suffix = suffix[0]; } |