Prevent duplicate search suggestions.

(imported from commit b1fb4d40ee76394ee8eee5aec4e292a408806667)
This commit is contained in:
Steve Howell 2013-07-19 17:04:05 -04:00
parent 04e1567ef8
commit 103625d123
1 changed files with 8 additions and 3 deletions

View File

@ -352,12 +352,17 @@ exports.initialize = function () {
suggestions = get_topic_suggestions(query, operators); suggestions = get_topic_suggestions(query, operators);
result = result.concat(suggestions); 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 = {}; search_object = {};
var final_result = [];
$.each(result, function (idx, obj) { $.each(result, function (idx, obj) {
if (!search_object[obj.search_string]) {
search_object[obj.search_string] = obj; 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; return obj.search_string;
}); });
}, },