mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 08:09:13 -05:00
refactor and fix bug I introduced
This commit is contained in:
parent
eca2931a63
commit
201891f51f
1 changed files with 12 additions and 13 deletions
|
@ -35,20 +35,19 @@ Discourse.SearchController = Em.ArrayController.extend(Discourse.Presence, {
|
|||
if (results) {
|
||||
searchController.set('noResults', results.length === 0);
|
||||
|
||||
// Make it easy to find the results by type
|
||||
var results_hashed = {};
|
||||
results.forEach(function(r) { results_hashed[r.type] = r });
|
||||
|
||||
// Default order
|
||||
var order = ['topic', 'category', 'user'];
|
||||
results = _(order).map(function(o) { return results_hashed[o] }).without(void 0);
|
||||
|
||||
var index = 0;
|
||||
results.forEach(function(r) {
|
||||
_.each(r.results,function(item) {
|
||||
results = _(['topic', 'category', 'user'])
|
||||
.map(function(n){
|
||||
return _(results).where({type: n}).first()
|
||||
})
|
||||
.without(undefined)
|
||||
.each(function(list){
|
||||
_.each(list.results, function(item){
|
||||
item.index = index++;
|
||||
});
|
||||
});
|
||||
})
|
||||
.value();
|
||||
|
||||
searchController.set('count', index);
|
||||
searchController.set('content', results);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue