diff --git a/client/components/main/globalSearch.jade b/client/components/main/globalSearch.jade index 63bf3b170..1459fee7a 100644 --- a/client/components/main/globalSearch.jade +++ b/client/components/main/globalSearch.jade @@ -16,7 +16,9 @@ template(name="globalSearch") +spinner else if hasResults.get .global-search-dueat-list-wrapper - h1 Results + h1 + = resultsCount.get + | Results each card in results .global-search-card-wrapper a.minicard-wrapper.card-title(href=card.absoluteUrl) diff --git a/client/components/main/globalSearch.js b/client/components/main/globalSearch.js index 343e70801..b5003e97a 100644 --- a/client/components/main/globalSearch.js +++ b/client/components/main/globalSearch.js @@ -41,6 +41,7 @@ BlazeComponent.extendComponent({ this.hasResults = new ReactiveVar(false); this.query = new ReactiveVar(''); this.queryParams = null; + this.resultsCount = new ReactiveVar(0); // this.autorun(() => { // const handle = subManager.subscribe('globalSearch'); @@ -55,7 +56,9 @@ BlazeComponent.extendComponent({ results() { if (this.queryParams) { - return Cards.globalSearch(this.queryParams); + const cards = Cards.globalSearch(this.queryParams); + this.resultsCount.set(cards.count()); + return cards; } return []; }, diff --git a/models/cards.js b/models/cards.js index 97ed17afa..81db53f31 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1798,6 +1798,16 @@ Cards.globalSearch = queryParams => { } } + if (queryParams.text) { + const regex = new RegExp(queryParams.text, 'i'); + + selector.$or = [ + { title: regex }, + { description: regex }, + { customFields: { $elemMatch: { value: regex } } }, + ]; + } + // eslint-disable-next-line no-console console.log('selector:', selector); return Cards.find(selector, { @@ -1815,6 +1825,7 @@ Cards.globalSearch = queryParams => { colors: 1, dueAt: 1, }, + limit: 50, }); };