diff options
| author | andrewdkim <adkim414@gmail.com> | 2019-07-19 11:21:47 -0400 |
|---|---|---|
| committer | andrewdkim <adkim414@gmail.com> | 2019-07-19 11:21:47 -0400 |
| commit | e453e7010def252b6cc10ad49d64708767c5589b (patch) | |
| tree | 4353a4be5495acd61d813066d001e2b12da7d207 /src/server/Search.ts | |
| parent | 9cad9abcf164c7d81b8debf4aa2639d83edd227b (diff) | |
| parent | 8854d3277541a67aef4187b5d3592bea5a7fcfa2 (diff) | |
merge from master
Diffstat (limited to 'src/server/Search.ts')
| -rw-r--r-- | src/server/Search.ts | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/src/server/Search.ts b/src/server/Search.ts index d776480c6..723dc101b 100644 --- a/src/server/Search.ts +++ b/src/server/Search.ts @@ -18,19 +18,28 @@ export class Search { } } - public async search(query: string) { + 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, documents); + } + } + + public async search(query: any) { try { const searchResults = JSON.parse(await rp.get(this.url + "dash/select", { - qs: { - q: query, - fl: "id" - } + qs: query })); - const fields = searchResults.response.docs; - const ids = fields.map((field: any) => field.id); - return ids; + const { docs, numFound } = searchResults.response; + const ids = docs.map((field: any) => field.id); + return { ids, numFound, highlighting: searchResults.highlighting }; } catch { - return []; + return { ids: [], numFound: -1 }; } } @@ -46,4 +55,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 |
