浏览代码

Global search display total hits

* modify User model to store some session data for searches
* Display total hits in search results
John R. Supplee 4 年之前
父节点
当前提交
3214800741
共有 5 个文件被更改,包括 49 次插入7 次删除
  1. 3 1
      client/components/main/globalSearch.jade
  2. 3 0
      client/components/main/globalSearch.js
  3. 1 0
      i18n/en.i18n.json
  4. 15 6
      models/cards.js
  5. 27 0
      models/users.js

+ 3 - 1
client/components/main/globalSearch.jade

@@ -21,8 +21,10 @@ template(name="globalSearch")
             | {{_ 'no-results' }}
           else if $eq resultsCount.get 1
             | {{_ 'one-result' }}
-          else
+          else if $eq resultsCount.get totalHits.get
             | {{_ 'n-results' resultsCount.get }}
+          else
+            | {{_ 'n-of-n-results' resultsCount.get totalHits.get }}
         if queryErrors.get
           div
             each msg in errorMessages

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

@@ -42,6 +42,7 @@ BlazeComponent.extendComponent({
     this.query = new ReactiveVar('');
     this.queryParams = null;
     this.resultsCount = new ReactiveVar(0);
+    this.totalHits = new ReactiveVar(0);
     this.queryErrors = new ReactiveVar(null);
     Meteor.subscribe('setting');
   },
@@ -50,7 +51,9 @@ BlazeComponent.extendComponent({
     if (this.queryParams) {
       const results = Cards.globalSearch(this.queryParams);
       // eslint-disable-next-line no-console
+      console.log('count:', results.count);
       // console.log('errors:', results.errors);
+      this.totalHits.set(Meteor.user().sessionData.totalHits);
       this.resultsCount.set(results.cards.count());
       this.queryErrors.set(results.errors);
       return results.cards;

+ 1 - 0
i18n/en.i18n.json

@@ -872,6 +872,7 @@
   "globalSearch-title": "Search All Boards",
   "one-results": "One Result",
   "n-results": "%s Results",
+  "n-of-n-results": "%s of %s Results",
   "operator-board": "board",
   "operator-board-abbrev": "b",
   "operator-swimlane": "swimlane",

+ 15 - 6
models/cards.js

@@ -1733,7 +1733,7 @@ Cards.mutations({
 Cards.globalSearch = queryParams => {
   const userId = Meteor.userId();
   // eslint-disable-next-line no-console
-  console.log('userId:', userId);
+  // console.log('userId:', userId);
 
   const errors = {
     notFound: {
@@ -1756,7 +1756,7 @@ Cards.globalSearch = queryParams => {
     const queryBoards = [];
     queryParams.boards.forEach(query => {
       const boards = Boards.userSearch(userId, {
-        title: query,
+        title: new RegExp(query, 'i'),
       });
       if (boards.count()) {
         boards.forEach(board => {
@@ -1774,7 +1774,7 @@ Cards.globalSearch = queryParams => {
     const querySwimlanes = [];
     queryParams.swimlanes.forEach(query => {
       const swimlanes = Swimlanes.find({
-        title: query,
+        title: new RegExp(query, 'i'),
       });
       if (swimlanes.count()) {
         swimlanes.forEach(swim => {
@@ -1792,7 +1792,7 @@ Cards.globalSearch = queryParams => {
     const queryLists = [];
     queryParams.lists.forEach(query => {
       const lists = Lists.find({
-        title: query,
+        title: new RegExp(query, 'i'),
       });
       if (lists.count()) {
         lists.forEach(list => {
@@ -1885,7 +1885,7 @@ Cards.globalSearch = queryParams => {
   }
 
   // eslint-disable-next-line no-console
-  console.log('selector:', selector);
+  // console.log('selector:', selector);
   const cards = Cards.find(selector, {
     fields: {
       _id: 1,
@@ -1906,7 +1906,16 @@ Cards.globalSearch = queryParams => {
   });
 
   // eslint-disable-next-line no-console
-  console.log('count:', cards.count());
+  // console.log('count:', cards.count());
+
+  if (Meteor.isServer) {
+    Users.update(userId, {
+      $set: {
+        'sessionData.totalHits': cards.count(),
+        'sessionData.lastHit': cards.count() > 50 ? 50 : cards.count(),
+      },
+    });
+  }
   return { cards, errors };
 };
 

+ 27 - 0
models/users.js

@@ -311,6 +311,33 @@ Users.attachSchema(
       optional: false,
       defaultValue: 'password',
     },
+    sessionData: {
+      /**
+       * profile settings
+       */
+      type: Object,
+      optional: true,
+      // eslint-disable-next-line consistent-return
+      autoValue() {
+        if (this.isInsert && !this.isSet) {
+          return {};
+        }
+      },
+    },
+    'sessionData.totalHits': {
+      /**
+       * Total hits from last search
+       */
+      type: Number,
+      optional: true,
+    },
+    'sessionData.lastHit': {
+      /**
+       * last hit that was returned
+       */
+      type: Number,
+      optional: true,
+    },
   }),
 );