From 2945062b79d4015ef9dba817ae9d8f880a09b551 Mon Sep 17 00:00:00 2001 From: Shubham Padia Date: Fri, 18 May 2018 10:03:13 +0530 Subject: [PATCH] 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`. --- frontend_tests/node_tests/search_suggestion.js | 4 ---- static/js/search_suggestion.js | 5 ++++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index 978e0d8140..9ed73908e1 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -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', diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index 049460e4ed..bdda27fa05 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -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]; }