search: Do not show default suggestion for `has` operator.

Fixes #9384.
Default suggestion e.g `messages with one or more abc` as a suggestion
for `has:abc` is not shown in a new suggestion. But if the has operator
is already present before any other operator, the default message text
will be used. e.g `has:abc sender:abc@zulipchat.com` will have all the
suggestions with the prefix `messages with one or more abc, sent by
abc@zulipchat.com`.
This commit is contained in:
Shubham Padia 2018-05-18 10:03:13 +05:30 committed by Tim Abbott
parent 0824308a7a
commit 2945062b79
2 changed files with 4 additions and 5 deletions

View File

@ -780,7 +780,6 @@ run_test('contains_suggestions', () => {
var query = 'has:';
var suggestions = search.get_suggestions(query);
var expected = [
'has:',
'has:link',
'has:image',
'has:attachment',
@ -790,7 +789,6 @@ run_test('contains_suggestions', () => {
query = 'has:im';
suggestions = search.get_suggestions(query);
expected = [
'has:im',
'has:image',
];
assert.deepEqual(suggestions.strings, expected);
@ -798,7 +796,6 @@ run_test('contains_suggestions', () => {
query = '-has:im';
suggestions = search.get_suggestions(query);
expected = [
'-has:im',
'-has:image',
];
assert.deepEqual(suggestions.strings, expected);
@ -814,7 +811,6 @@ run_test('contains_suggestions', () => {
query = 'stream:Denmark is:alerted has:lin';
suggestions = search.get_suggestions(query);
expected = [
'stream:Denmark is:alerted has:lin',
'stream:Denmark is:alerted has:link',
'stream:Denmark is:alerted',
'stream:Denmark',

View File

@ -538,7 +538,10 @@ exports.get_suggestions = function (query) {
}
// Display the default first
if (last.operator !== '') {
// `has` operator works only on predefined categories. Default suggestion
// is not displayed in that case. e.g. `messages with one or more abc` as
// a suggestion for `has:abc`does not make sense.
if (last.operator !== '' && last.operator !== 'has') {
suggestion = get_default_suggestion(operators);
result = [suggestion];
}