From 60dab77cf4e227908711726dd4e7db78bff48911 Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Sun, 15 May 2016 21:25:59 +0200 Subject: [PATCH] adding keyword and place to search and instant serach --- backend/model/mongoose/MongoSearchManager.ts | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/model/mongoose/MongoSearchManager.ts b/backend/model/mongoose/MongoSearchManager.ts index cdd11a02..0b973524 100644 --- a/backend/model/mongoose/MongoSearchManager.ts +++ b/backend/model/mongoose/MongoSearchManager.ts @@ -71,10 +71,14 @@ export class MongoSearchManager implements ISearchManager { let result:SearchResult = new SearchResult(); result.searchText = text; PhotoModel.find({ - name: { - $regex: text, - $options: "i" - } + $or: [ + {name: {$regex: text, $options: "i"}}, + {"metadata.positionData.city": {$regex: text, $options: "i"}}, + {"metadata.positionData.state": {$regex: text, $options: "i"}}, + {"metadata.positionData.country": {$regex: text, $options: "i"}}, + {"metadata.keywords": {$regex: text, $options: "i"}} + ] + }).populate('directory', 'name path').exec((err, res:Array) => { if (err || !res) { return cb(err, null); @@ -103,10 +107,14 @@ export class MongoSearchManager implements ISearchManager { let result:SearchResult = new SearchResult(); result.searchText = text; PhotoModel.find({ - name: { - $regex: text, - $options: "i" - } + $or: [ + {name: {$regex: text, $options: "i"}}, + {"metadata.positionData.city": {$regex: text, $options: "i"}}, + {"metadata.positionData.state": {$regex: text, $options: "i"}}, + {"metadata.positionData.country": {$regex: text, $options: "i"}}, + {"metadata.keywords": {$regex: text, $options: "i"}} + ] + }).limit(10).populate('directory', 'name path').exec((err, res:Array) => { if (err || !res) { return cb(err, null);