search: Exclude with operator terms from search terms.

This commit excludes terms containing the `with` operator
from the search terms, since `with` operator is not a search
operator.
This commit is contained in:
roanster007 2025-02-07 23:11:44 +05:30 committed by Tim Abbott
parent 725d0e2d47
commit ca2394495e
2 changed files with 18 additions and 3 deletions

View File

@ -18,11 +18,15 @@ export function filter(): Filter | undefined {
export function search_terms(current_filter: Filter | undefined = filter()): NarrowTerm[] {
if (current_filter === undefined) {
if (page_params.narrow !== undefined) {
return new Filter(page_params.narrow).terms();
current_filter = new Filter(page_params.narrow);
} else {
current_filter = new Filter([]);
}
return new Filter([]).terms();
}
return current_filter.terms();
const non_search_operators = new Set(["with"]);
return current_filter.terms().filter((term) => !non_search_operators.has(term.operator));
}
export function is_search_view(current_filter: Filter | undefined = filter()): boolean {

View File

@ -151,6 +151,17 @@ test("terms", () => {
assert.equal(result.length, 1);
assert.equal(result[0].operator, "channel");
assert.equal(result[0].operand, foo_stream_id.toString());
// `with` terms are excluded from search terms.
page_params.narrow = [
{operator: "stream", operand: foo_stream_id.toString()},
{operator: "topic", operand: "Bar"},
{operator: "with", operand: "12"},
];
result = narrow_state.search_terms();
assert.equal(result.length, 2);
assert.equal(result[0].operator, "channel");
assert.equal(result[1].operator, "topic");
});
test("excludes_muted_topics", () => {