Streamline search suggestions when query has trailing space.

If you entered "stream:Denmark " in the search box, we would show
you two suggestions for "stream Denmark", despite our duplicate
detection, because we didn't canonicalize the suggestion that is
literally based off the user typed query, and so the other way
of generating the "stream Denmark" suggestion created a duplicate.

Now all the suggestions we generate are canonicalized, so the
generalized duplicate detection can work.

(imported from commit 52bf08ccf9bb2e2260ca8c20690169aead3732ab)
This commit is contained in:
Steve Howell 2013-08-06 13:08:39 -04:00
parent 349039289c
commit 3aa5930191
2 changed files with 28 additions and 3 deletions

View File

@ -206,8 +206,10 @@ function get_person_suggestions(all_people, query, prefix, operator) {
return objs;
}
function get_suggestion_based_on_query(search_string, operators) {
// We expect caller to call narrow.parse to get operators from search_string.
function get_default_suggestion(operators) {
// Here we return the canonical suggestion for the full query that the
// user typed. (The caller passes us the parsed query as "operators".)
var search_string = narrow.unparse(operators);
var description = describe(operators);
description = Handlebars.Utils.escapeExpression(description);
return {description: description, search_string: search_string};
@ -394,7 +396,7 @@ exports.get_suggestions = function (query) {
// Add an entry for narrow by operators.
var operators = narrow.parse(query);
suggestion = get_suggestion_based_on_query(query, operators);
suggestion = get_default_suggestion(operators);
result = [suggestion];
suggestions = get_special_filter_suggestions(query, operators);

View File

@ -33,6 +33,8 @@ function set_up_dependencies() {
global.recent_subjects = {};
global.util = require('js/util.js');
return search;
}
@ -131,6 +133,27 @@ var search = set_up_dependencies();
}());
(function test_whitespace_glitch() {
var query = 'stream:office '; // note trailing space
global.subs.subscribed_streams = function () {
return ['office'];
};
global.narrow.stream = function () {
return;
};
global.recent_subjects = {};
var suggestions = search.get_suggestions(query);
var expected = [
"stream:office"
];
assert.deepEqual(suggestions.strings, expected);
}());
(function test_people_suggestions() {
var query = 'te';