From 103625d12381afebc9b0e06597cad30d3a3ae007 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Fri, 19 Jul 2013 17:04:05 -0400 Subject: [PATCH] Prevent duplicate search suggestions. (imported from commit b1fb4d40ee76394ee8eee5aec4e292a408806667) --- zephyr/static/js/search.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/zephyr/static/js/search.js b/zephyr/static/js/search.js index 8a4c9d0576..d2cafd0f2d 100644 --- a/zephyr/static/js/search.js +++ b/zephyr/static/js/search.js @@ -352,12 +352,17 @@ exports.initialize = function () { suggestions = get_topic_suggestions(query, operators); result = result.concat(suggestions); - // We can't send typeahead objects, only strings. + // We can't send typeahead objects, only strings, so we have to create a map + // back to our objects, and we also filter duplicates here. search_object = {}; + var final_result = []; $.each(result, function (idx, obj) { - search_object[obj.search_string] = obj; + if (!search_object[obj.search_string]) { + search_object[obj.search_string] = obj; + final_result.push(obj); + } }); - return $.map(result, function (obj) { + return $.map(final_result, function (obj) { return obj.search_string; }); },