Skip to content
This repository was archived by the owner on Jan 7, 2020. It is now read-only.

Commit b04d8da

Browse files
committed
MEM-598 Ensure text searches are on entire phrase, and handle result properly.
1 parent 81d5580 commit b04d8da

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

modules/search/server/routes/search.routes.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

3-
var path = require ('path');
3+
var path = require ('path');
44
var routes = require('../../../core/server/controllers/core.routes.controller');
55
var policy = require('../../../core/server/controllers/core.policy.controller');
66
var DocumentController = require (path.resolve('./modules/documents/server/controllers/core.document.controller'));
77
var ProjectController = require (path.resolve('./modules/projects/server/controllers/project.controller'));
88
var OrgController = require (path.resolve('./modules/organizations/server/controllers/organization.controller'));
9-
var _ = require ('lodash');
9+
var _ = require ('lodash');
1010
var ObjectId = require('mongodb').ObjectId;
1111

1212
module.exports = function (app) {
@@ -45,7 +45,7 @@ module.exports = function (app) {
4545
}
4646
// owner filtering (strings are coming in)
4747
if (req.query.ownership) {
48-
projectQuery = _.extend (projectQuery, { $text: { $search: req.query.ownership }});
48+
projectQuery = _.extend (projectQuery, { $text: { $search: '\"' + req.query.ownership + '\"' }});
4949
// console.log("ownership query:", projectQuery);
5050
}
5151
if (req.query.page) {
@@ -57,7 +57,7 @@ module.exports = function (app) {
5757
// We're filtering our searches on project and orgs
5858
var orgQ = {};
5959
if (req.query.proponentstring) {
60-
orgQ = { $text: { $search: req.query.proponentstring }};
60+
orgQ = { $text: { $search: '\"' + req.query.proponentstring + '\"' }};
6161
}
6262
return o.findMany(orgQ)
6363
.then(function (orgs) {
@@ -68,9 +68,12 @@ module.exports = function (app) {
6868
if (ops.length > 0) {
6969
projectQuery = _.extend (projectQuery, { "proponent": {$in : ops}});
7070
}
71-
return;
71+
return ops.length;
7272
})
73-
.then(function () {
73+
.then(function (opsCount) {
74+
// console.log("opsCount: ", opsCount);
75+
// If no proponents then we're done.
76+
if (opsCount === 0) return [];
7477
// console.log("projectQuery: ", projectQuery);
7578
return p.findMany(projectQuery,"_id type name code ownership proponent");
7679
})
@@ -164,7 +167,7 @@ module.exports = function (app) {
164167
}
165168
// owner filtering (strings are coming in)
166169
if (req.query.ownership) {
167-
projectQuery = _.extend (projectQuery, { $text: { $search: req.query.ownership }});
170+
projectQuery = _.extend (projectQuery, { $text: { $search: '\"' + req.query.ownership + '\"' }});
168171
// console.log("ownership query:", projectQuery);
169172
}
170173
if (req.query.page) {
@@ -176,7 +179,7 @@ module.exports = function (app) {
176179
// We're filtering our searches on project and orgs
177180
var orgQ = {};
178181
if (req.query.proponentstring) {
179-
orgQ = { $text: { $search: req.query.proponentstring }};
182+
orgQ = { $text: { $search: '\"' + req.query.proponentstring + '\"' }};
180183
}
181184
return o.findMany(orgQ)
182185
.then(function (orgs) {
@@ -187,9 +190,12 @@ module.exports = function (app) {
187190
if (ops.length > 0) {
188191
projectQuery = _.extend (projectQuery, { "proponent": {$in : ops}});
189192
}
190-
return;
193+
return ops.length;
191194
})
192-
.then(function () {
195+
.then(function (opsCount) {
196+
// console.log("opsCount: ", opsCount);
197+
// If no proponents then we're done.
198+
if (opsCount === 0) return [];
193199
// console.log("projectQuery: ", projectQuery);
194200
return p.findMany(projectQuery,"_id type name code ownership proponent");
195201
})

0 commit comments

Comments
 (0)