search.js: Simplify get_stream_suggestions

(imported from commit 0fd00a2f22cc0241945767b4bf1151b811f00a63)
This commit is contained in:
Steve Howell
2013-07-16 17:46:45 -04:00
parent 6a8a403cc9
commit c515ad4cbb

View File

@@ -126,20 +126,15 @@ function get_stream_suggestions(query, max_num) {
return stream_matches_query(stream, query); return stream_matches_query(stream, query);
}); });
streams = typeahead_helper.sorter(query, streams);
streams = streams.slice(0, max_num);
var objs = $.map(streams, function (stream) { var objs = $.map(streams, function (stream) {
return {query: stream};
});
objs = typeahead_helper.sorter(query, objs, get_query);
objs = objs.slice(0, max_num);
$.each(objs, function (idx, obj) {
var prefix = 'Narrow to stream'; var prefix = 'Narrow to stream';
var stream = obj.query; var highlighted_stream = typeahead_helper.highlight_query_in_phrase(query, stream);
stream = typeahead_helper.highlight_query_in_phrase(query, stream); var description = prefix + ' ' + highlighted_stream;
obj.description = prefix + ' ' + stream; var search_string = 'stream:' + stream;
obj.search_string = 'stream:' + obj.query; return {description: description, search_string: search_string};
}); });
return objs; return objs;