diff options
| author | Sam Wilkins <samwilkins333@gmail.com> | 2019-05-09 22:14:30 -0400 |
|---|---|---|
| committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-05-09 22:14:30 -0400 |
| commit | ea1bffb43f0533cde4cf8a3f34da8b0e25ef6268 (patch) | |
| tree | 5016ac7d3bbb37e62a809d738ddc45c3797bab18 /src/server/Search.ts | |
| parent | 11c6ecdebdfb84246169f1e573c0e47e5336eff6 (diff) | |
| parent | 310d4b0f4bb56adaa71e4b42d09e483e4face0f7 (diff) | |
merged with master and fixed linter issues
Diffstat (limited to 'src/server/Search.ts')
| -rw-r--r-- | src/server/Search.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/server/Search.ts b/src/server/Search.ts new file mode 100644 index 000000000..c3cb3c3e6 --- /dev/null +++ b/src/server/Search.ts @@ -0,0 +1,45 @@ +import * as rp from 'request-promise'; +import { Database } from './database'; +import { thisExpression } from 'babel-types'; + +export class Search { + public static Instance = new Search(); + private url = 'http://localhost:8983/solr/'; + + public async updateDocument(document: any) { + try { + return await rp.post(this.url + "dash/update", { + headers: { 'content-type': 'application/json' }, + body: JSON.stringify([document]) + }); + } catch { } + } + + public async search(query: string) { + try { + const searchResults = JSON.parse(await rp.get(this.url + "dash/select", { + qs: { + q: query + } + })); + const fields = searchResults.response.docs; + const ids = fields.map((field: any) => field.id); + return ids; + } catch { + return []; + } + } + + public async clear() { + try { + return await rp.post(this.url + "dash/update", { + body: { + delete: { + query: "*:*" + } + }, + json: true + }); + } catch { } + } +}
\ No newline at end of file |
