浏览代码

start work on searching in comments

John R. Supplee 4 年之前
父节点
当前提交
dd163b9923
共有 4 个文件被更改,包括 22 次插入0 次删除
  1. 2 0
      client/components/main/globalSearch.js
  2. 1 0
      models/boards.js
  3. 17 0
      models/cardComments.js
  4. 2 0
      models/cards.js

+ 2 - 0
client/components/main/globalSearch.js

@@ -212,6 +212,7 @@ BlazeComponent.extendComponent({
       'operator-due': 'dueAt',
       'operator-due': 'dueAt',
       'operator-created': 'createdAt',
       'operator-created': 'createdAt',
       'operator-modified': 'modifiedAt',
       'operator-modified': 'modifiedAt',
+      'operator-comment': 'comments',
     };
     };
 
 
     const operatorMap = {};
     const operatorMap = {};
@@ -233,6 +234,7 @@ BlazeComponent.extendComponent({
       dueAt: null,
       dueAt: null,
       createdAt: null,
       createdAt: null,
       modifiedAt: null,
       modifiedAt: null,
+      comments: [],
     };
     };
 
 
     let text = '';
     let text = '';

+ 1 - 0
models/boards.js

@@ -1,3 +1,4 @@
+const escapeForRegex = require('escape-string-regexp');
 Boards = new Mongo.Collection('boards');
 Boards = new Mongo.Collection('boards');
 
 
 /**
 /**

+ 17 - 0
models/cardComments.js

@@ -1,3 +1,4 @@
+const escapeForRegex = require('escape-string-regexp');
 CardComments = new Mongo.Collection('card_comments');
 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) {
 if (Meteor.isServer) {
   // Comments are often fetched within a card, so we create an index to make these
   // Comments are often fetched within a card, so we create an index to make these
   // queries more efficient.
   // queries more efficient.

+ 2 - 0
models/cards.js

@@ -1,3 +1,5 @@
+const escapeForRegex = require('escape-string-regexp');
+
 Cards = new Mongo.Collection('cards');
 Cards = new Mongo.Collection('cards');
 
 
 // XXX To improve pub/sub performances a card document should include a
 // XXX To improve pub/sub performances a card document should include a