From 9c5d9c961cb7acd687bdd56ef5e4e5fab3371926 Mon Sep 17 00:00:00 2001 From: Ryan Rehman Date: Sat, 13 Jun 2020 18:57:21 +0530 Subject: [PATCH] search: Parse search string correctly. This is the exact same bug as observed in 02ab48a61e7ad1c1ab300d6a7d02dcc87f4b6e0f. The bug is in the way we invoke `Filter.parse`. `Filter.parse` returns a list of operators which can contain only one 'search' term at max. All strings with the 'search' operator present in the query are combined to form this 'search' term. However on concatenating two filters we may get two terms containing the 'search' operator. This will lead to the search suggestions getting generated based on only the last 'search' operator term instead of all the terms having the 'search' operator. This is evident from the test change as suggestions should be based on "s stream:of" but instead they were based on just the latest query. --- frontend_tests/node_tests/search_suggestion.js | 2 +- static/js/search_suggestion.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js index 5a5cd9aee0..923beab978 100644 --- a/frontend_tests/node_tests/search_suggestion.js +++ b/frontend_tests/node_tests/search_suggestion.js @@ -960,7 +960,7 @@ run_test('stream_completion', () => { stream_topic_history.reset(); let query = 'stream:of'; - let suggestions = get_suggestions('s', query); + let suggestions = get_suggestions('', query); let expected = [ "stream:of", "stream:office", diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index f19a66b4eb..f82217e168 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -625,9 +625,8 @@ exports.get_search_result = function (base_query, query) { // or pressing enter in between i.e search pill for is:starred has not yet been added, // then `base` should be equal to the default suggestion for `is:starred`. Thus the // description of `is:starred` will act as a prefix in every suggestion. - const base_query_operators = Filter.parse(base_query); const query_operators = Filter.parse(query); - const operators = base_query_operators.concat(query_operators); + const operators = Filter.parse((base_query + " " + query).trim()); let last = {operator: '', operand: '', negated: false}; if (query_operators.length > 0) { last = query_operators.slice(-1)[0];