Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
search_suggestion: Remove subset suggestions from search suggestion.
Pratik Chanda85e7d2f5f79f
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.tsindex becfc4dd656..c783525d93b 100644--- a/web/src/search_suggestion.ts+++ b/web/src/search_suggestion.ts@@ -557,24 +557,6 @@ function get_topic_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestio});}-function get_term_subset_suggestions(terms: NarrowTerm[]): Suggestion[] {- // For channel:a topic:b search:c, suggest:- // channel:a topic:b- // channel:a- if (terms.length === 0) {- return [];- }-- const suggestions: Suggestion[] = [];-- for (let i = terms.length - 1; i >= 1; i -= 1) {- const subset = terms.slice(0, i);- suggestions.push(format_as_suggestion(subset));- }-- return suggestions;-}-type SuggestionAndIncompatiblePatterns = Suggestion & {incompatible_patterns: TermPattern[]};function get_special_filter_suggestions(@@ -1110,11 +1092,6 @@ export function get_search_result(}}- if (attacher.result.length < max_items) {- const subset_suggestions = get_term_subset_suggestions(all_search_terms);- const subset_suggestion_lines = subset_suggestions.map((suggestion) => [suggestion]);- attacher.push_many(subset_suggestion_lines);- }return attacher.get_result().slice(0, max_items);}diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjsindex e8ef67c8147..4981978259e 100644--- a/web/tests/search_suggestion.test.cjs+++ b/web/tests/search_suggestion.test.cjs@@ -150,25 +150,6 @@ test("get_is_suggestions_for_spectator", () => {page_params.is_spectator = false;});-test("subset_suggestions", ({mock_template}) => {- mock_template("search_description.hbs", true, (_data, html) => html);-- const denmark_id = new_stream_id();- const sub = {name: "Denmark", stream_id: denmark_id};- stream_data.add_sub(sub);- const query = `channel:${denmark_id} topic:Hamlet shakespeare`;-- const suggestions = get_suggestions(query);-- const expected = [- `channel:${denmark_id} topic:Hamlet shakespeare`,- `channel:${denmark_id} topic:Hamlet`,- `channel:${denmark_id}`,- ];-- assert.deepEqual(suggestions.strings, expected);-});-test("dm_suggestions", ({override, mock_template}) => {mock_template("search_description.hbs", true, (_data, html) => html);@@ -192,7 +173,6 @@ test("dm_suggestions", ({override, mock_template}) => {"is:dm dm:[email protected]","is:dm sender:[email protected]","is:dm dm-including:[email protected]",- "is:dm",];assert.deepEqual(suggestions.strings, expected);@@ -254,25 +234,25 @@ test("dm_suggestions", ({override, mock_template}) => {query = "is:unread from:ted";suggestions = get_suggestions(query);- expected = ["is:unread sender:[email protected]", "is:unread"];+ expected = ["is:unread sender:[email protected]"];assert.deepEqual(suggestions.strings, expected);// Users can enter bizarre queries, and if they do, we want to// be conservative with suggestions.query = "is:dm near:3";suggestions = get_suggestions(query);- expected = ["is:dm near:3", "is:dm"];+ expected = ["is:dm near:3"];assert.deepEqual(suggestions.strings, expected);query = "dm:[email protected] near:3";suggestions = get_suggestions(query);- expected = ["dm:[email protected] near:3", "dm:[email protected]"];+ expected = ["dm:[email protected] near:3"];assert.deepEqual(suggestions.strings, expected);// Make sure suggestions still work if preceding tokensquery = "is:alerted sender:[email protected]";suggestions = get_suggestions(query);- expected = ["is:alerted sender:[email protected]", "is:alerted"];+ expected = ["is:alerted sender:[email protected]"];assert.deepEqual(suggestions.strings, expected);query = "is:starred has:link is:dm al";@@ -283,9 +263,6 @@ test("dm_suggestions", ({override, mock_template}) => {"is:starred has:link is:dm dm:[email protected]","is:starred has:link is:dm sender:[email protected]","is:starred has:link is:dm dm-including:[email protected]",- "is:starred has:link is:dm",- "is:starred has:link",- "is:starred",];assert.deepEqual(suggestions.strings, expected);@@ -322,7 +299,6 @@ test("group_suggestions", ({mock_template}) => {"dm:[email protected] sender:[email protected]","dm:[email protected] dm-including:[email protected]",- "dm:[email protected]",];assert.deepEqual(suggestions.strings, expected);@@ -334,7 +310,6 @@ test("group_suggestions", ({mock_template}) => {"dm:[email protected] my","dm:[email protected] sender:[email protected]","dm:[email protected] dm-including:[email protected]",- "dm:[email protected]",];assert.deepEqual(suggestions.strings, expected);@@ -356,7 +331,6 @@ test("group_suggestions", ({mock_template}) => {"dm:[email protected] sender:[email protected]","dm:[email protected] dm-including:[email protected]",- "dm:[email protected]",];assert.deepEqual(suggestions.strings, expected);@@ -369,9 +343,6 @@ test("group_suggestions", ({mock_template}) => {"is:starred has:link dm:[email protected],[email protected]","is:starred has:link dm:[email protected] sender:[email protected]","is:starred has:link dm:[email protected] dm-including:[email protected]",- "is:starred has:link dm:[email protected]",- "is:starred has:link",- "is:starred",];assert.deepEqual(suggestions.strings, expected);@@ -379,13 +350,13 @@ test("group_suggestions", ({mock_template}) => {// with a channel. (Random channel id.)query = "channel:66 has:link dm:[email protected],Smit";suggestions = get_suggestions(query);- expected = ["channel:66 has:link", "channel:66"];+ expected = [];assert.deepEqual(suggestions.strings, expected);// Invalid emails don't give suggestions- query = "has:link dm:[email protected],Smit";+ query = "dm:[email protected],Smit";suggestions = get_suggestions(query);- expected = ["has:link"];+ expected = [];assert.deepEqual(suggestions.strings, expected);});@@ -498,7 +469,7 @@ test("has_suggestions", ({override, mock_template}) => {// 66 is misc channel id.query = "channel:66 is:alerted has:lin";suggestions = get_suggestions(query);- expected = ["channel:66 is:alerted has:link", "channel:66 is:alerted", "channel:66"];+ expected = ["channel:66 is:alerted has:link"];assert.deepEqual(suggestions.strings, expected);});@@ -598,7 +569,7 @@ test("check_is_suggestions", ({override, mock_template}) => {query = "channel:66 has:link is:sta";suggestions = get_suggestions(query);- expected = ["channel:66 has:link is:starred", "channel:66 has:link", "channel:66"];+ expected = ["channel:66 has:link is:starred"];assert.deepEqual(suggestions.strings, expected);});@@ -663,14 +634,12 @@ test("sent_by_me_suggestions", ({override, mock_template}) => {expected = [`channel:${denmark_id} topic:Denmark1 sent`,`channel:${denmark_id} topic:Denmark1 sender:[email protected]`,- `channel:${denmark_id} topic:Denmark1`,- `channel:${denmark_id}`,];assert.deepEqual(suggestions.strings, expected);query = "is:starred sender:m";suggestions = get_suggestions(query);- expected = ["is:starred sender:[email protected]", "is:starred"];+ expected = ["is:starred sender:[email protected]"];assert.deepEqual(suggestions.strings, expected);});@@ -722,23 +691,15 @@ test("topic_suggestions", ({override, mock_template}) => {assert.equal(describe(`channel:${office_id} topic:team`), "Messages in #office > team");suggestions = get_suggestions(`topic:staplers channel:${office_id}`);- expected = [`topic:staplers channel:${office_id}`, "topic:staplers"];+ expected = [`topic:staplers channel:${office_id}`];assert.deepEqual(suggestions.strings, expected);suggestions = get_suggestions(`channel:${devel_id} topic:`);- expected = [- `channel:${devel_id} topic:`,- `channel:${devel_id} topic:REXX`,- `channel:${devel_id}`,- ];+ expected = [`channel:${devel_id} topic:`, `channel:${devel_id} topic:REXX`];assert.deepEqual(suggestions.strings, expected);suggestions = get_suggestions(`channel:${devel_id} -topic:`);- expected = [- `channel:${devel_id} -topic:`,- `channel:${devel_id} -topic:REXX`,- `channel:${devel_id}`,- ];+ expected = [`channel:${devel_id} -topic:`, `channel:${devel_id} -topic:REXX`];assert.deepEqual(suggestions.strings, expected);suggestions = get_suggestions("-topic:te");@@ -753,22 +714,15 @@ test("topic_suggestions", ({override, mock_template}) => {expected = [`is:alerted channel:${devel_id} is:starred topic:`,`is:alerted channel:${devel_id} is:starred topic:REXX`,- `is:alerted channel:${devel_id} is:starred`,- `is:alerted channel:${devel_id}`,- "is:alerted",];assert.deepEqual(suggestions.strings, expected);suggestions = get_suggestions(`is:dm channel:${devel_id} topic:`);- expected = [`is:dm channel:${devel_id} topic:`, `is:dm channel:${devel_id}`, `is:dm`];+ expected = [`is:dm channel:${devel_id} topic:`];assert.deepEqual(suggestions.strings, expected);suggestions = get_suggestions(`topic:REXX channel:${devel_id} topic:`);- expected = [- `topic:REXX channel:${devel_id} topic:`,- `topic:REXX channel:${devel_id}`,- "topic:REXX",- ];+ expected = [`topic:REXX channel:${devel_id} topic:`];assert.deepEqual(suggestions.strings, expected);});@@ -984,7 +938,7 @@ test("people_suggestions", ({override, mock_template}) => {assert.deepEqual(suggestions.strings, expected);query = "sender:[email protected] new";- expected = ["sender:[email protected] new", "sender:[email protected]"];+ expected = ["sender:[email protected] new"];suggestions = get_suggestions(query);assert.deepEqual(suggestions.strings, expected);@@ -1022,8 +976,6 @@ test("operator_suggestions", ({override, mock_template}) => {"channel:66 is:alerted -f","channel:66 is:alerted -sender:","channel:66 is:alerted -sender:[email protected]",- "channel:66 is:alerted",- "channel:66",];assert.deepEqual(suggestions.strings, expected);});