search performance: Stop at max_items.

Once we have max_items results, stop trying
to get more items.

This should really help large realms when
you do a search on streams that turns up
more than N streams (where N is about 12).
We won't even bother to find people.
This commit is contained in:
Steve Howell
2019-12-25 15:58:11 +00:00
committed by Tim Abbott
parent 8406d34145
commit ab34ee0800
6 changed files with 23 additions and 8 deletions

View File

@@ -85,9 +85,11 @@ run_test('initizalize', () => {
return 'is:starred'; return 'is:starred';
}; };
search_suggestion.max_num_of_search_results = 99;
search_query_box.typeahead = (opts) => { search_query_box.typeahead = (opts) => {
assert.equal(opts.fixed, true); assert.equal(opts.fixed, true);
assert.equal(opts.items, 12); assert.equal(opts.items, 99);
assert.equal(opts.naturalSearch, true); assert.equal(opts.naturalSearch, true);
assert.equal(opts.helpOnEmptyStrings, true); assert.equal(opts.helpOnEmptyStrings, true);
assert.equal(opts.matcher(), true); assert.equal(opts.matcher(), true);

View File

@@ -63,9 +63,10 @@ run_test('initialize', () => {
assert(search.is_using_input_method); assert(search.is_using_input_method);
}; };
search_suggestion.max_num_of_search_results = 999;
search_query_box.typeahead = (opts) => { search_query_box.typeahead = (opts) => {
assert.equal(opts.fixed, true); assert.equal(opts.fixed, true);
assert.equal(opts.items, 12); assert.equal(opts.items, 999);
assert.equal(opts.naturalSearch, true); assert.equal(opts.naturalSearch, true);
assert.equal(opts.helpOnEmptyStrings, true); assert.equal(opts.helpOnEmptyStrings, true);
assert.equal(opts.matcher(), true); assert.equal(opts.matcher(), true);

View File

@@ -13,6 +13,8 @@ zrequire('unread');
zrequire('common'); zrequire('common');
const search = zrequire('search_suggestion'); const search = zrequire('search_suggestion');
search.max_num_of_search_results = 15;
const bob = { const bob = {
email: 'bob@zulip.com', email: 'bob@zulip.com',
full_name: 'Bob Roberts', full_name: 'Bob Roberts',

View File

@@ -99,6 +99,7 @@ zrequire('upload');
zrequire('compose'); zrequire('compose');
zrequire('composebox_typeahead'); zrequire('composebox_typeahead');
zrequire('narrow'); zrequire('narrow');
zrequire('search_suggestion');
zrequire('search'); zrequire('search');
zrequire('tutorial'); zrequire('tutorial');
zrequire('notifications'); zrequire('notifications');

View File

@@ -81,7 +81,7 @@ exports.initialize = function () {
return suggestions.strings; return suggestions.strings;
}, },
fixed: true, fixed: true,
items: 12, items: search_suggestion.max_num_of_search_results,
helpOnEmptyStrings: true, helpOnEmptyStrings: true,
naturalSearch: true, naturalSearch: true,
highlighter: function (item) { highlighter: function (item) {

View File

@@ -1,3 +1,5 @@
exports.max_num_of_search_results = 12;
function stream_matches_query(stream_name, q) { function stream_matches_query(stream_name, q) {
return common.phrase_match(q, stream_name); return common.phrase_match(q, stream_name);
} }
@@ -779,14 +781,21 @@ exports.get_search_result_legacy = function (query) {
get_has_filter_suggestions, get_has_filter_suggestions,
]; ];
const max_items = exports.max_num_of_search_results;
_.each(filterers, function (filterer) { _.each(filterers, function (filterer) {
if (attacher.result.length < max_items) {
const suggestions = filterer(last, base_operators); const suggestions = filterer(last, base_operators);
attacher.attach_many(suggestions); attacher.attach_many(suggestions);
}
}); });
if (attacher.result.length < max_items) {
const subset_suggestions = get_operator_subset_suggestions(operators); const subset_suggestions = get_operator_subset_suggestions(operators);
attacher.concat(subset_suggestions); attacher.concat(subset_suggestions);
return attacher.result; }
return attacher.result.slice(0, max_items);
}; };
exports.get_suggestions_legacy = function (query) { exports.get_suggestions_legacy = function (query) {