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