diff --git a/client/components/main/globalSearch.js b/client/components/main/globalSearch.js index 69ccad64e..796a2562d 100644 --- a/client/components/main/globalSearch.js +++ b/client/components/main/globalSearch.js @@ -212,6 +212,7 @@ BlazeComponent.extendComponent({ 'operator-due': 'dueAt', 'operator-created': 'createdAt', 'operator-modified': 'modifiedAt', + 'operator-comment': 'comments', }; const operatorMap = {}; @@ -233,6 +234,7 @@ BlazeComponent.extendComponent({ dueAt: null, createdAt: null, modifiedAt: null, + comments: [], }; let text = ''; diff --git a/models/boards.js b/models/boards.js index 35b00ee75..f4f0d8042 100644 --- a/models/boards.js +++ b/models/boards.js @@ -1,3 +1,4 @@ +const escapeForRegex = require('escape-string-regexp'); Boards = new Mongo.Collection('boards'); /** diff --git a/models/cardComments.js b/models/cardComments.js index 39477e14a..ecfbc7516 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -1,3 +1,4 @@ +const escapeForRegex = require('escape-string-regexp'); CardComments = new Mongo.Collection('card_comments'); /** @@ -109,6 +110,22 @@ function commentCreation(userId, doc) { }); } +CardComments.textSearch = (userId, textArray) => { + const selector = { + boardId: { $in: Boards.userBoardIds() }, + $and: [], + }; + + for (const text of textArray) { + selector.$and.push({ text: new RegExp(escapeForRegex(text)) }); + } + + // eslint-disable-next-line no-console + console.log(textArray); + + return CardComments.find(selector); +}; + if (Meteor.isServer) { // Comments are often fetched within a card, so we create an index to make these // queries more efficient. diff --git a/models/cards.js b/models/cards.js index caacc93be..3457e5fc9 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1,3 +1,5 @@ +const escapeForRegex = require('escape-string-regexp'); + Cards = new Mongo.Collection('cards'); // XXX To improve pub/sub performances a card document should include a