Handle negated topics in search suggestions.

Typing "stream:foo -topic:b" leads to "stream:foo -topic:bar" properly
as a suggestion now.

(imported from commit bb0acf52744f7b13977a3db5d3c130d1402b09b7)
This commit is contained in:
Steve Howell 2014-03-04 16:52:13 -05:00
parent 30f9fed766
commit e5e0ba9e7c
2 changed files with 21 additions and 2 deletions

View File

@ -195,6 +195,7 @@ function get_topic_suggestions(query_operators) {
var last_term = query_operators.slice(-1)[0];
var operator = Filter.canonicalize_operator(last_term.operator);
var operand = last_term.operand;
var negated = (operator === 'topic') && (last_term.negated);
var stream;
var guess;
var filter;
@ -277,7 +278,7 @@ function get_topic_suggestions(query_operators) {
topics.sort();
return _.map(topics, function (topic) {
var topic_term = {operator: 'topic', operand: topic};
var topic_term = {operator: 'topic', operand: topic, negated: negated};
var operators = query_operators.concat([topic_term]);
var search_string = Filter.unparse(operators);
var description = Filter.describe(operators);

View File

@ -16,7 +16,9 @@ add_dependencies({
var search = require('js/search_suggestion.js');
set_global('feature_flags', {});
set_global('feature_flags', {
negated_search: true
});
set_global('page_params', {
email: 'bob@zulip.com'
});
@ -262,6 +264,22 @@ set_global('narrow', {});
'stream:devel'
];
assert.deepEqual(suggestions.strings, expected);
suggestions = search.get_suggestions('stream:devel -topic:');
expected = [
'stream:devel -topic:',
'stream:devel -topic:REXX',
'stream:devel'
];
assert.deepEqual(suggestions.strings, expected);
suggestions = search.get_suggestions('-topic:te');
expected = [
'-topic:te',
'stream:office -topic:team',
'stream:office -topic:test'
];
assert.deepEqual(suggestions.strings, expected);
}());
(function test_whitespace_glitch() {