From 5c16549b8a50cd05c0abb9f5e72ff00fe4dcdf53 Mon Sep 17 00:00:00 2001 From: Pratik Chanda Date: Tue, 29 Jul 2025 19:59:53 +0530 Subject: [PATCH] search_suggestion: Don't show operator suggestion if its incompatible. Earlier, we would show operator suggestion even if it is incompatible with current search terms. Selecting this wouldn't show further suggestions for the operator since we don't allow narrow to incompatible search terms. This commit fixes this by hiding new suggestions if it is not compatible with current search terms in the search box. --- web/src/search_suggestion.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts index f2e53aa195..e341320631 100644 --- a/web/src/search_suggestion.ts +++ b/web/src/search_suggestion.ts @@ -799,7 +799,7 @@ function get_sent_by_me_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Sugg return []; } -function get_operator_suggestions(last: NarrowTerm): Suggestion[] { +function get_operator_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestion[] { if (!(last.operator === "search" || last.operator === "")) { return []; } @@ -831,7 +831,14 @@ function get_operator_suggestions(last: NarrowTerm): Suggestion[] { ]; } - choices = choices.filter((choice) => common.phrase_match(last_operand, choice)); + // We remove suggestion choice if its incompatible_pattern matches + // that of current search terms. + choices = choices.filter( + (choice) => + common.phrase_match(last_operand, choice) && + (!incompatible_patterns[choice] || + !match_criteria(terms, incompatible_patterns[choice])), + ); return choices.map((choice) => { // Map results for "dm:" operator for users