search: Parse search string correctly.

This is the exact same bug as observed in
02ab48a61e.

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.
This commit is contained in:
Ryan Rehman 2020-06-13 18:57:21 +05:30 committed by Tim Abbott
parent 26396c5e25
commit 9c5d9c961c
2 changed files with 2 additions and 3 deletions

View File

@ -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",

View File

@ -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];