Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Commit

Permalink
Fix slow search
Browse files Browse the repository at this point in the history
  • Loading branch information
jkleinsc committed Mar 23, 2017
1 parent d25af74 commit 5880a01
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions routes/20-searchproxy.js
Original file line number Diff line number Diff line change
@@ -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) {' +
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5880a01

Please sign in to comment.