From ec7a5c0ea5dacab76c061bbbab31bb519f042850 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 15 Jul 2013 17:59:47 -0400 Subject: [PATCH] search.js: Simplify operators suggestion (imported from commit 55f84b69be5e8f75a8e0ab5a7a00ba6f88873db8) --- zephyr/static/js/search.js | 39 +++----------------------------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/zephyr/static/js/search.js b/zephyr/static/js/search.js index 0a9dfc7d45..4ac059d298 100644 --- a/zephyr/static/js/search.js +++ b/zephyr/static/js/search.js @@ -262,6 +262,8 @@ exports.initialize = function () { // Delete our old search queries (one for find-in-page, one for operators) delete mapped[labels.shift()]; // Operators + var result = []; + // Add an entry for narrow by operators. var operators = narrow.parse(query); if (operators.length !== 0) { @@ -269,46 +271,11 @@ exports.initialize = function () { var label = get_label(obj); mapped[label] = obj; obj.label = label; - labels.unshift(label); + result = [label]; } else { return []; } - var items = $.grep(labels, function (label) { - var obj = mapped[label]; - if (obj.disabled) - return false; - if (obj.action === 'stream') { - return false; - } - if (obj.action === 'private_message' || obj.action === "sender") { - return false; - } - var actual_search_term = obj.query; - // Case-insensitive (from Bootstrap's default matcher). - return (actual_search_term.toLowerCase().indexOf(query.toLowerCase()) !== -1); - }); - - var objects_by_action = {}; - var result = []; - - $.each(items, function (idx, elt) { - var obj = mapped[elt]; - if (objects_by_action[obj.action] === undefined) - objects_by_action[obj.action] = []; - objects_by_action[obj.action].push(obj); - }); - - $.each(['operators'], function (idx, action) { - var objs = objects_by_action[action]; - if (!objs) - return; - objs = objs.slice(0, 4); - var labels = $.map(objs, function (obj) { return obj.label;}); - - result = result.concat(labels); - }); - var stream_suggestions = get_stream_suggestions(query).slice(0,4); result = result.concat(stream_suggestions);