From 5880a017773e844212f38e913fd1ed887c23b321 Mon Sep 17 00:00:00 2001 From: John Kleinschmidt Date: Thu, 23 Mar 2017 15:10:33 -0400 Subject: [PATCH] Fix slow search Fixes HospitalRun/hospitalrun-frontend#1011 Partially fixes HospitalRun/hospitalrun-frontend#986 --- routes/20-searchproxy.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/routes/20-searchproxy.js b/routes/20-searchproxy.js index 1256d87..d888bea 100644 --- a/routes/20-searchproxy.js +++ b/routes/20-searchproxy.js @@ -1,5 +1,6 @@ var forward = require('../forward.js'); var request = require('request'); +var url = require('url'); function _createMapFunction(type, query) { var mapFunction = 'function(doc) {' + @@ -46,9 +47,14 @@ function _createMapFunction(type, query) { function slowSearch(pattern, dburl) { return function(req, res) { var model = req.url.match(pattern)[1]; + var parsedURL = url.parse(req.url, true); var searchUrl = dburl + '/main/_temp_view/?include_docs=true'; - var query = decodeURIComponent(req.url.match(pattern)[2]); - var queryParts = query.split('+OR+'); + var query = parsedURL.query.q; + var queryParts = query.split(' OR '); + var size = parsedURL.query.size; + if (size) { + searchUrl += '&limit='+size; + } var requestOptions = { body: _createMapFunction(model, queryParts), json: true,