diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.js index c815c709c5..812f3fe97e 100644 --- a/frontend_tests/node_tests/search.js +++ b/frontend_tests/node_tests/search.js @@ -85,9 +85,11 @@ run_test('initizalize', () => { return 'is:starred'; }; + search_suggestion.max_num_of_search_results = 99; search_query_box.typeahead = (opts) => { + assert.equal(opts.fixed, true); - assert.equal(opts.items, 12); + assert.equal(opts.items, 99); assert.equal(opts.naturalSearch, true); assert.equal(opts.helpOnEmptyStrings, true); assert.equal(opts.matcher(), true); diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.js index 59c400952c..080c4bf387 100644 --- a/frontend_tests/node_tests/search_legacy.js +++ b/frontend_tests/node_tests/search_legacy.js @@ -63,9 +63,10 @@ run_test('initialize', () => { assert(search.is_using_input_method); }; + search_suggestion.max_num_of_search_results = 999; search_query_box.typeahead = (opts) => { assert.equal(opts.fixed, true); - assert.equal(opts.items, 12); + assert.equal(opts.items, 999); assert.equal(opts.naturalSearch, true); assert.equal(opts.helpOnEmptyStrings, true); assert.equal(opts.matcher(), true); diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.js index ea256af093..7161e97686 100644 --- a/frontend_tests/node_tests/search_suggestion_legacy.js +++ b/frontend_tests/node_tests/search_suggestion_legacy.js @@ -13,6 +13,8 @@ zrequire('unread'); zrequire('common'); const search = zrequire('search_suggestion'); +search.max_num_of_search_results = 15; + const bob = { email: 'bob@zulip.com', full_name: 'Bob Roberts', diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index 3f5a0545e9..05fb5e4425 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -99,6 +99,7 @@ zrequire('upload'); zrequire('compose'); zrequire('composebox_typeahead'); zrequire('narrow'); +zrequire('search_suggestion'); zrequire('search'); zrequire('tutorial'); zrequire('notifications'); diff --git a/static/js/search.js b/static/js/search.js index eee9f4d62c..bce84f830c 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -81,7 +81,7 @@ exports.initialize = function () { return suggestions.strings; }, fixed: true, - items: 12, + items: search_suggestion.max_num_of_search_results, helpOnEmptyStrings: true, naturalSearch: true, highlighter: function (item) { diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js index d60e7ed6c9..53fd20cdcf 100644 --- a/static/js/search_suggestion.js +++ b/static/js/search_suggestion.js @@ -1,3 +1,5 @@ +exports.max_num_of_search_results = 12; + function stream_matches_query(stream_name, q) { return common.phrase_match(q, stream_name); } @@ -779,14 +781,21 @@ exports.get_search_result_legacy = function (query) { get_has_filter_suggestions, ]; + const max_items = exports.max_num_of_search_results; + _.each(filterers, function (filterer) { - const suggestions = filterer(last, base_operators); - attacher.attach_many(suggestions); + if (attacher.result.length < max_items) { + const suggestions = filterer(last, base_operators); + attacher.attach_many(suggestions); + } }); - const subset_suggestions = get_operator_subset_suggestions(operators); - attacher.concat(subset_suggestions); - return attacher.result; + if (attacher.result.length < max_items) { + const subset_suggestions = get_operator_subset_suggestions(operators); + attacher.concat(subset_suggestions); + } + + return attacher.result.slice(0, max_items); }; exports.get_suggestions_legacy = function (query) {