search.js: extract get_suggestion_based_on_query

(imported from commit 6c242fa9dd9ad9f73976fe9b1265521610326c5d)
This commit is contained in:
Steve Howell 2013-07-16 18:41:54 -04:00
parent c9ec96cab3
commit 3af905db66
1 changed files with 9 additions and 5 deletions

View File

@ -150,6 +150,13 @@ function get_person_suggestions(all_people, query, prefix, operator, max_num) {
return objs;
}
function get_suggestion_based_on_query(search_string, operators) {
// We expect caller to call narrow.parse to get operators from search_string.
var description = describe(operators);
description = Handlebars.Utils.escapeExpression(description);
return {description: description, search_string: search_string};
}
exports.initialize = function () {
$( "#search_query" ).typeahead({
source: function (query, process) {
@ -158,11 +165,8 @@ exports.initialize = function () {
// Add an entry for narrow by operators.
var operators = narrow.parse(query);
if (operators.length !== 0) {
var obj = {query: query};
obj.search_string = query;
var description = describe(operators);
obj.description = Handlebars.Utils.escapeExpression(description);
result = [obj];
var suggestion = get_suggestion_based_on_query(query, operators);
result = [suggestion];
} else {
return [];
}