diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-05-05 18:28:35 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-05-05 18:28:35 -0400 |
commit | 86f55d8aa12268fe847eaa344e8efbab5d293f34 (patch) | |
tree | 6bbc5c6fb6825ef969ed0342e4851667b81577cc /src/server/Search.ts | |
parent | 2a9db784a6e3492a8f7d8ce9a745b4f1a0494241 (diff) | |
parent | 139600ab7e8a82a31744cd3798247236cd5616fc (diff) |
Merge branch 'nathan-starter' of https://github.com/brown-dash/Dash-Web into nathan-starter
Diffstat (limited to 'src/server/Search.ts')
-rw-r--r-- | src/server/Search.ts | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/server/Search.ts b/src/server/Search.ts index 25bd8badf..b21ee853a 100644 --- a/src/server/Search.ts +++ b/src/server/Search.ts @@ -4,32 +4,33 @@ import * as rp from 'request-promise'; const pathTo = (relative: string) => `http://localhost:8983/solr/dash/${relative}`; export namespace Search { - export async function updateDocument(document: any) { try { - return await rp.post(pathTo("update"), { + return await rp.post(pathTo('update'), { headers: { 'content-type': 'application/json' }, - body: JSON.stringify([document]) + body: JSON.stringify([document]), }); } catch (e) { // console.warn("Search error: " + e + document); } + return undefined; } export async function updateDocuments(documents: any[]) { try { - return await rp.post(pathTo("update"), { + return await rp.post(pathTo('update'), { headers: { 'content-type': 'application/json' }, - body: JSON.stringify(documents) + body: JSON.stringify(documents), }); } catch (e) { // console.warn("Search error: ", e, documents); } + return undefined; } export async function search(query: any) { try { - const output = await rp.get(pathTo("select"), { qs: query }); + const output = await rp.get(pathTo('select'), { qs: query }); const searchResults = JSON.parse(output); const { docs, numFound } = searchResults.response; const ids = docs.map((field: any) => field.id); @@ -41,16 +42,16 @@ export namespace Search { export async function clear() { try { - await rp.post(pathTo("update"), { + await rp.post(pathTo('update'), { body: { delete: { - query: "*:*" - } + query: '*:*', + }, }, - json: true + json: true, }); } catch (e: any) { - console.log(red("Unable to clear search...")); + console.log(red('Unable to clear search...')); console.log(red(e.message)); } } @@ -63,16 +64,18 @@ export namespace Search { const count = Math.min(docs.length - index, nToDelete); const deleteIds = docs.slice(index, index + count); index += count; - promises.push(rp.post(pathTo("update"), { - body: { - delete: { - query: deleteIds.map(id => `id:"${id}"`).join(" ") - } - }, - json: true - })); + promises.push( + rp.post(pathTo('update'), { + body: { + delete: { + query: deleteIds.map(id => `id:"${id}"`).join(' '), + }, + }, + json: true, + }) + ); } return Promise.all(promises); } -}
\ No newline at end of file +} |