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 */
|
/* Test source */
|
||||||
search_suggestion.get_suggestions = () => search_suggestions;
|
search_suggestion.get_suggestions_legacy = () => search_suggestions;
|
||||||
const expected_source_value = search_suggestions.strings;
|
const expected_source_value = search_suggestions.strings;
|
||||||
const source = opts.source('ver');
|
const source = opts.source('ver');
|
||||||
assert.equal(source, expected_source_value);
|
assert.equal(source, expected_source_value);
|
||||||
|
|
|
@ -42,7 +42,7 @@ run_test('basic_get_suggestions', () => {
|
||||||
return 'office';
|
return 'office';
|
||||||
};
|
};
|
||||||
|
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
|
|
||||||
var expected = [
|
var expected = [
|
||||||
'fred',
|
'fred',
|
||||||
|
@ -61,7 +61,7 @@ run_test('subset_suggestions', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
|
|
||||||
var expected = [
|
var expected = [
|
||||||
"stream:Denmark topic:Hamlet shakespeare",
|
"stream:Denmark topic:Hamlet shakespeare",
|
||||||
|
@ -99,7 +99,7 @@ run_test('private_suggestions', () => {
|
||||||
people.add(alice);
|
people.add(alice);
|
||||||
|
|
||||||
var query = 'is:private';
|
var query = 'is:private';
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
var expected = [
|
var expected = [
|
||||||
"is:private",
|
"is:private",
|
||||||
"pm-with:alice@zulip.com",
|
"pm-with:alice@zulip.com",
|
||||||
|
@ -109,7 +109,7 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'is:private al';
|
query = 'is:private al';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"is:private al",
|
"is:private al",
|
||||||
"is:private is:alerted",
|
"is:private is:alerted",
|
||||||
|
@ -121,7 +121,7 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'pm-with:t';
|
query = 'pm-with:t';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:t",
|
"pm-with:t",
|
||||||
"pm-with:ted@zulip.com",
|
"pm-with:ted@zulip.com",
|
||||||
|
@ -129,7 +129,7 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-pm-with:t';
|
query = '-pm-with:t';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-pm-with:t",
|
"-pm-with:t",
|
||||||
"is:private -pm-with:ted@zulip.com",
|
"is:private -pm-with:ted@zulip.com",
|
||||||
|
@ -137,14 +137,14 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'pm-with:ted@zulip.com';
|
query = 'pm-with:ted@zulip.com';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:ted@zulip.com",
|
"pm-with:ted@zulip.com",
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:ted';
|
query = 'sender:ted';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"sender:ted",
|
"sender:ted",
|
||||||
"sender:ted@zulip.com",
|
"sender:ted@zulip.com",
|
||||||
|
@ -152,7 +152,7 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:te';
|
query = 'sender:te';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"sender:te",
|
"sender:te",
|
||||||
"sender:ted@zulip.com",
|
"sender:ted@zulip.com",
|
||||||
|
@ -160,7 +160,7 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-sender:te';
|
query = '-sender:te';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-sender:te",
|
"-sender:te",
|
||||||
"-sender:ted@zulip.com",
|
"-sender:ted@zulip.com",
|
||||||
|
@ -168,14 +168,14 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:ted@zulip.com';
|
query = 'sender:ted@zulip.com';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"sender:ted@zulip.com",
|
"sender:ted@zulip.com",
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'is:unread from:ted';
|
query = 'is:unread from:ted';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"is:unread from:ted",
|
"is:unread from:ted",
|
||||||
"is:unread from:ted@zulip.com",
|
"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
|
// Users can enter bizarre queries, and if they do, we want to
|
||||||
// be conservative with suggestions.
|
// be conservative with suggestions.
|
||||||
query = 'is:private near:3';
|
query = 'is:private near:3';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"is:private near:3",
|
"is:private near:3",
|
||||||
"is:private",
|
"is:private",
|
||||||
|
@ -195,7 +195,7 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'pm-with:ted@zulip.com near:3';
|
query = 'pm-with:ted@zulip.com near:3';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:ted@zulip.com near:3",
|
"pm-with:ted@zulip.com near:3",
|
||||||
"pm-with:ted@zulip.com",
|
"pm-with:ted@zulip.com",
|
||||||
|
@ -204,7 +204,7 @@ run_test('private_suggestions', () => {
|
||||||
|
|
||||||
// Make sure suggestions still work if preceding tokens
|
// Make sure suggestions still work if preceding tokens
|
||||||
query = 'is:alerted sender:ted@zulip.com';
|
query = 'is:alerted sender:ted@zulip.com';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"is:alerted sender:ted@zulip.com",
|
"is:alerted sender:ted@zulip.com",
|
||||||
"is:alerted",
|
"is:alerted",
|
||||||
|
@ -212,7 +212,7 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'is:starred has:link is:private al';
|
query = 'is:starred has:link is:private al';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"is:starred has:link is:private al",
|
"is:starred has:link is:private al",
|
||||||
"is:starred has:link is:private is:alerted",
|
"is:starred has:link is:private is:alerted",
|
||||||
|
@ -227,7 +227,7 @@ run_test('private_suggestions', () => {
|
||||||
|
|
||||||
// Make sure it handles past context correctly
|
// Make sure it handles past context correctly
|
||||||
query = 'stream:Denmark pm-with:';
|
query = 'stream:Denmark pm-with:';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'stream:Denmark pm-with:',
|
'stream:Denmark pm-with:',
|
||||||
'stream:Denmark',
|
'stream:Denmark',
|
||||||
|
@ -235,7 +235,7 @@ run_test('private_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:ted@zulip.com sender:';
|
query = 'sender:ted@zulip.com sender:';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'sender:ted@zulip.com sender:',
|
'sender:ted@zulip.com sender:',
|
||||||
'sender:ted@zulip.com',
|
'sender:ted@zulip.com',
|
||||||
|
@ -286,7 +286,7 @@ run_test('group_suggestions', () => {
|
||||||
// Entering a comma in a pm-with query should immediately generate
|
// Entering a comma in a pm-with query should immediately generate
|
||||||
// suggestions for the next person.
|
// suggestions for the next person.
|
||||||
var query = 'pm-with:bob@zulip.com,';
|
var query = 'pm-with:bob@zulip.com,';
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
var expected = [
|
var expected = [
|
||||||
"pm-with:bob@zulip.com,",
|
"pm-with:bob@zulip.com,",
|
||||||
"pm-with:bob@zulip.com,alice@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
|
// Only the last part of a comma-separated pm-with query should be used to
|
||||||
// generate suggestions.
|
// generate suggestions.
|
||||||
query = 'pm-with:bob@zulip.com,t';
|
query = 'pm-with:bob@zulip.com,t';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:bob@zulip.com,t",
|
"pm-with:bob@zulip.com,t",
|
||||||
"pm-with:bob@zulip.com,ted@zulip.com",
|
"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.
|
// Smit should also generate ted@zulip.com (Ted Smith) as a suggestion.
|
||||||
query = 'pm-with:bob@zulip.com,Smit';
|
query = 'pm-with:bob@zulip.com,Smit';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:bob@zulip.com,Smit",
|
"pm-with:bob@zulip.com,Smit",
|
||||||
"pm-with:bob@zulip.com,ted@zulip.com",
|
"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)
|
// Do not suggest "bob@zulip.com" (the name of the current user)
|
||||||
query = 'pm-with:ted@zulip.com,bo';
|
query = 'pm-with:ted@zulip.com,bo';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:ted@zulip.com,bo",
|
"pm-with:ted@zulip.com,bo",
|
||||||
];
|
];
|
||||||
|
@ -324,7 +324,7 @@ run_test('group_suggestions', () => {
|
||||||
|
|
||||||
// No superfluous suggestions should be generated.
|
// No superfluous suggestions should be generated.
|
||||||
query = 'pm-with:bob@zulip.com,red';
|
query = 'pm-with:bob@zulip.com,red';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:bob@zulip.com,red",
|
"pm-with:bob@zulip.com,red",
|
||||||
];
|
];
|
||||||
|
@ -334,7 +334,7 @@ run_test('group_suggestions', () => {
|
||||||
// operator is negated.
|
// operator is negated.
|
||||||
|
|
||||||
query = '-pm-with:bob@zulip.com,';
|
query = '-pm-with:bob@zulip.com,';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-pm-with:bob@zulip.com,",
|
"-pm-with:bob@zulip.com,",
|
||||||
"is:private -pm-with:bob@zulip.com,alice@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);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-pm-with:bob@zulip.com,t';
|
query = '-pm-with:bob@zulip.com,t';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-pm-with:bob@zulip.com,t",
|
"-pm-with:bob@zulip.com,t",
|
||||||
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
||||||
|
@ -352,7 +352,7 @@ run_test('group_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-pm-with:bob@zulip.com,Smit';
|
query = '-pm-with:bob@zulip.com,Smit';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-pm-with:bob@zulip.com,Smit",
|
"-pm-with:bob@zulip.com,Smit",
|
||||||
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
"is:private -pm-with:bob@zulip.com,ted@zulip.com",
|
||||||
|
@ -360,7 +360,7 @@ run_test('group_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-pm-with:bob@zulip.com,red';
|
query = '-pm-with:bob@zulip.com,red';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-pm-with:bob@zulip.com,red",
|
"-pm-with:bob@zulip.com,red",
|
||||||
];
|
];
|
||||||
|
@ -368,7 +368,7 @@ run_test('group_suggestions', () => {
|
||||||
|
|
||||||
// Test multiple operators
|
// Test multiple operators
|
||||||
query = 'is:starred has:link pm-with:bob@zulip.com,Smit';
|
query = 'is:starred has:link pm-with:bob@zulip.com,Smit';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"is:starred has:link pm-with:bob@zulip.com,Smit",
|
"is:starred has:link pm-with:bob@zulip.com,Smit",
|
||||||
"is:starred has:link pm-with:bob@zulip.com,ted@zulip.com",
|
"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);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'stream:Denmark has:link pm-with:bob@zulip.com,Smit';
|
query = 'stream:Denmark has:link pm-with:bob@zulip.com,Smit';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"stream:Denmark has:link pm-with:bob@zulip.com,Smit",
|
"stream:Denmark has:link pm-with:bob@zulip.com,Smit",
|
||||||
"stream:Denmark has:link",
|
"stream:Denmark has:link",
|
||||||
|
@ -394,7 +394,7 @@ run_test('group_suggestions', () => {
|
||||||
|
|
||||||
// Simulate a past huddle which should now prioritize ted over alice
|
// Simulate a past huddle which should now prioritize ted over alice
|
||||||
query = 'pm-with:bob@zulip.com,';
|
query = 'pm-with:bob@zulip.com,';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:bob@zulip.com,",
|
"pm-with:bob@zulip.com,",
|
||||||
"pm-with:bob@zulip.com,ted@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
|
// bob,ted,jeff is already an existing huddle, so prioritize this one
|
||||||
query = 'pm-with:bob@zulip.com,ted@zulip.com,';
|
query = 'pm-with:bob@zulip.com,ted@zulip.com,';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:bob@zulip.com,ted@zulip.com,",
|
"pm-with:bob@zulip.com,ted@zulip.com,",
|
||||||
"pm-with:bob@zulip.com,ted@zulip.com,jeff@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,
|
// 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.
|
// then don't prioritize ted over alice because it doesn't complete the full huddle.
|
||||||
query = 'pm-with:jeff@zulip.com,';
|
query = 'pm-with:jeff@zulip.com,';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"pm-with:jeff@zulip.com,",
|
"pm-with:jeff@zulip.com,",
|
||||||
"pm-with:jeff@zulip.com,alice@zulip.com",
|
"pm-with:jeff@zulip.com,alice@zulip.com",
|
||||||
|
@ -438,7 +438,7 @@ run_test('empty_query_suggestions', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
|
|
||||||
var expected = [
|
var expected = [
|
||||||
"",
|
"",
|
||||||
|
@ -482,7 +482,7 @@ run_test('has_suggestions', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
var expected = [
|
var expected = [
|
||||||
"h",
|
"h",
|
||||||
'has:link',
|
'has:link',
|
||||||
|
@ -500,7 +500,7 @@ run_test('has_suggestions', () => {
|
||||||
assert.equal(describe('has:attachment'), 'Messages with one or more attachment');
|
assert.equal(describe('has:attachment'), 'Messages with one or more attachment');
|
||||||
|
|
||||||
query = '-h';
|
query = '-h';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-h",
|
"-h",
|
||||||
'-has:link',
|
'-has:link',
|
||||||
|
@ -515,7 +515,7 @@ run_test('has_suggestions', () => {
|
||||||
// operand suggestions follow.
|
// operand suggestions follow.
|
||||||
|
|
||||||
query = 'has:';
|
query = 'has:';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'has:link',
|
'has:link',
|
||||||
'has:image',
|
'has:image',
|
||||||
|
@ -524,21 +524,21 @@ run_test('has_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'has:im';
|
query = 'has:im';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'has:image',
|
'has:image',
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-has:im';
|
query = '-has:im';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'-has:image',
|
'-has:image',
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'att';
|
query = 'att';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'att',
|
'att',
|
||||||
'has:attachment',
|
'has:attachment',
|
||||||
|
@ -546,7 +546,7 @@ run_test('has_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'stream:Denmark is:alerted has:lin';
|
query = 'stream:Denmark is:alerted has:lin';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'stream:Denmark is:alerted has:link',
|
'stream:Denmark is:alerted has:link',
|
||||||
'stream:Denmark is:alerted',
|
'stream:Denmark is:alerted',
|
||||||
|
@ -564,7 +564,7 @@ run_test('check_is_suggestions', () => {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
var expected = [
|
var expected = [
|
||||||
'i',
|
'i',
|
||||||
'is:private',
|
'is:private',
|
||||||
|
@ -587,7 +587,7 @@ run_test('check_is_suggestions', () => {
|
||||||
assert.equal(describe('is:unread'), 'Unread messages');
|
assert.equal(describe('is:unread'), 'Unread messages');
|
||||||
|
|
||||||
query = '-i';
|
query = '-i';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'-i',
|
'-i',
|
||||||
'-is:private',
|
'-is:private',
|
||||||
|
@ -607,7 +607,7 @@ run_test('check_is_suggestions', () => {
|
||||||
// operand suggestions follow.
|
// operand suggestions follow.
|
||||||
|
|
||||||
query = 'is:';
|
query = 'is:';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'is:private',
|
'is:private',
|
||||||
'is:starred',
|
'is:starred',
|
||||||
|
@ -618,21 +618,21 @@ run_test('check_is_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'is:st';
|
query = 'is:st';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'is:starred',
|
'is:starred',
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-is:st';
|
query = '-is:st';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'-is:starred',
|
'-is:starred',
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'st';
|
query = 'st';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'st',
|
'st',
|
||||||
'is:starred',
|
'is:starred',
|
||||||
|
@ -641,7 +641,7 @@ run_test('check_is_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'stream:Denmark has:link is:sta';
|
query = 'stream:Denmark has:link is:sta';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'stream:Denmark has:link is:starred',
|
'stream:Denmark has:link is:starred',
|
||||||
'stream:Denmark has:link',
|
'stream:Denmark has:link',
|
||||||
|
@ -660,13 +660,13 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
var query = '';
|
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(suggestions.strings.indexOf('sender:bob@zulip.com') !== -1);
|
||||||
assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description,
|
assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description,
|
||||||
'Sent by me');
|
'Sent by me');
|
||||||
|
|
||||||
query = 'sender';
|
query = 'sender';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
var expected = [
|
var expected = [
|
||||||
"sender",
|
"sender",
|
||||||
"sender:bob@zulip.com",
|
"sender:bob@zulip.com",
|
||||||
|
@ -675,7 +675,7 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-sender';
|
query = '-sender';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-sender",
|
"-sender",
|
||||||
"-sender:bob@zulip.com",
|
"-sender:bob@zulip.com",
|
||||||
|
@ -684,7 +684,7 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'from';
|
query = 'from';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"from",
|
"from",
|
||||||
"from:bob@zulip.com",
|
"from:bob@zulip.com",
|
||||||
|
@ -693,7 +693,7 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-from';
|
query = '-from';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-from",
|
"-from",
|
||||||
"-from:bob@zulip.com",
|
"-from:bob@zulip.com",
|
||||||
|
@ -702,21 +702,21 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:bob@zulip.com';
|
query = 'sender:bob@zulip.com';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"sender:bob@zulip.com",
|
"sender:bob@zulip.com",
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'from:bob@zulip.com';
|
query = 'from:bob@zulip.com';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"from:bob@zulip.com",
|
"from:bob@zulip.com",
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sent';
|
query = 'sent';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"sent",
|
"sent",
|
||||||
"sender:bob@zulip.com",
|
"sender:bob@zulip.com",
|
||||||
|
@ -724,7 +724,7 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-sent';
|
query = '-sent';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-sent",
|
"-sent",
|
||||||
"-sender:bob@zulip.com",
|
"-sender:bob@zulip.com",
|
||||||
|
@ -732,7 +732,7 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'stream:Denmark topic:Denmark1 sent';
|
query = 'stream:Denmark topic:Denmark1 sent';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"stream:Denmark topic:Denmark1 sent",
|
"stream:Denmark topic:Denmark1 sent",
|
||||||
"stream:Denmark topic:Denmark1 sender:bob@zulip.com",
|
"stream:Denmark topic:Denmark1 sender:bob@zulip.com",
|
||||||
|
@ -742,7 +742,7 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'is:starred sender:m';
|
query = 'is:starred sender:m';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"is:starred sender:m",
|
"is:starred sender:m",
|
||||||
"is:starred sender:bob@zulip.com",
|
"is:starred sender:bob@zulip.com",
|
||||||
|
@ -751,7 +751,7 @@ run_test('sent_by_me_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:alice@zulip.com sender:';
|
query = 'sender:alice@zulip.com sender:';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"sender:alice@zulip.com sender:",
|
"sender:alice@zulip.com sender:",
|
||||||
"sender:alice@zulip.com",
|
"sender:alice@zulip.com",
|
||||||
|
@ -782,7 +782,7 @@ run_test('topic_suggestions', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
topic_data.reset();
|
topic_data.reset();
|
||||||
suggestions = search.get_suggestions('te');
|
suggestions = search.get_suggestions_legacy('te');
|
||||||
expected = [
|
expected = [
|
||||||
"te",
|
"te",
|
||||||
];
|
];
|
||||||
|
@ -800,7 +800,7 @@ run_test('topic_suggestions', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suggestions = search.get_suggestions('te');
|
suggestions = search.get_suggestions_legacy('te');
|
||||||
expected = [
|
expected = [
|
||||||
"te",
|
"te",
|
||||||
"stream:office topic:team",
|
"stream:office topic:team",
|
||||||
|
@ -814,14 +814,14 @@ run_test('topic_suggestions', () => {
|
||||||
assert.equal(describe('te'), "Search for te");
|
assert.equal(describe('te'), "Search for te");
|
||||||
assert.equal(describe('stream:office topic:team'), "Stream office > team");
|
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 = [
|
expected = [
|
||||||
'topic:staplers stream:office',
|
'topic:staplers stream:office',
|
||||||
'topic:staplers',
|
'topic:staplers',
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
suggestions = search.get_suggestions('stream:devel topic:');
|
suggestions = search.get_suggestions_legacy('stream:devel topic:');
|
||||||
expected = [
|
expected = [
|
||||||
'stream:devel topic:',
|
'stream:devel topic:',
|
||||||
'stream:devel topic:REXX',
|
'stream:devel topic:REXX',
|
||||||
|
@ -829,7 +829,7 @@ run_test('topic_suggestions', () => {
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
suggestions = search.get_suggestions('stream:devel -topic:');
|
suggestions = search.get_suggestions_legacy('stream:devel -topic:');
|
||||||
expected = [
|
expected = [
|
||||||
'stream:devel -topic:',
|
'stream:devel -topic:',
|
||||||
'stream:devel -topic:REXX',
|
'stream:devel -topic:REXX',
|
||||||
|
@ -837,7 +837,7 @@ run_test('topic_suggestions', () => {
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
suggestions = search.get_suggestions('-topic:te');
|
suggestions = search.get_suggestions_legacy('-topic:te');
|
||||||
expected = [
|
expected = [
|
||||||
'-topic:te',
|
'-topic:te',
|
||||||
'stream:office -topic:team',
|
'stream:office -topic:team',
|
||||||
|
@ -845,7 +845,7 @@ run_test('topic_suggestions', () => {
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
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 = [
|
expected = [
|
||||||
'is:alerted stream:devel is:starred topic:',
|
'is:alerted stream:devel is:starred topic:',
|
||||||
'is:alerted stream:devel is:starred topic:REXX',
|
'is:alerted stream:devel is:starred topic:REXX',
|
||||||
|
@ -855,7 +855,7 @@ run_test('topic_suggestions', () => {
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
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 = [
|
expected = [
|
||||||
'is:private stream:devel topic:',
|
'is:private stream:devel topic:',
|
||||||
'is:private stream:devel',
|
'is:private stream:devel',
|
||||||
|
@ -863,7 +863,7 @@ run_test('topic_suggestions', () => {
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
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 = [
|
expected = [
|
||||||
'topic:REXX stream:devel topic:',
|
'topic:REXX stream:devel topic:',
|
||||||
'topic:REXX stream:devel',
|
'topic:REXX stream:devel',
|
||||||
|
@ -885,7 +885,7 @@ run_test('whitespace_glitch', () => {
|
||||||
|
|
||||||
topic_data.reset();
|
topic_data.reset();
|
||||||
|
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
|
|
||||||
var expected = [
|
var expected = [
|
||||||
"stream:office",
|
"stream:office",
|
||||||
|
@ -906,7 +906,7 @@ run_test('stream_completion', () => {
|
||||||
topic_data.reset();
|
topic_data.reset();
|
||||||
|
|
||||||
var query = 'stream:of';
|
var query = 'stream:of';
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
var expected = [
|
var expected = [
|
||||||
"stream:of",
|
"stream:of",
|
||||||
"stream:office",
|
"stream:office",
|
||||||
|
@ -914,7 +914,7 @@ run_test('stream_completion', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-stream:of';
|
query = '-stream:of';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"-stream:of",
|
"-stream:of",
|
||||||
"-stream:office",
|
"-stream:office",
|
||||||
|
@ -922,7 +922,7 @@ run_test('stream_completion', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'hel';
|
query = 'hel';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"hel",
|
"hel",
|
||||||
"stream:dev+help",
|
"stream:dev+help",
|
||||||
|
@ -965,7 +965,7 @@ run_test('people_suggestions', () => {
|
||||||
|
|
||||||
topic_data.reset();
|
topic_data.reset();
|
||||||
|
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
|
|
||||||
var expected = [
|
var expected = [
|
||||||
"te",
|
"te",
|
||||||
|
@ -986,7 +986,7 @@ run_test('people_suggestions', () => {
|
||||||
assert.equal(describe('sender:ted@zulip.com'),
|
assert.equal(describe('sender:ted@zulip.com'),
|
||||||
"Sent by <strong>Te</strong>d Smith <<strong>te</strong>d@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 = [
|
expected = [
|
||||||
"Ted",
|
"Ted",
|
||||||
|
@ -1002,7 +1002,7 @@ run_test('people_suggestions', () => {
|
||||||
'sender:ted+sm',
|
'sender:ted+sm',
|
||||||
'sender:ted@zulip.com',
|
'sender:ted@zulip.com',
|
||||||
];
|
];
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:ted@zulip.com new';
|
query = 'sender:ted@zulip.com new';
|
||||||
|
@ -1010,28 +1010,28 @@ run_test('people_suggestions', () => {
|
||||||
'sender:ted@zulip.com new',
|
'sender:ted@zulip.com new',
|
||||||
'sender:ted@zulip.com',
|
'sender:ted@zulip.com',
|
||||||
];
|
];
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'sender:ted@tulip.com new';
|
query = 'sender:ted@tulip.com new';
|
||||||
expected = [
|
expected = [
|
||||||
'sender:ted@tulip.com+new',
|
'sender:ted@tulip.com+new',
|
||||||
];
|
];
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test('operator_suggestions', () => {
|
run_test('operator_suggestions', () => {
|
||||||
// Completed operator should return nothing
|
// Completed operator should return nothing
|
||||||
var query = 'stream:';
|
var query = 'stream:';
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
var expected = [
|
var expected = [
|
||||||
'stream:',
|
'stream:',
|
||||||
];
|
];
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'st';
|
query = 'st';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'st',
|
'st',
|
||||||
'is:starred',
|
'is:starred',
|
||||||
|
@ -1040,7 +1040,7 @@ run_test('operator_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'group-';
|
query = 'group-';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'group-',
|
'group-',
|
||||||
'group-pm-with:',
|
'group-pm-with:',
|
||||||
|
@ -1048,7 +1048,7 @@ run_test('operator_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = '-s';
|
query = '-s';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'-s',
|
'-s',
|
||||||
'-sender:bob@zulip.com',
|
'-sender:bob@zulip.com',
|
||||||
|
@ -1058,7 +1058,7 @@ run_test('operator_suggestions', () => {
|
||||||
assert.deepEqual(suggestions.strings, expected);
|
assert.deepEqual(suggestions.strings, expected);
|
||||||
|
|
||||||
query = 'stream:Denmark is:alerted -f';
|
query = 'stream:Denmark is:alerted -f';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
'stream:Denmark is:alerted -f',
|
'stream:Denmark is:alerted -f',
|
||||||
'stream:Denmark is:alerted -from:bob@zulip.com',
|
'stream:Denmark is:alerted -from:bob@zulip.com',
|
||||||
|
@ -1082,7 +1082,7 @@ run_test('queries_with_spaces', () => {
|
||||||
|
|
||||||
// test allowing spaces with quotes surrounding operand
|
// test allowing spaces with quotes surrounding operand
|
||||||
var query = 'stream:"dev he"';
|
var query = 'stream:"dev he"';
|
||||||
var suggestions = search.get_suggestions(query);
|
var suggestions = search.get_suggestions_legacy(query);
|
||||||
var expected = [
|
var expected = [
|
||||||
"stream:dev+he",
|
"stream:dev+he",
|
||||||
"stream:dev+help",
|
"stream:dev+help",
|
||||||
|
@ -1091,7 +1091,7 @@ run_test('queries_with_spaces', () => {
|
||||||
|
|
||||||
// test mismatched quote
|
// test mismatched quote
|
||||||
query = 'stream:"dev h';
|
query = 'stream:"dev h';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"stream:dev+h",
|
"stream:dev+h",
|
||||||
"stream:dev+help",
|
"stream:dev+help",
|
||||||
|
@ -1100,7 +1100,7 @@ run_test('queries_with_spaces', () => {
|
||||||
|
|
||||||
// test extra space after operator still works
|
// test extra space after operator still works
|
||||||
query = 'stream: offi';
|
query = 'stream: offi';
|
||||||
suggestions = search.get_suggestions(query);
|
suggestions = search.get_suggestions_legacy(query);
|
||||||
expected = [
|
expected = [
|
||||||
"stream:offi",
|
"stream:offi",
|
||||||
"stream:office",
|
"stream:office",
|
||||||
|
|
|
@ -71,7 +71,12 @@ exports.initialize = function () {
|
||||||
|
|
||||||
search_query_box.typeahead({
|
search_query_box.typeahead({
|
||||||
source: function (query) {
|
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
|
// Update our global search_object hash
|
||||||
search_object = suggestions.lookup_table;
|
search_object = suggestions.lookup_table;
|
||||||
return suggestions.strings;
|
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;
|
return exports;
|
||||||
}());
|
}());
|
||||||
|
|
Loading…
Reference in New Issue