diff options
Diffstat (limited to 'src/server/ApiManagers/SearchManager.ts')
-rw-r--r-- | src/server/ApiManagers/SearchManager.ts | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/src/server/ApiManagers/SearchManager.ts b/src/server/ApiManagers/SearchManager.ts index 7afecbb18..0e794fed6 100644 --- a/src/server/ApiManagers/SearchManager.ts +++ b/src/server/ApiManagers/SearchManager.ts @@ -4,13 +4,28 @@ import { Search } from "../Search"; const findInFiles = require('find-in-files'); import * as path from 'path'; import { pathToDirectory, Directory } from "./UploadManager"; +import { command_line, addBeforeExitHandler } from "../ActionUtilities"; +import request = require('request-promise'); +import { red, green, yellow, cyan } from "colors"; -export default class SearchManager extends ApiManager { +export class SearchManager extends ApiManager { protected initialize(register: Registration): void { register({ method: Method.GET, + subscription: "/startSolr", + onValidation: async ({ res }) => res.send((await SolrManager.SetRunning(true)) ? "Successfully started Solr!" : "Uh oh! Check the console for the error that occurred while starting Solr") + }); + + register({ + method: Method.GET, + subscription: "/stopSolr", + onValidation: async ({ res }) => res.send((await SolrManager.SetRunning(false)) ? "Successfully stopped Solr!" : "Uh oh! Check the console for the error that occurred while stopping Solr") + }); + + register({ + method: Method.GET, subscription: "/textsearch", onValidation: async ({ req, res }) => { const q = req.query.q; @@ -46,4 +61,36 @@ export default class SearchManager extends ApiManager { } +} + +export namespace SolrManager { + + export async function initializeSolr() { + console.log(cyan("\nInspecting Solr status...")); + try { + await request("http://localhost:8983"); + console.log(green('Solr already running\n')); + } catch (e) { + console.log(cyan('Initializing Solr...')); + await SolrManager.SetRunning(true); + } finally { + addBeforeExitHandler(async () => SolrManager.SetRunning(false)); + } + } + + export async function SetRunning(status: boolean): Promise<boolean> { + const args = status ? "start" : "stop -p 8983"; + console.log(`Solr management: trying to ${args}`); + try { + console.log(await command_line(`solr.cmd ${args}`, "../../solr-8.1.1/bin")); + return true; + } catch (e) { + console.log(red(`Solr management error: unable to ${args}`)); + if (status) { + process.exit(0); + } + return false; + } + } + }
\ No newline at end of file |