diff --git a/app/assets/javascripts/discourse/controllers/search.js.es6 b/app/assets/javascripts/discourse/controllers/search.js.es6 index 2bf8183041..9c44f0b2a9 100644 --- a/app/assets/javascripts/discourse/controllers/search.js.es6 +++ b/app/assets/javascripts/discourse/controllers/search.js.es6 @@ -23,6 +23,30 @@ export default Em.Controller.extend(Presence, { } }.observes('searchContext'), + fullSearchUrlRelative: function(){ + + if (this.get('searchContextEnabled') && this.get('searchContext.type') === 'topic') { + return null; + } + + var url = '/search?q=' + encodeURIComponent(this.get('term')); + var searchContext = this.get('searchContext'); + + if (this.get('searchContextEnabled') && searchContext) { + url += encodeURIComponent(" " + searchContext.type + ":" + searchContext.id); + } + + return url; + + }.property('searchContext','term','searchContextEnabled'), + + fullSearchUrl: function(){ + var url = this.get('fullSearchUrlRelative'); + if (url) { + return Discourse.getURL(url); + } + }.property('fullSearchUrlRelative'), + searchContextDescription: function(){ var ctx = this.get('searchContext'); if (ctx) { @@ -68,7 +92,8 @@ export default Em.Controller.extend(Presence, { searchForTerm(term, { typeFilter: typeFilter, - searchContext: context + searchContext: context, + fullSearchUrl: this.get('fullSearchUrl') }).then(function(results) { self.setProperties({ noResults: !results, content: results }); self.set('loading', false); @@ -87,15 +112,15 @@ export default Em.Controller.extend(Presence, { }.observes('term'), actions: { - moreOfType: function(type) { - if (type === 'topic' && (!this.get('searchContextEnabled') || this.get('searchContext.type') !== 'topic')) { - var term = this.get('term'); - // TODO in topic and in category special handling - Discourse.URL.routeTo("/search?q=" + encodeURIComponent(term)); - } else { - this.set('typeFilter', type); + fullSearch: function() { + var url = this.get('fullSearchUrlRelative'); + if (url) { + Discourse.URL.routeTo(url); } }, + moreOfType: function(type) { + this.set('typeFilter', type); + }, cancelType: function() { this.cancelTypeFilter(); diff --git a/app/assets/javascripts/discourse/lib/search-for-term.js.es6 b/app/assets/javascripts/discourse/lib/search-for-term.js.es6 index 478b1bc6e9..a63eacad71 100644 --- a/app/assets/javascripts/discourse/lib/search-for-term.js.es6 +++ b/app/assets/javascripts/discourse/lib/search-for-term.js.es6 @@ -51,12 +51,19 @@ function searchForTerm(term, opts) { [['topic','posts'],['user','users'],['category','categories']].forEach(function(pair){ const type = pair[0], name = pair[1]; if (results[name].length > 0) { - results.resultTypes.push({ + var result = { results: results[name], componentName: "search-result-" + ((opts.searchContext && opts.searchContext.type === 'topic' && type === 'topic') ? 'post' : type), type, more: r['more_' + name] - }); + }; + + if (result.more && name === "posts" && opts.fullSearchUrl) { + result.more = false; + result.moreUrl = opts.fullSearchUrl; + } + + results.resultTypes.push(result); } }); diff --git a/app/assets/javascripts/discourse/templates/search.hbs b/app/assets/javascripts/discourse/templates/search.hbs index a3c58a3add..fb062f0259 100644 --- a/app/assets/javascripts/discourse/templates/search.hbs +++ b/app/assets/javascripts/discourse/templates/search.hbs @@ -24,6 +24,9 @@ {{component resultType.componentName results=resultType.results term=term}}