mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
filter: Show typeahead suggestions if search query has search filters.
In message header search bar, users didn't use to get any typeahead suggestions if a normal filter follows search filter. E.g.: query => foo bar stream:D In the above case, users didn't use to get any typeahead suggestions. This was because we had set that the callers of 'parse' function can assume that the 'search' operator is present in the last in the query. Because of which `get_search_result` function (in search_suggestion.js) didn't use to show any typeahead suggestions as it used to assume that the latest typed query is for search filters. Fixes part of #19435.
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -982,6 +982,6 @@ test("multiple_operators_without_pills", () => {
|
||||
query = "abc is:alerted sender:ted@zulip.com";
|
||||
base_query = "";
|
||||
suggestions = get_suggestions(base_query, query);
|
||||
expected = ["is:alerted sender:ted@zulip.com abc"];
|
||||
expected = ["abc is:alerted sender:ted@zulip.com"];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user