FEATURE: search by user id or category id
FIX: more search results work if you open in new tab FIX: carry context to full page search
This commit is contained in:
parent
a2398c07f7
commit
4a5a2d869e
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
{{component resultType.componentName results=resultType.results term=term}}
|
||||
</ul>
|
||||
<div class="no-results">
|
||||
{{#if resultType.moreUrl}}
|
||||
<a href="{{resultType.moreUrl}}" class="filter">{{i18n "show_more"}} {{fa-icon "chevron-down"}}</a>
|
||||
{{/if}}
|
||||
{{#if resultType.more}}
|
||||
<a href class="filter" {{action "moreOfType" resultType.type bubbles=false}}>{{i18n "show_more"}} {{fa-icon "chevron-down"}}</a>
|
||||
{{/if}}
|
||||
|
|
|
@ -6,7 +6,7 @@ export default Discourse.View.extend({
|
|||
keyDown: function(e){
|
||||
var term = this.get('controller.term');
|
||||
if (e.which === 13 && term && term.length > 2) {
|
||||
this.get('controller').send('moreOfType', 'topic');
|
||||
this.get('controller').send('fullSearch');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -214,12 +214,12 @@ class Search
|
|||
end
|
||||
|
||||
advanced_filter(/category:(.+)/) do |posts,match|
|
||||
category_id = Category.find_by('name ilike ?', match).try(:id)
|
||||
category_id = Category.find_by('name ilike ? OR id = ?', match, match.to_i).try(:id)
|
||||
posts.where("topics.category_id = ?", category_id)
|
||||
end
|
||||
|
||||
advanced_filter(/user:(.+)/) do |posts,match|
|
||||
user_id = User.find_by('username_lower = ?', match.downcase).try(:id)
|
||||
user_id = User.find_by('username_lower = ? OR id = ?', match.downcase, match.to_i).try(:id)
|
||||
posts.where("posts.user_id = #{user_id}")
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue