diff options
| author | Sam Wilkins <samwilkins333@gmail.com> | 2019-07-09 14:34:07 -0400 |
|---|---|---|
| committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-07-09 14:34:07 -0400 |
| commit | 68a433e689345b2fdd6279d7a80c5cf77cace1c3 (patch) | |
| tree | 782181ba288c7035efac476764e67a6449f762ff /src/server/Search.ts | |
| parent | 9d9c16939bb296a9deb38bc34cbea9870aee4f76 (diff) | |
| parent | fb1e2078dc0e0cdc33f6037cd3c3e18ffded413e (diff) | |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into import
Diffstat (limited to 'src/server/Search.ts')
| -rw-r--r-- | src/server/Search.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/server/Search.ts b/src/server/Search.ts index e2a74b737..8591f8857 100644 --- a/src/server/Search.ts +++ b/src/server/Search.ts @@ -18,6 +18,18 @@ export class Search { } } + public async updateDocuments(documents: any[]) { + try { + const res = await rp.post(this.url + "dash/update", { + headers: { 'content-type': 'application/json' }, + body: JSON.stringify(documents) + }); + return res; + } catch (e) { + // console.warn("Search error: " + e + document); + } + } + public async search(query: string, start: number = 0) { try { const searchResults = JSON.parse(await rp.get(this.url + "dash/select", { @@ -47,4 +59,25 @@ export class Search { }); } catch { } } + + public deleteDocuments(docs: string[]) { + const promises: rp.RequestPromise[] = []; + const nToDelete = 1000; + let index = 0; + while (index < docs.length) { + const count = Math.min(docs.length - index, nToDelete); + const deleteIds = docs.slice(index, index + count); + index += count; + promises.push(rp.post(this.url + "dash/update", { + body: { + delete: { + query: deleteIds.map(id => `id:"${id}"`).join(" ") + } + }, + json: true + })); + } + + return Promise.all(promises); + } }
\ No newline at end of file |
