Fix group candidates fuzzy filter

b8a9a552463d5e889f0e22a0255048f01b702c73

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +14 -11Showing whitespace changes
public/scripts/char-data.js+1 -0
@@ -75,6 +75,7 @@
7575 * @property {string} [source_url] - The source URL associated with the character.
7676 * @property {{full_path: string}} [chub] - The Chub-specific data associated with the character.
7777 * @property {{source: string[]}} [risuai] - The RisuAI-specific data associated with the character.
78+ * @property {{positive: string, negative: string}} [sd_character_prompt] - SD-specific data associated with the character.
7879 */
7980
8081/**
public/scripts/group-chats.js+3 -2
@@ -1265,7 +1265,7 @@ function getGroupCharacters({ doFilter, onlyMembers } = {}) {
12651265 const thisGroup = openGroupId && groups.find((x) => x.id == openGroupId);
12661266 let candidates = characters
12671267 .filter((x) => isGroupMember(thisGroup, x.avatar) == onlyMembers)
12681268 .map((x, index) => ({ item: x, id: indexcharacters.indexOf(x), type: 'character' }));
12691269
12701270 if (doFilter) {
12711271 candidates = groupCandidatesFilter.applyFilters(candidates);
@@ -1275,9 +1275,10 @@ function getGroupCharacters({ doFilter, onlyMembers } = {}) {
12751275 candidates.sort(sortMembersFn);
12761276 } else {
12771277 const useFilterOrder = doFilter && !!$('#rm_group_filter').val();
12781278 sortEntitiesList(candidates, useFilterOrder, groupCandidatesFilter);
12791279 }
12801280
1281+ groupCandidatesFilter.clearFuzzySearchCaches();
12811282 return candidates;
12821283}
12831284
public/scripts/power-user.js+10 -9
@@ -1836,7 +1836,7 @@ async function loadContextSettings() {
18361836 * Common function to perform fuzzy search with optional caching
18371837 * @param {string} type - Type of search from fuzzySearchCategories
18381838 * @param {any[]} data - Data array to search in
18391839 * @param {Array<{name: string, weight: number, getFn?: Function(obj: any) => string}>} keys - Fuse.js keys configuration
18401840 * @param {string} searchValue - The search term
18411841 * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - Optional fuzzy search caches
18421842 * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score
@@ -1850,7 +1850,6 @@ function performFuzzySearch(type, data, keys, searchValue, fuzzySearchCaches = n
18501850 }
18511851 }
18521852
1853- // @ts-ignore
18541853 const fuse = new Fuse(data, {
18551854 keys: keys,
18561855 includeScore: true,
@@ -1924,7 +1923,7 @@ export function fuzzySearchPersonas(data, searchValue, fuzzySearchCaches = null)
19241923 const mappedData = data.map(x => ({
19251924 key: x,
19261925 name: power_user.personas[x] ?? '',
19271926 description: power_user.persona_descriptions[x]?.description ?? '',
19281927 }));
19291928
19301929 const keys = [
@@ -2080,19 +2079,21 @@ const compareFunc = (first, second) => {
20802079 * Sorts an array of entities based on the current sort settings
20812080 * @param {any[]} entities An array of objects with an `item` property
20822081 * @param {boolean} forceSearch Whether to force search sorting
2082+ * @param {import('./filters.js').FilterHelper} [filterHelper=null] Filter helper to use
20832083 */
20842084export function sortEntitiesList(entities, forceSearch, filterHelper = null) {
2085+ filterHelper = filterHelper ?? entitiesFilter;
20852086 if (power_user.sort_field == undefined || entities.length === 0) {
20862087 return;
20872088 }
20882089
2089- if (power_user.sort_order === 'random') {
2090+ const isSearch = forceSearch || $('#character_sort_order option[data-field="search"]').is(':selected');
2091+
2092+ if (!isSearch && power_user.sort_order === 'random') {
20902093 shuffle(entities);
20912094 return;
20922095 }
20932096
2094- const isSearch = forceSearch || $('#character_sort_order option[data-field="search"]').is(':selected');
2095-
20962097 entities.sort((a, b) => {
20972098 // Sort tags/folders will always be at the top
20982099 if (a.type === 'tag' && b.type !== 'tag') {
@@ -2104,8 +2105,8 @@ export function sortEntitiesList(entities, forceSearch) {
21042105
21052106 // If we have search sorting, we take scores and use those
21062107 if (isSearch) {
21072108 const aScore = entitiesFilterfilterHelper.getScore(FILTER_TYPES.SEARCH, `${a.type}.${a.id}`);
21082109 const bScore = entitiesFilterfilterHelper.getScore(FILTER_TYPES.SEARCH, `${b.type}.${b.id}`);
21092110 return (aScore - bScore);
21102111 }
21112112