Global search display total hits

* modify User model to store some session data for searches
* Display total hits in search results
reviewable/pr3433/r1
John R. Supplee 4 years ago
parent c11c3f9a88
commit 3214800741
  1. 4
      client/components/main/globalSearch.jade
  2. 3
      client/components/main/globalSearch.js
  3. 1
      i18n/en.i18n.json
  4. 21
      models/cards.js
  5. 27
      models/users.js

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

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

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

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

@ -311,6 +311,33 @@ Users.attachSchema(
optional: false, optional: false,
defaultValue: 'password', 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,
},
}), }),
); );

Loading…
Cancel
Save