11'use strict' ;
22
3- var path = require ( 'path' ) ;
3+ var path = require ( 'path' ) ;
44var routes = require ( '../../../core/server/controllers/core.routes.controller' ) ;
55var policy = require ( '../../../core/server/controllers/core.policy.controller' ) ;
66var DocumentController = require ( path . resolve ( './modules/documents/server/controllers/core.document.controller' ) ) ;
77var ProjectController = require ( path . resolve ( './modules/projects/server/controllers/project.controller' ) ) ;
88var OrgController = require ( path . resolve ( './modules/organizations/server/controllers/organization.controller' ) ) ;
9- var _ = require ( 'lodash' ) ;
9+ var _ = require ( 'lodash' ) ;
1010var ObjectId = require ( 'mongodb' ) . ObjectId ;
1111
1212module . 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