diff options
author | Monika Hedman <monika_hedman@brown.edu> | 2019-04-30 16:17:39 -0400 |
---|---|---|
committer | Monika Hedman <monika_hedman@brown.edu> | 2019-04-30 16:17:39 -0400 |
commit | df9fa3e362a6bdd616bc0b46ef9b425cfc5a010d (patch) | |
tree | 12d9707bb7035b7b901a22bb1ae2c4357113b385 /src/server/Search.ts | |
parent | 53e183fbc116c406ca86889a9fb3e2de61520b60 (diff) |
before pull
Diffstat (limited to 'src/server/Search.ts')
-rw-r--r-- | src/server/Search.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/server/Search.ts b/src/server/Search.ts new file mode 100644 index 000000000..7d8602346 --- /dev/null +++ b/src/server/Search.ts @@ -0,0 +1,38 @@ +import * as rp from 'request-promise'; +import { Database } from './database'; + +export class Search { + public static Instance = new Search(); + private url = 'http://localhost:8983/solr/'; + + public updateDocument(document: any): rp.RequestPromise { + return rp.post(this.url + "dash/update/json/docs", { + headers: { 'content-type': 'application/json' }, + body: JSON.stringify(document) + }); + } + + public async search(query: string) { + 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); + const docs = await Database.Instance.searchQuery(ids); + const docIds = docs.map((doc: any) => doc._id); + return docIds; + } + + public async clear() { + return rp.post(this.url + "dash/update", { + body: { + delete: { + query: "*:*" + } + }, + json: true + }); + } +}
\ No newline at end of file |