Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
filter: Show typeahead suggestions if search query has search filters.
akshatdalton76afb31196ba
diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.jsindex 00ef2592da1..7288c19824d 100644--- a/frontend_tests/node_tests/filter.js+++ b/frontend_tests/node_tests/filter.js@@ -944,15 +944,17 @@ test("parse", () => {string = "text stream:foo more text";operators = [+ {operator: "search", operand: "text"},{operator: "stream", operand: "foo"},- {operator: "search", operand: "text more text"},+ {operator: "search", operand: "more text"},];_test();string = "text streams:public more text";operators = [+ {operator: "search", operand: "text"},{operator: "streams", operand: "public"},- {operator: "search", operand: "text more text"},+ {operator: "search", operand: "more text"},];_test();@@ -973,15 +975,17 @@ test("parse", () => {string = ":stream: stream:foo :emoji: are cool";operators = [+ {operator: "search", operand: ":stream:"},{operator: "stream", operand: "foo"},- {operator: "search", operand: ":stream: :emoji: are cool"},+ {operator: "search", operand: ":emoji: are cool"},];_test();string = ":stream: stream:foo -:emoji: are cool";operators = [+ {operator: "search", operand: ":stream:"},{operator: "stream", operand: "foo"},- {operator: "search", operand: ":stream: -:emoji: are cool"},+ {operator: "search", operand: "-:emoji: are cool"},];_test();diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.jsindex 78ff4334e93..d15a8571f7c 100644--- a/frontend_tests/node_tests/search_suggestion.js+++ b/frontend_tests/node_tests/search_suggestion.js@@ -982,6 +982,6 @@ test("multiple_operators_without_pills", () => {query = "abc is:alerted sender:[email protected]";base_query = "";suggestions = get_suggestions(base_query, query);- expected = ["is:alerted sender:[email protected] abc"];+ expected = ["abc is:alerted sender:[email protected]"];assert.deepEqual(suggestions.strings, expected);});diff --git a/static/js/filter.js b/static/js/filter.jsindex 3f94187a209..e23f4e5ba8f 100644--- a/static/js/filter.js+++ b/static/js/filter.js@@ -293,7 +293,7 @@ export class Filter {// Parse a string into a list of operators (see below).static parse(str) {const operators = [];- const search_term = [];+ let search_term = [];let negated;let operator;let operand;@@ -305,6 +305,7 @@ export class Filter {const _operand = search_term.join(" ");term = {operator, operand: _operand, negated: false};operators.push(term);+ search_term = [];}}@@ -340,12 +341,16 @@ export class Filter {search_term.push(token);continue;}+ // If any search query was present and it is followed by some other filters+ // then we must add that search filter in its current position in the+ // operators list. This is done so that the last active filter is correctly+ // detected by the `get_search_result` function (in search_suggestions.js).+ maybe_add_search_terms();term = {negated, operator, operand};operators.push(term);}}- // NB: Callers of 'parse' can assume that the 'search' operator is last.maybe_add_search_terms();return operators;}