search: Simplify narrow_or_search_for_term code path.

The main reasoning for this change is as follows:

    * When the search bar contains multiple search queries
        but no search results, the last search operand does
        not get displayed.

        This happens due to the fact that filter object
        contained 2 terms having the operator key value as
        "search" instead of a single term where operator is
        "search" and operand is a single string containing
        the space seperated search queries. This condition
        occurs for search_pills_enabled case only because
        we used to Filter.parse the query twice
        (once for the `base_operators` and once for the
        `suggestion_operator instead of doing both at once).

        Thus the `search_query` value inside the
        `narrow.show_search_query` function which only
        selected the operands of the first term displayed
        an incomplete result.

    * Another benefit of this commit is to display the narrow
        operators in the URL fragment the same way as when
        search_pills_enabled = False.

        For example, On entering the queries in the mentioned
        order -> 'is: starred', 'abc', 'def', 'is: private',
        'ghi'. This is the URL:

        Previously:
        /#narrow/is/starred/is/private/search/abc.20def/search/ghi

        Now (same as pills disabled case):
        /#narrow/is/starred/is/private/search/abc.20def.20ghi

    * We are also able to de-duplicate the non-typeahead search
        query code path.
This commit is contained in:
Ryan Rehman
2020-05-10 07:28:57 +05:30
committed by Tim Abbott
parent d3f2bbc4bb
commit 02ab48a61e
3 changed files with 18 additions and 38 deletions

View File

@@ -20,6 +20,7 @@ set_global('ui_util', {
set_global('narrow', {});
search_pill.append_search_string = noop;
search_pill.get_search_string_for_current_filter = noop;
global.patch_builtin('setTimeout', func => func());
@@ -139,7 +140,7 @@ run_test('initizalize', () => {
assert.deepEqual(options, {trigger: 'search'});
};
search_pill.get_search_string_for_current_filter = () => {
return '';
return search_box_val;
};
};
@@ -150,7 +151,7 @@ run_test('initizalize', () => {
}];
_setup('ver');
opts.updater('ver');
assert(is_blurred);
assert(!is_blurred);
assert(is_append_search_string_called);
operators = [{
@@ -160,7 +161,7 @@ run_test('initizalize', () => {
}];
_setup('stream:Verona');
opts.updater('stream:Verona');
assert(is_blurred);
assert(!is_blurred);
assert(is_append_search_string_called);
search.is_using_input_method = true;
@@ -206,7 +207,7 @@ run_test('initizalize', () => {
assert.deepEqual(options, {trigger: 'search'});
};
search_pill.get_search_string_for_current_filter = () => {
return '';
return search_box_val;
};
};