Handle negated person-related operators in search suggestions.

(imported from commit e045a0910ff59d9b8569c5ba3b3b644fe2d7dad7)
This commit is contained in:
Steve Howell
2014-03-04 17:22:15 -05:00
parent e5e0ba9e7c
commit 89f10d7e7a
2 changed files with 32 additions and 6 deletions

View File

@@ -96,7 +96,9 @@ function get_private_suggestions(all_people, operators, person_operator_matches)
return [];
}
var query, matching_operator;
var query;
var matching_operator;
var negated = false;
if (operators.length === 0) {
query = '';
@@ -112,6 +114,7 @@ function get_private_suggestions(all_people, operators, person_operator_matches)
if (operator === item) {
query = operators[0].operand;
matching_operator = item;
negated = operators[0].negated;
}
});
}
@@ -134,16 +137,21 @@ function get_private_suggestions(all_people, operators, person_operator_matches)
// Take top 15 people, since they're ordered by pm_recipient_count.
people = people.slice(0, 15);
var prefix = Filter.operator_to_prefix(matching_operator);
var prefix = Filter.operator_to_prefix(matching_operator, negated);
var suggestions = _.map(people, function (person) {
var name = highlight_person(query, person);
var description = prefix + ' ' + name;
var term = {
operator: matching_operator,
operand: person.email
operand: person.email,
negated: negated
};
var search_string = Filter.unparse([term]);
var name = highlight_person(query, person);
var description = prefix + ' ' + name;
var terms = [term];
if (negated) {
terms = [{operator: 'is', operand: 'private'}, term];
}
var search_string = Filter.unparse(terms);
return {description: description, search_string: search_string};
});

View File

@@ -119,6 +119,15 @@ set_global('narrow', {});
];
assert.deepEqual(suggestions.strings, expected);
query = '-pm-with:t';
suggestions = search.get_suggestions(query);
expected = [
"-pm-with:t",
"is:private -pm-with:ted@zulip.com",
"is:private"
];
assert.deepEqual(suggestions.strings, expected);
query = 'pm-with:ted@zulip.com';
suggestions = search.get_suggestions(query);
expected = [
@@ -145,6 +154,15 @@ set_global('narrow', {});
];
assert.deepEqual(suggestions.strings, expected);
query = '-sender:te';
suggestions = search.get_suggestions(query);
expected = [
"-sender:te",
"is:private -sender:ted@zulip.com",
"is:private"
];
assert.deepEqual(suggestions.strings, expected);
query = 'sender:ted@zulip.com';
suggestions = search.get_suggestions(query);
expected = [