From 64ba2864bc4944cdc191d1022ac649e45f6cdf2b Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 6 May 2013 14:43:55 -0400 Subject: [PATCH] Match names w/prefix and turn off highlighting. (imported from commit 4ebc4aba5d05173ad6b8176d47fdf062e23c1441) --- zephyr/static/js/search.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/zephyr/static/js/search.js b/zephyr/static/js/search.js index 8c1c5fa49a..85c9f24772 100644 --- a/zephyr/static/js/search.js +++ b/zephyr/static/js/search.js @@ -20,18 +20,28 @@ function get_person(obj) { return typeahead_helper.render_person(obj.query); } -function stream_matches_query(stream_name, q) { +function phrase_match(phrase, q) { // match "tes" to "test" and "stream test" but not "hostess" var i; - var parts = stream_name.split(' '); + q = q.toLowerCase(); + + var parts = phrase.split(' '); for (i = 0; i < parts.length; i++) { - if (parts[i].toLowerCase().indexOf(q.toLowerCase()) === 0) { + if (parts[i].toLowerCase().indexOf(q) === 0) { return true; } } return false; } +function person_matches_query(person, q) { + return phrase_match(person.full_name, q) || phrase_match(person.email, q); +} + +function stream_matches_query(stream_name, q) { + return phrase_match(stream_name, q); +} + function render_object_in_parts(obj) { // N.B. action is *not* escaped by the caller switch (obj.action) { @@ -202,11 +212,8 @@ exports.initialize = function () { highlighter: function (item) { var query = this.query; var parts = render_object_in_parts(mapped[item]); - // We provide action, not the user, so this should - // be fine from a not-needing-escaping perspective. - return parts.prefix + " " + - typeahead_helper.highlight_with_escaping(query, parts.query) - + " " + parts.suffix; + return Handlebars.Utils.escapeExpression( + parts.prefix + " " + parts.query + " " + parts.suffix); }, matcher: function (item) { var obj = mapped[item]; @@ -215,10 +222,10 @@ exports.initialize = function () { if (obj.action === 'stream') { return stream_matches_query(obj.query, this.query); } - var actual_search_term = obj.query; if (obj.action === 'private_message' || obj.action === "sender") { - actual_search_term = obj.query.full_name + ' <' + obj.query.email + '>'; + return person_matches_query(obj.query, this.query); } + var actual_search_term = obj.query; // Case-insensitive (from Bootstrap's default matcher). return (actual_search_term.toLowerCase().indexOf(this.query.toLowerCase()) !== -1); },