mirror of https://github.com/zulip/zulip.git
search_suggestions: Convert lookup_table from object to Map.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
d4434a54e0
commit
7c6ec51e5d
|
@ -96,16 +96,16 @@ run_test('initizalize', () => {
|
|||
|
||||
{
|
||||
const search_suggestions = {
|
||||
lookup_table: {
|
||||
'stream:Verona': {
|
||||
lookup_table: new Map([
|
||||
['stream:Verona', {
|
||||
description: 'Stream <strong>Ver</strong>ona',
|
||||
search_string: 'stream:Verona',
|
||||
},
|
||||
ver: {
|
||||
}],
|
||||
['ver', {
|
||||
description: 'Search for ver',
|
||||
search_string: 'ver',
|
||||
},
|
||||
},
|
||||
}],
|
||||
]),
|
||||
strings: ['ver', 'stream:Verona'],
|
||||
};
|
||||
|
||||
|
|
|
@ -73,16 +73,16 @@ run_test('initialize', () => {
|
|||
|
||||
{
|
||||
const search_suggestions = {
|
||||
lookup_table: {
|
||||
'stream:Verona': {
|
||||
lookup_table: new Map([
|
||||
['stream:Verona', {
|
||||
description: 'Stream <strong>Ver</strong>ona',
|
||||
search_string: 'stream:Verona',
|
||||
},
|
||||
ver: {
|
||||
}],
|
||||
['ver', {
|
||||
description: 'Search for ver',
|
||||
search_string: 'ver',
|
||||
},
|
||||
},
|
||||
}],
|
||||
]),
|
||||
strings: ['ver', 'stream:Verona'],
|
||||
};
|
||||
|
||||
|
|
|
@ -478,7 +478,7 @@ run_test('empty_query_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
assert.equal(describe('is:private'), 'Private messages');
|
||||
assert.equal(describe('is:starred'), 'Starred messages');
|
||||
|
@ -512,7 +512,7 @@ run_test('has_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
|
||||
assert.equal(describe('has:link'), 'Messages with one or more link');
|
||||
|
@ -596,7 +596,7 @@ run_test('check_is_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
|
||||
assert.equal(describe('is:private'), 'Private messages');
|
||||
|
@ -715,7 +715,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
let query = '';
|
||||
let suggestions = get_suggestions('', query);
|
||||
assert(suggestions.strings.includes('sender:bob@zulip.com'));
|
||||
assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description,
|
||||
assert.equal(suggestions.lookup_table.get('sender:bob@zulip.com').description,
|
||||
'Sent by me');
|
||||
|
||||
query = 'sender';
|
||||
|
@ -862,7 +862,7 @@ run_test('topic_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
assert.equal(describe('te'), "Search for te");
|
||||
assert.equal(describe('stream:office topic:team'), "Stream office > team");
|
||||
|
@ -1017,7 +1017,7 @@ run_test('people_suggestions', () => {
|
|||
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
const describe = (q) => suggestions.lookup_table[q].description;
|
||||
const describe = (q) => suggestions.lookup_table.get(q).description;
|
||||
|
||||
assert.equal(describe('pm-with:ted@zulip.com'),
|
||||
"Private messages with <strong>Te</strong>d Smith <<strong>te</strong>d@zulip.com>");
|
||||
|
@ -1087,7 +1087,7 @@ run_test('people_suggestion (Admin only email visibility)', () => {
|
|||
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
const describe = (q) => suggestions.lookup_table[q].description;
|
||||
const describe = (q) => suggestions.lookup_table.get(q).description;
|
||||
|
||||
assert.equal(describe('pm-with:ted@zulip.com'),
|
||||
'Private messages with <strong>Te</strong>d Smith');
|
||||
|
|
|
@ -479,7 +479,7 @@ run_test('empty_query_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
assert.equal(describe('is:private'), 'Private messages');
|
||||
assert.equal(describe('is:starred'), 'Starred messages');
|
||||
|
@ -513,7 +513,7 @@ run_test('has_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
|
||||
assert.equal(describe('has:link'), 'Messages with one or more link');
|
||||
|
@ -598,7 +598,7 @@ run_test('check_is_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
|
||||
assert.equal(describe('is:private'), 'Private messages');
|
||||
|
@ -684,7 +684,7 @@ run_test('sent_by_me_suggestions', () => {
|
|||
let query = '';
|
||||
let suggestions = search.get_suggestions_legacy(query);
|
||||
assert(suggestions.strings.includes('sender:bob@zulip.com'));
|
||||
assert.equal(suggestions.lookup_table['sender:bob@zulip.com'].description,
|
||||
assert.equal(suggestions.lookup_table.get('sender:bob@zulip.com').description,
|
||||
'Sent by me');
|
||||
|
||||
query = 'sender';
|
||||
|
@ -831,7 +831,7 @@ run_test('topic_suggestions', () => {
|
|||
assert.deepEqual(suggestions.strings, expected);
|
||||
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
assert.equal(describe('te'), "Search for te");
|
||||
assert.equal(describe('stream:office topic:team'), "Stream office > team");
|
||||
|
@ -1001,7 +1001,7 @@ run_test('people_suggestions', () => {
|
|||
|
||||
assert.deepEqual(suggestions.strings, expected);
|
||||
function describe(q) {
|
||||
return suggestions.lookup_table[q].description;
|
||||
return suggestions.lookup_table.get(q).description;
|
||||
}
|
||||
assert.equal(describe('pm-with:ted@zulip.com'),
|
||||
"Private messages with <strong>Te</strong>d Smith <<strong>te</strong>d@zulip.com>");
|
||||
|
|
|
@ -64,7 +64,7 @@ exports.initialize = function () {
|
|||
// (It's a bit of legacy that we have an object with only one important
|
||||
// field. There's also a "search_string" field on each element that actually
|
||||
// just represents the key of the hash, so it's redundant.)
|
||||
let search_object = {};
|
||||
let search_map = new Map();
|
||||
|
||||
search_query_box.typeahead({
|
||||
source: function (query) {
|
||||
|
@ -76,8 +76,8 @@ exports.initialize = function () {
|
|||
} else {
|
||||
suggestions = search_suggestion.get_suggestions_legacy(query);
|
||||
}
|
||||
// Update our global search_object hash
|
||||
search_object = suggestions.lookup_table;
|
||||
// Update our global search_map hash
|
||||
search_map = suggestions.lookup_table;
|
||||
return suggestions.strings;
|
||||
},
|
||||
fixed: true,
|
||||
|
@ -85,7 +85,7 @@ exports.initialize = function () {
|
|||
helpOnEmptyStrings: true,
|
||||
naturalSearch: true,
|
||||
highlighter: function (item) {
|
||||
const obj = search_object[item];
|
||||
const obj = search_map.get(item);
|
||||
return obj.description;
|
||||
},
|
||||
matcher: function () {
|
||||
|
|
|
@ -832,10 +832,10 @@ exports.finalize_search_result = function (result) {
|
|||
|
||||
// Typeahead expects us to give it strings, not objects,
|
||||
// so we maintain our own hash back to our objects
|
||||
const lookup_table = {};
|
||||
const lookup_table = new Map();
|
||||
|
||||
for (const obj of result) {
|
||||
lookup_table[obj.search_string] = obj;
|
||||
lookup_table.set(obj.search_string, obj);
|
||||
}
|
||||
|
||||
const strings = result.map(obj => obj.search_string);
|
||||
|
|
Loading…
Reference in New Issue