people: Split search terms inside the search function.

This helps other views calling this function to not do a separate
split of the terms.
This commit is contained in:
Aman Agrawal 2024-05-16 05:41:44 +00:00 committed by Tim Abbott
parent 2a8174baa3
commit b2dc6f4039
3 changed files with 12 additions and 12 deletions

View File

@ -339,11 +339,8 @@ function filter_user_ids(user_filter_text: string, user_ids: number[]): number[]
}
// If a query is present in "Search people", we return matches.
let search_terms = user_filter_text.toLowerCase().split(/[,|]+/);
search_terms = search_terms.map((s) => s.trim());
const persons = user_ids.map((user_id) => people.get_by_user_id(user_id));
return [...people.filter_people_by_search_terms(persons, search_terms)];
return [...people.filter_people_by_search_terms(persons, user_filter_text)];
}
function get_filtered_user_id_list(user_filter_text: string): number[] {

View File

@ -1224,7 +1224,10 @@ export function build_person_matcher(query: string): (user: User) => boolean {
};
}
export function filter_people_by_search_terms(users: User[], search_terms: string[]): Set<number> {
export function filter_people_by_search_terms(users: User[], search_string: string): Set<number> {
let search_terms = search_string.toLowerCase().split(/[,|]+/);
search_terms = search_terms.map((s) => s.trim());
const filtered_users = new Set<number>();
// Build our matchers outside the loop to avoid some

View File

@ -726,33 +726,33 @@ test_people("filtered_users", () => {
const search_term = "a";
const users = people.get_realm_users();
let filtered_people = people.filter_people_by_search_terms(users, [search_term]);
let filtered_people = people.filter_people_by_search_terms(users, search_term);
assert.equal(filtered_people.size, 2);
assert.ok(filtered_people.has(ashton.user_id));
assert.ok(filtered_people.has(maria.user_id));
assert.ok(!filtered_people.has(charles.user_id));
filtered_people = people.filter_people_by_search_terms(users, []);
assert.equal(filtered_people.size, 0);
filtered_people = people.filter_people_by_search_terms(users, "");
assert.equal(filtered_people.size, 7);
filtered_people = people.filter_people_by_search_terms(users, ["ltorv"]);
filtered_people = people.filter_people_by_search_terms(users, "ltorv");
assert.equal(filtered_people.size, 1);
assert.ok(filtered_people.has(linus.user_id));
filtered_people = people.filter_people_by_search_terms(users, ["ch di", "maria"]);
filtered_people = people.filter_people_by_search_terms(users, "ch di, maria");
assert.equal(filtered_people.size, 2);
assert.ok(filtered_people.has(charles.user_id));
assert.ok(filtered_people.has(maria.user_id));
// Test filtering of names with diacritics
// This should match Nöôáàh by ignoring diacritics, and also match Nooaah
filtered_people = people.filter_people_by_search_terms(users, ["noOa"]);
filtered_people = people.filter_people_by_search_terms(users, "noOa");
assert.equal(filtered_people.size, 2);
assert.ok(filtered_people.has(noah.user_id));
assert.ok(filtered_people.has(plain_noah.user_id));
// This should match ëmerson, but not emerson
filtered_people = people.filter_people_by_search_terms(users, ["ëm"]);
filtered_people = people.filter_people_by_search_terms(users, "ëm");
assert.equal(filtered_people.size, 1);
assert.ok(filtered_people.has(noah.user_id));
});