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'),
|
}.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(){
|
searchContextDescription: function(){
|
||||||
var ctx = this.get('searchContext');
|
var ctx = this.get('searchContext');
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
|
@ -68,7 +92,8 @@ export default Em.Controller.extend(Presence, {
|
||||||
|
|
||||||
searchForTerm(term, {
|
searchForTerm(term, {
|
||||||
typeFilter: typeFilter,
|
typeFilter: typeFilter,
|
||||||
searchContext: context
|
searchContext: context,
|
||||||
|
fullSearchUrl: this.get('fullSearchUrl')
|
||||||
}).then(function(results) {
|
}).then(function(results) {
|
||||||
self.setProperties({ noResults: !results, content: results });
|
self.setProperties({ noResults: !results, content: results });
|
||||||
self.set('loading', false);
|
self.set('loading', false);
|
||||||
|
@ -87,15 +112,15 @@ export default Em.Controller.extend(Presence, {
|
||||||
}.observes('term'),
|
}.observes('term'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
moreOfType: function(type) {
|
fullSearch: function() {
|
||||||
if (type === 'topic' && (!this.get('searchContextEnabled') || this.get('searchContext.type') !== 'topic')) {
|
var url = this.get('fullSearchUrlRelative');
|
||||||
var term = this.get('term');
|
if (url) {
|
||||||
// TODO in topic and in category special handling
|
Discourse.URL.routeTo(url);
|
||||||
Discourse.URL.routeTo("/search?q=" + encodeURIComponent(term));
|
|
||||||
} else {
|
|
||||||
this.set('typeFilter', type);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
moreOfType: function(type) {
|
||||||
|
this.set('typeFilter', type);
|
||||||
|
},
|
||||||
|
|
||||||
cancelType: function() {
|
cancelType: function() {
|
||||||
this.cancelTypeFilter();
|
this.cancelTypeFilter();
|
||||||
|
|
|
@ -51,12 +51,19 @@ function searchForTerm(term, opts) {
|
||||||
[['topic','posts'],['user','users'],['category','categories']].forEach(function(pair){
|
[['topic','posts'],['user','users'],['category','categories']].forEach(function(pair){
|
||||||
const type = pair[0], name = pair[1];
|
const type = pair[0], name = pair[1];
|
||||||
if (results[name].length > 0) {
|
if (results[name].length > 0) {
|
||||||
results.resultTypes.push({
|
var result = {
|
||||||
results: results[name],
|
results: results[name],
|
||||||
componentName: "search-result-" + ((opts.searchContext && opts.searchContext.type === 'topic' && type === 'topic') ? 'post' : type),
|
componentName: "search-result-" + ((opts.searchContext && opts.searchContext.type === 'topic' && type === 'topic') ? 'post' : type),
|
||||||
type,
|
type,
|
||||||
more: r['more_' + name]
|
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}}
|
{{component resultType.componentName results=resultType.results term=term}}
|
||||||
</ul>
|
</ul>
|
||||||
<div class="no-results">
|
<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}}
|
{{#if resultType.more}}
|
||||||
<a href class="filter" {{action "moreOfType" resultType.type bubbles=false}}>{{i18n "show_more"}} {{fa-icon "chevron-down"}}</a>
|
<a href class="filter" {{action "moreOfType" resultType.type bubbles=false}}>{{i18n "show_more"}} {{fa-icon "chevron-down"}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -6,7 +6,7 @@ export default Discourse.View.extend({
|
||||||
keyDown: function(e){
|
keyDown: function(e){
|
||||||
var term = this.get('controller.term');
|
var term = this.get('controller.term');
|
||||||
if (e.which === 13 && term && term.length > 2) {
|
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
|
end
|
||||||
|
|
||||||
advanced_filter(/category:(.+)/) do |posts,match|
|
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)
|
posts.where("topics.category_id = ?", category_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
advanced_filter(/user:(.+)/) do |posts,match|
|
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}")
|
posts.where("posts.user_id = #{user_id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue