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.
This commit is contained in:
Pratik Chanda
2025-07-29 19:59:53 +05:30
committed by Tim Abbott
parent 35bfc8bace
commit 5c16549b8a

View File

@@ -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