diff options
| author | tschicke-brown <tyler_schicke@brown.edu> | 2019-05-09 20:31:52 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-09 20:31:52 -0400 |
| commit | 30aaf7c496eb4cbebac1e4cf9e0695cd286c63f2 (patch) | |
| tree | fe887b7862ed82b7b59d657146ea8e627174ece7 /src/server/Search.ts | |
| parent | 6691c55623fff5194b5fd1a830096e3925281301 (diff) | |
| parent | b18aec5d4b07bbc859a5b1b2d22ca3bd92ca53cd (diff) | |
Merge pull request #130 from browngraphicslab/new_search
New search
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..1d8cfdcf0 --- /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 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 rp.post(this.url + "dash/update", { + body: { + delete: { + query: "*:*" + } + }, + json: true + }); + } catch { } + } +}
\ No newline at end of file |
