From ffa178cf7a6a40fabd13047474f4b4702c8d71bb Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 22 Jul 2013 23:22:51 -0400 Subject: [PATCH] Suggest "widening" searches in search autocomplete. This will allow you to always get Home from the search box, as well as easily backing out narrows. (imported from commit 68bcfc83ce0428645f4e734ae46f9589cb562a86) --- zephyr/static/js/search.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/zephyr/static/js/search.js b/zephyr/static/js/search.js index 3dec582052..f63f0bf8ce 100644 --- a/zephyr/static/js/search.js +++ b/zephyr/static/js/search.js @@ -340,6 +340,32 @@ function get_topic_suggestions(query, query_operators) { }); } +function get_operator_subset_suggestions(query, operators) { + // If you have stream:foo topic:x search:needle, then + // suggest "stream:foo" and "stream:foo topic:x" so that + // power users can use search as a quick mouse-free way + // to de-narrow. This won't cause too much clutter, as + // you generally only have 1 to 3 operators, and this gives + // N-1 additional suggestions. + if (operators.length < 1) { + return []; + } + + var i; + var suggestions = []; + + for (i = 0; i < operators.length; ++i) { + var subset = operators.slice(0, i); + var search_string = narrow.unparse(subset); + var description = describe(subset); + var suggestion = {description: description, search_string: search_string}; + suggestions.push(suggestion); + } + + return suggestions; +} + + function get_special_filter_suggestions(query, operators) { if (operators.length >= 2) { return []; @@ -403,6 +429,9 @@ exports.initialize = function () { suggestions = get_special_filter_suggestions(query, operators); result = result.concat(suggestions); + suggestions = get_operator_subset_suggestions(query, operators); + result = result.concat(suggestions); + suggestions = get_stream_suggestions(query); result = result.concat(suggestions);