mirror of https://github.com/zulip/zulip.git
search: Duplicate search_suggestions.get_suggestions.
This large function will need to be modified significantly as part of the pills effort, and copying it lets us preserve behavior in production until we're ready to cut things over.
This commit is contained in:
parent
069a4f1626
commit
5b0e9b7fe6
|
@ -86,7 +86,7 @@ run_test('initizalize', () => {
|
|||
};
|
||||
|
||||
/* Test source */
|
||||
search_suggestion.get_suggestions = () => search_suggestions;
|
||||
search_suggestion.get_suggestions_legacy = () => search_suggestions;
|
||||
const expected_source_value = search_suggestions.strings;
|
||||
const source = opts.source('ver');
|
||||
assert.equal(source, expected_source_value);
|
||||
|
|
|
@ -42,7 +42,7 @@ run_test('basic_get_suggestions', () => {
|
|||
return 'office';
|
||||
};
|
||||
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
|
||||
var expected = [
|
||||
'fred',
|
||||
|
@ -61,7 +61,7 @@ run_test('subset_suggestions', () => {
|
|||
return;
|
||||
};
|
||||
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
|
||||
var expected = [
|
||||
"stream:Denmark topic:Hamlet shakespeare",
|
||||
|
@ -99,7 +99,7 @@ run_test('private_suggestions', () => {
|
|||
people.add(alice);
|
||||
|
||||
var query = 'is:private';
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
var expected = [
|
||||
"is:private",
|
||||
"pm-with:alice@zulip.com",
|
||||
|
@ -109,7 +109,7 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'is:private al';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"is:private al",
|
||||
"is:private is:alerted",
|
||||
|
@ -121,7 +121,7 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'pm-with:t';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:t",
|
||||
"pm-with:ted@zulip.com",
|
||||
|
@ -129,7 +129,7 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-pm-with:t';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-pm-with:t",
|
||||
"is:private -pm-with:ted@zulip.com",
|
||||
|
@ -137,14 +137,14 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'pm-with:ted@zulip.com';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:ted@zulip.com",
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sender:ted';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"sender:ted",
|
||||
"sender:ted@zulip.com",
|
||||
|
@ -152,7 +152,7 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sender:te';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"sender:te",
|
||||
"sender:ted@zulip.com",
|
||||
|
@ -160,7 +160,7 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-sender:te';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-sender:te",
|
||||
"-sender:ted@zulip.com",
|
||||
|
@ -168,14 +168,14 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sender:ted@zulip.com';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"sender:ted@zulip.com",
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'is:unread from:ted';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"is:unread from:ted",
|
||||
"is:unread from:ted@zulip.com",
|
||||
|
@ -187,7 +187,7 @@ run_test('private_suggestions', () => {
|
|||
// Users can enter bizarre queries, and if they do, we want to
|
||||
// be conservative with suggestions.
|
||||
query = 'is:private near:3';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"is:private near:3",
|
||||
"is:private",
|
||||
|
@ -195,7 +195,7 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'pm-with:ted@zulip.com near:3';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:ted@zulip.com near:3",
|
||||
"pm-with:ted@zulip.com",
|
||||
|
@ -204,7 +204,7 @@ run_test('private_suggestions', () => {
|
|||
|
||||
// Make sure suggestions still work if preceding tokens
|
||||
query = 'is:alerted sender:ted@zulip.com';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"is:alerted sender:ted@zulip.com",
|
||||
"is:alerted",
|
||||
|
@ -212,7 +212,7 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'is:starred has:link is:private al';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"is:starred has:link is:private al",
|
||||
"is:starred has:link is:private is:alerted",
|
||||
|
@ -227,7 +227,7 @@ run_test('private_suggestions', () => {
|
|||
|
||||
// Make sure it handles past context correctly
|
||||
query = 'stream:Denmark pm-with:';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'stream:Denmark pm-with:',
|
||||
'stream:Denmark',
|
||||
|
@ -235,7 +235,7 @@ run_test('private_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sender:ted@zulip.com sender:';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'sender:ted@zulip.com sender:',
|
||||
'sender:ted@zulip.com',
|
||||
|
@ -286,7 +286,7 @@ run_test('group_suggestions', () => {
|
|||
// Entering a comma in a pm-with query should immediately generate
|
||||
// suggestions for the next person.
|
||||
var query = 'pm-with:bob@zulip.com,';
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
var expected = [
|
||||
"pm-with:bob@zulip.com,",
|
||||
"pm-with:bob@zulip.com,alice@zulip.com",
|
||||
|
@ -298,7 +298,7 @@ run_test('group_suggestions', () => {
|
|||
// Only the last part of a comma-separated pm-with query should be used to
|
||||
// generate suggestions.
|
||||
query = 'pm-with:bob@zulip.com,t';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:bob@zulip.com,t",
|
||||
"pm-with:bob@zulip.com,ted@zulip.com",
|
||||
|
@ -307,7 +307,7 @@ run_test('group_suggestions', () => {
|
|||
|
||||
// Smit should also generate ted@zulip.com (Ted Smith) as a suggestion.
|
||||
query = 'pm-with:bob@zulip.com,Smit';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:bob@zulip.com,Smit",
|
||||
"pm-with:bob@zulip.com,ted@zulip.com",
|
||||
|
@ -316,7 +316,7 @@ run_test('group_suggestions', () => {
|
|||
|
||||
// Do not suggest "bob@zulip.com" (the name of the current user)
|
||||
query = 'pm-with:ted@zulip.com,bo';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:ted@zulip.com,bo",
|
||||
];
|
||||
|
@ -324,7 +324,7 @@ run_test('group_suggestions', () => {
|
|||
|
||||
// No superfluous suggestions should be generated.
|
||||
query = 'pm-with:bob@zulip.com,red';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:bob@zulip.com,red",
|
||||
];
|
||||
|
@ -334,7 +334,7 @@ run_test('group_suggestions', () => {
|
|||
// operator is negated.
|
||||
|
||||
query = '-pm-with:bob@zulip.com,';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-pm-with:bob@zulip.com,",
|
||||
"is:private -pm-with:bob@zulip.com,alice@zulip.com",
|
||||
|
@ -344,7 +344,7 @@ run_test('group_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-pm-with:bob@zulip.com,t';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-pm-with:bob@zulip.com,t",
|
||||
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
||||
|
@ -352,7 +352,7 @@ run_test('group_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-pm-with:bob@zulip.com,Smit';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-pm-with:bob@zulip.com,Smit",
|
||||
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
||||
|
@ -360,7 +360,7 @@ run_test('group_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-pm-with:bob@zulip.com,red';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-pm-with:bob@zulip.com,red",
|
||||
];
|
||||
|
@ -368,7 +368,7 @@ run_test('group_suggestions', () => {
|
|||
|
||||
// Test multiple operators
|
||||
query = 'is:starred has:link pm-with:bob@zulip.com,Smit';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"is:starred has:link pm-with:bob@zulip.com,Smit",
|
||||
"is:starred has:link pm-with:bob@zulip.com,ted@zulip.com",
|
||||
|
@ -378,7 +378,7 @@ run_test('group_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'stream:Denmark has:link pm-with:bob@zulip.com,Smit';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"stream:Denmark has:link pm-with:bob@zulip.com,Smit",
|
||||
"stream:Denmark has:link",
|
||||
|
@ -394,7 +394,7 @@ run_test('group_suggestions', () => {
|
|||
|
||||
// Simulate a past huddle which should now prioritize ted over alice
|
||||
query = 'pm-with:bob@zulip.com,';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:bob@zulip.com,",
|
||||
"pm-with:bob@zulip.com,ted@zulip.com",
|
||||
|
@ -405,7 +405,7 @@ run_test('group_suggestions', () => {
|
|||
|
||||
// bob,ted,jeff is already an existing huddle, so prioritize this one
|
||||
query = 'pm-with:bob@zulip.com,ted@zulip.com,';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:bob@zulip.com,ted@zulip.com,",
|
||||
"pm-with:bob@zulip.com,ted@zulip.com,jeff@zulip.com",
|
||||
|
@ -416,7 +416,7 @@ run_test('group_suggestions', () => {
|
|||
// bob,ted,jeff is already an existing huddle, but if we start with just bob,
|
||||
// then don't prioritize ted over alice because it doesn't complete the full huddle.
|
||||
query = 'pm-with:jeff@zulip.com,';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"pm-with:jeff@zulip.com,",
|
||||
"pm-with:jeff@zulip.com,alice@zulip.com",
|
||||
|
@ -438,7 +438,7 @@ run_test('empty_query_suggestions', () => {
|
|||
return;
|
||||
};
|
||||
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
|
||||
var expected = [
|
||||
"",
|
||||
|
@ -482,7 +482,7 @@ run_test('has_suggestions', () => {
|
|||
return;
|
||||
};
|
||||
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
var expected = [
|
||||
"h",
|
||||
'has:link',
|
||||
|
@ -500,7 +500,7 @@ run_test('has_suggestions', () => {
|
|||
assert.equal(describe('has:attachment'), 'Messages with one or more attachment');
|
||||
|
||||
query = '-h';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-h",
|
||||
'-has:link',
|
||||
|
@ -515,7 +515,7 @@ run_test('has_suggestions', () => {
|
|||
// operand suggestions follow.
|
||||
|
||||
query = 'has:';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'has:link',
|
||||
'has:image',
|
||||
|
@ -524,21 +524,21 @@ run_test('has_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'has:im';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'has:image',
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-has:im';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'-has:image',
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'att';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'att',
|
||||
'has:attachment',
|
||||
|
@ -546,7 +546,7 @@ run_test('has_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'stream:Denmark is:alerted has:lin';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'stream:Denmark is:alerted has:link',
|
||||
'stream:Denmark is:alerted',
|
||||
|
@ -564,7 +564,7 @@ run_test('check_is_suggestions', () => {
|
|||
return;
|
||||
};
|
||||
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
var expected = [
|
||||
'i',
|
||||
'is:private',
|
||||
|
@ -587,7 +587,7 @@ run_test('check_is_suggestions', () => {
|
|||
assert.equal(describe('is:unread'), 'Unread messages');
|
||||
|
||||
query = '-i';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'-i',
|
||||
'-is:private',
|
||||
|
@ -607,7 +607,7 @@ run_test('check_is_suggestions', () => {
|
|||
// operand suggestions follow.
|
||||
|
||||
query = 'is:';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'is:private',
|
||||
'is:starred',
|
||||
|
@ -618,21 +618,21 @@ run_test('check_is_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'is:st';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'is:starred',
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-is:st';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'-is:starred',
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'st';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'st',
|
||||
'is:starred',
|
||||
|
@ -641,7 +641,7 @@ run_test('check_is_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'stream:Denmark has:link is:sta';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'stream:Denmark has:link is:starred',
|
||||
'stream:Denmark has:link',
|
||||
|
@ -660,13 +660,13 @@ run_test('sent_by_me_suggestions', () => {
|
|||
};
|
||||
|
||||
var query = '';
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
assert(suggestions.strings.indexOf('sender:bob@zulip.com') !== -1);
|
||||
assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description,
|
||||
'Sent by me');
|
||||
|
||||
query = 'sender';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
var expected = [
|
||||
"sender",
|
||||
"sender:bob@zulip.com",
|
||||
|
@ -675,7 +675,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-sender';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-sender",
|
||||
"-sender:bob@zulip.com",
|
||||
|
@ -684,7 +684,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'from';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"from",
|
||||
"from:bob@zulip.com",
|
||||
|
@ -693,7 +693,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-from';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-from",
|
||||
"-from:bob@zulip.com",
|
||||
|
@ -702,21 +702,21 @@ run_test('sent_by_me_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sender:bob@zulip.com';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"sender:bob@zulip.com",
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'from:bob@zulip.com';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"from:bob@zulip.com",
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sent';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"sent",
|
||||
"sender:bob@zulip.com",
|
||||
|
@ -724,7 +724,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-sent';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-sent",
|
||||
"-sender:bob@zulip.com",
|
||||
|
@ -732,7 +732,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'stream:Denmark topic:Denmark1 sent';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"stream:Denmark topic:Denmark1 sent",
|
||||
"stream:Denmark topic:Denmark1 sender:bob@zulip.com",
|
||||
|
@ -742,7 +742,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'is:starred sender:m';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"is:starred sender:m",
|
||||
"is:starred sender:bob@zulip.com",
|
||||
|
@ -751,7 +751,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sender:alice@zulip.com sender:';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"sender:alice@zulip.com sender:",
|
||||
"sender:alice@zulip.com",
|
||||
|
@ -782,7 +782,7 @@ run_test('topic_suggestions', () => {
|
|||
};
|
||||
|
||||
topic_data.reset();
|
||||
suggestions = search.get_suggestions('te');
|
||||
suggestions = search.get_suggestions_legacy('te');
|
||||
expected = [
|
||||
"te",
|
||||
];
|
||||
|
@ -800,7 +800,7 @@ run_test('topic_suggestions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
suggestions = search.get_suggestions('te');
|
||||
suggestions = search.get_suggestions_legacy('te');
|
||||
expected = [
|
||||
"te",
|
||||
"stream:office topic:team",
|
||||
|
@ -814,14 +814,14 @@ run_test('topic_suggestions', () => {
|
|||
assert.equal(describe('te'), "Search for te");
|
||||
assert.equal(describe('stream:office topic:team'), "Stream office > team");
|
||||
|
||||
suggestions = search.get_suggestions('topic:staplers stream:office');
|
||||
suggestions = search.get_suggestions_legacy('topic:staplers stream:office');
|
||||
expected = [
|
||||
'topic:staplers stream:office',
|
||||
'topic:staplers',
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
suggestions = search.get_suggestions('stream:devel topic:');
|
||||
suggestions = search.get_suggestions_legacy('stream:devel topic:');
|
||||
expected = [
|
||||
'stream:devel topic:',
|
||||
'stream:devel topic:REXX',
|
||||
|
@ -829,7 +829,7 @@ run_test('topic_suggestions', () => {
|
|||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
suggestions = search.get_suggestions('stream:devel -topic:');
|
||||
suggestions = search.get_suggestions_legacy('stream:devel -topic:');
|
||||
expected = [
|
||||
'stream:devel -topic:',
|
||||
'stream:devel -topic:REXX',
|
||||
|
@ -837,7 +837,7 @@ run_test('topic_suggestions', () => {
|
|||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
suggestions = search.get_suggestions('-topic:te');
|
||||
suggestions = search.get_suggestions_legacy('-topic:te');
|
||||
expected = [
|
||||
'-topic:te',
|
||||
'stream:office -topic:team',
|
||||
|
@ -845,7 +845,7 @@ run_test('topic_suggestions', () => {
|
|||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
suggestions = search.get_suggestions('is:alerted stream:devel is:starred topic:');
|
||||
suggestions = search.get_suggestions_legacy('is:alerted stream:devel is:starred topic:');
|
||||
expected = [
|
||||
'is:alerted stream:devel is:starred topic:',
|
||||
'is:alerted stream:devel is:starred topic:REXX',
|
||||
|
@ -855,7 +855,7 @@ run_test('topic_suggestions', () => {
|
|||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
suggestions = search.get_suggestions('is:private stream:devel topic:');
|
||||
suggestions = search.get_suggestions_legacy('is:private stream:devel topic:');
|
||||
expected = [
|
||||
'is:private stream:devel topic:',
|
||||
'is:private stream:devel',
|
||||
|
@ -863,7 +863,7 @@ run_test('topic_suggestions', () => {
|
|||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
suggestions = search.get_suggestions('topic:REXX stream:devel topic:');
|
||||
suggestions = search.get_suggestions_legacy('topic:REXX stream:devel topic:');
|
||||
expected = [
|
||||
'topic:REXX stream:devel topic:',
|
||||
'topic:REXX stream:devel',
|
||||
|
@ -885,7 +885,7 @@ run_test('whitespace_glitch', () => {
|
|||
|
||||
topic_data.reset();
|
||||
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
|
||||
var expected = [
|
||||
"stream:office",
|
||||
|
@ -906,7 +906,7 @@ run_test('stream_completion', () => {
|
|||
topic_data.reset();
|
||||
|
||||
var query = 'stream:of';
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
var expected = [
|
||||
"stream:of",
|
||||
"stream:office",
|
||||
|
@ -914,7 +914,7 @@ run_test('stream_completion', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-stream:of';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"-stream:of",
|
||||
"-stream:office",
|
||||
|
@ -922,7 +922,7 @@ run_test('stream_completion', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'hel';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"hel",
|
||||
"stream:dev+help",
|
||||
|
@ -965,7 +965,7 @@ run_test('people_suggestions', () => {
|
|||
|
||||
topic_data.reset();
|
||||
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
|
||||
var expected = [
|
||||
"te",
|
||||
|
@ -986,7 +986,7 @@ run_test('people_suggestions', () => {
|
|||
assert.equal(describe('sender:ted@zulip.com'),
|
||||
"Sent by <strong>Te</strong>d Smith <<strong>te</strong>d@zulip.com>");
|
||||
|
||||
suggestions = search.get_suggestions('Ted '); // note space
|
||||
suggestions = search.get_suggestions_legacy('Ted '); // note space
|
||||
|
||||
expected = [
|
||||
"Ted",
|
||||
|
@ -1002,7 +1002,7 @@ run_test('people_suggestions', () => {
|
|||
'sender:ted+sm',
|
||||
'sender:ted@zulip.com',
|
||||
];
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sender:ted@zulip.com new';
|
||||
|
@ -1010,28 +1010,28 @@ run_test('people_suggestions', () => {
|
|||
'sender:ted@zulip.com new',
|
||||
'sender:ted@zulip.com',
|
||||
];
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'sender:ted@tulip.com new';
|
||||
expected = [
|
||||
'sender:ted@tulip.com+new',
|
||||
];
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
});
|
||||
|
||||
run_test('operator_suggestions', () => {
|
||||
// Completed operator should return nothing
|
||||
var query = 'stream:';
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
var expected = [
|
||||
'stream:',
|
||||
];
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'st';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'st',
|
||||
'is:starred',
|
||||
|
@ -1040,7 +1040,7 @@ run_test('operator_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'group-';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'group-',
|
||||
'group-pm-with:',
|
||||
|
@ -1048,7 +1048,7 @@ run_test('operator_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = '-s';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'-s',
|
||||
'-sender:bob@zulip.com',
|
||||
|
@ -1058,7 +1058,7 @@ run_test('operator_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
query = 'stream:Denmark is:alerted -f';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
'stream:Denmark is:alerted -f',
|
||||
'stream:Denmark is:alerted -from:bob@zulip.com',
|
||||
|
@ -1082,7 +1082,7 @@ run_test('queries_with_spaces', () => {
|
|||
|
||||
// test allowing spaces with quotes surrounding operand
|
||||
var query = 'stream:"dev he"';
|
||||
var suggestions = search.get_suggestions(query);
|
||||
var suggestions = search.get_suggestions_legacy(query);
|
||||
var expected = [
|
||||
"stream:dev+he",
|
||||
"stream:dev+help",
|
||||
|
@ -1091,7 +1091,7 @@ run_test('queries_with_spaces', () => {
|
|||
|
||||
// test mismatched quote
|
||||
query = 'stream:"dev h';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"stream:dev+h",
|
||||
"stream:dev+help",
|
||||
|
@ -1100,7 +1100,7 @@ run_test('queries_with_spaces', () => {
|
|||
|
||||
// test extra space after operator still works
|
||||
query = 'stream: offi';
|
||||
suggestions = search.get_suggestions(query);
|
||||
suggestions = search.get_suggestions_legacy(query);
|
||||
expected = [
|
||||
"stream:offi",
|
||||
"stream:office",
|
||||
|
|
|
@ -71,7 +71,12 @@ exports.initialize = function () {
|
|||
|
||||
search_query_box.typeahead({
|
||||
source: function (query) {
|
||||
var suggestions = search_suggestion.get_suggestions(query);
|
||||
var suggestions;
|
||||
if (page_params.search_pills_enabled) {
|
||||
suggestions = search_suggestion.get_suggestions(query);
|
||||
} else {
|
||||
suggestions = search_suggestion.get_suggestions_legacy(query);
|
||||
}
|
||||
// Update our global search_object hash
|
||||
search_object = suggestions.lookup_table;
|
||||
return suggestions.strings;
|
||||
|
|
|
@ -652,6 +652,126 @@ exports.get_suggestions = function (query) {
|
|||
};
|
||||
};
|
||||
|
||||
exports.get_suggestions_legacy = function (query) {
|
||||
// This method works in tandem with the typeahead library to generate
|
||||
// search suggestions. If you want to change its behavior, be sure to update
|
||||
// the tests. Its API is partly shaped by the typeahead library, which wants
|
||||
// us to give it strings only, but we also need to return our caller a hash
|
||||
// with information for subsequent callbacks.
|
||||
var result = [];
|
||||
var suggestion;
|
||||
var base; //base, default suggestion
|
||||
var suggestions;
|
||||
|
||||
// Add an entry for narrow by operators.
|
||||
var operators = Filter.parse(query);
|
||||
var last = {operator: '', operand: '', negated: false};
|
||||
if (operators.length > 0) {
|
||||
last = operators.slice(-1)[0];
|
||||
}
|
||||
|
||||
var person_suggestion_ops = ['sender', 'pm-with', 'from', 'group-pm'];
|
||||
var operators_len = operators.length;
|
||||
|
||||
// Handle spaces in person name in new suggestions only. Checks if the last operator is
|
||||
// 'search' and the second last operator is one out of person_suggestion_ops.
|
||||
// e.g for `sender:Ted sm`, initially last = {operator: 'search', operand: 'sm'....}
|
||||
// and second last is {operator: 'sender', operand: 'sm'....}. If the second last operand
|
||||
// is an email of a user, both of these operators remain unchanged. Otherwise search operator
|
||||
// will be deleted and new last will become {operator:'sender', operand: 'Ted sm`....}.
|
||||
if (operators_len > 1 &&
|
||||
last.operator === 'search' &&
|
||||
person_suggestion_ops.indexOf(operators[operators_len - 2].operator) !== -1) {
|
||||
var person_op = operators[operators_len - 2];
|
||||
if (!people.get_by_email(person_op.operand)) {
|
||||
last = {
|
||||
operator: person_op.operator,
|
||||
operand: person_op.operand + ' ' + last.operand,
|
||||
negated: person_op.negated,
|
||||
};
|
||||
operators[operators_len - 2] = last;
|
||||
operators.splice(-1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Display the default first
|
||||
// `has` and `is` operators work only on predefined categories. Default suggestion
|
||||
// is not displayed in that case. e.g. `messages with one or more abc` as
|
||||
// a suggestion for `has:abc`does not make sense.
|
||||
if (last.operator !== '' && last.operator !== 'has' && last.operator !== 'is') {
|
||||
suggestion = get_default_suggestion(operators);
|
||||
result = [suggestion];
|
||||
}
|
||||
|
||||
var base_operators = [];
|
||||
if (operators.length > 1) {
|
||||
base_operators = operators.slice(0, -1);
|
||||
}
|
||||
base = get_default_suggestion(base_operators);
|
||||
|
||||
// Get all individual suggestions, and then attach_suggestions
|
||||
// mutates the list 'result' to add a properly-formatted suggestion
|
||||
suggestions = get_is_filter_suggestions(last, base_operators);
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_sent_by_me_suggestions(last, base_operators);
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_stream_suggestions(last, base_operators);
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
var persons = people.get_all_persons();
|
||||
|
||||
suggestions = get_person_suggestions(persons, last, base_operators, 'sender');
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_person_suggestions(persons, last, base_operators, 'pm-with');
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_person_suggestions(persons, last, base_operators, 'from');
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_person_suggestions(persons, last, base_operators, 'group-pm-with');
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_group_suggestions(persons, last, base_operators);
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_topic_suggestions(last, base_operators);
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_operator_suggestions(last);
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_has_filter_suggestions(last, base_operators);
|
||||
attach_suggestions(result, base, suggestions);
|
||||
|
||||
suggestions = get_operator_subset_suggestions(operators);
|
||||
result = result.concat(suggestions);
|
||||
|
||||
_.each(result, function (sug) {
|
||||
var first = sug.description.charAt(0).toUpperCase();
|
||||
sug.description = first + sug.description.slice(1);
|
||||
});
|
||||
|
||||
// Typeahead expects us to give it strings, not objects, so we maintain our own hash
|
||||
// back to our objects, and we also filter duplicates here.
|
||||
var lookup_table = {};
|
||||
var unique_suggestions = [];
|
||||
_.each(result, function (obj) {
|
||||
if (!lookup_table[obj.search_string]) {
|
||||
lookup_table[obj.search_string] = obj;
|
||||
unique_suggestions.push(obj);
|
||||
}
|
||||
});
|
||||
var strings = _.map(unique_suggestions, function (obj) {
|
||||
return obj.search_string;
|
||||
});
|
||||
return {
|
||||
strings: strings,
|
||||
lookup_table: lookup_table,
|
||||
};
|
||||
};
|
||||
|
||||
return exports;
|
||||
}());
|
||||
|
|
Loading…
Reference in New Issue