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 @@
75 * @property {string} [source_url] - The source URL associated with the character.75 * @property {string} [source_url] - The source URL associated with the character.
76 * @property {{full_path: string}} [chub] - The Chub-specific data associated with the character.76 * @property {{full_path: string}} [chub] - The Chub-specific data associated with the character.
77 * @property {{source: string[]}} [risuai] - The RisuAI-specific data associated with the character.77 * @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.
78 */79 */
7980
80/**81/**
public/scripts/group-chats.js+3 -2
@@ -1265,7 +1265,7 @@ function getGroupCharacters({ doFilter, onlyMembers } = {}) {
1265 const thisGroup = openGroupId && groups.find((x) => x.id == openGroupId);1265 const thisGroup = openGroupId && groups.find((x) => x.id == openGroupId);
1266 let candidates = characters1266 let candidates = characters
1267 .filter((x) => isGroupMember(thisGroup, x.avatar) == onlyMembers)1267 .filter((x) => isGroupMember(thisGroup, x.avatar) == onlyMembers)
1268 .map((x, index) => ({ item: x, id: index, type: 'character' }));1268 .map((x) => ({ item: x, id: characters.indexOf(x), type: 'character' }));
12691269
1270 if (doFilter) {1270 if (doFilter) {
1271 candidates = groupCandidatesFilter.applyFilters(candidates);1271 candidates = groupCandidatesFilter.applyFilters(candidates);
@@ -1275,9 +1275,10 @@ function getGroupCharacters({ doFilter, onlyMembers } = {}) {
1275 candidates.sort(sortMembersFn);1275 candidates.sort(sortMembersFn);
1276 } else {1276 } else {
1277 const useFilterOrder = doFilter && !!$('#rm_group_filter').val();1277 const useFilterOrder = doFilter && !!$('#rm_group_filter').val();
1278 sortEntitiesList(candidates, useFilterOrder);1278 sortEntitiesList(candidates, useFilterOrder, groupCandidatesFilter);
1279 }1279 }
12801280
1281 groupCandidatesFilter.clearFuzzySearchCaches();
1281 return candidates;1282 return candidates;
1282}1283}
12831284
public/scripts/power-user.js+10 -9
@@ -1836,7 +1836,7 @@ async function loadContextSettings() {
1836 * Common function to perform fuzzy search with optional caching1836 * Common function to perform fuzzy search with optional caching
1837 * @param {string} type - Type of search from fuzzySearchCategories1837 * @param {string} type - Type of search from fuzzySearchCategories
1838 * @param {any[]} data - Data array to search in1838 * @param {any[]} data - Data array to search in
1839 * @param {Array<{name: string, weight: number, getFn?: Function}>} keys - Fuse.js keys configuration1839 * @param {Array<{name: string, weight: number, getFn?: (obj: any) => string}>} keys - Fuse.js keys configuration
1840 * @param {string} searchValue - The search term1840 * @param {string} searchValue - The search term
1841 * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - Optional fuzzy search caches1841 * @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - Optional fuzzy search caches
1842 * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score1842 * @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score
@@ -1850,7 +1850,6 @@ function performFuzzySearch(type, data, keys, searchValue, fuzzySearchCaches = n
1850 }1850 }
1851 }1851 }
18521852
1853 // @ts-ignore
1854 const fuse = new Fuse(data, {1853 const fuse = new Fuse(data, {
1855 keys: keys,1854 keys: keys,
1856 includeScore: true,1855 includeScore: true,
@@ -1924,7 +1923,7 @@ export function fuzzySearchPersonas(data, searchValue, fuzzySearchCaches = null)
1924 const mappedData = data.map(x => ({1923 const mappedData = data.map(x => ({
1925 key: x,1924 key: x,
1926 name: power_user.personas[x] ?? '',1925 name: power_user.personas[x] ?? '',
1927 description: power_user.persona_descriptions[x]?.description ?? ''1926 description: power_user.persona_descriptions[x]?.description ?? '',
1928 }));1927 }));
19291928
1930 const keys = [1929 const keys = [
@@ -2080,19 +2079,21 @@ const compareFunc = (first, second) => {
2080 * Sorts an array of entities based on the current sort settings2079 * Sorts an array of entities based on the current sort settings
2081 * @param {any[]} entities An array of objects with an `item` property2080 * @param {any[]} entities An array of objects with an `item` property
2082 * @param {boolean} forceSearch Whether to force search sorting2081 * @param {boolean} forceSearch Whether to force search sorting
2082 * @param {import('./filters.js').FilterHelper} [filterHelper=null] Filter helper to use
2083 */2083 */
2084export function sortEntitiesList(entities, forceSearch) {2084export function sortEntitiesList(entities, forceSearch, filterHelper = null) {
2085 filterHelper = filterHelper ?? entitiesFilter;
2085 if (power_user.sort_field == undefined || entities.length === 0) {2086 if (power_user.sort_field == undefined || entities.length === 0) {
2086 return;2087 return;
2087 }2088 }
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') {
2090 shuffle(entities);2093 shuffle(entities);
2091 return;2094 return;
2092 }2095 }
20932096
2094 const isSearch = forceSearch || $('#character_sort_order option[data-field="search"]').is(':selected');
2095
2096 entities.sort((a, b) => {2097 entities.sort((a, b) => {
2097 // Sort tags/folders will always be at the top2098 // Sort tags/folders will always be at the top
2098 if (a.type === 'tag' && b.type !== 'tag') {2099 if (a.type === 'tag' && b.type !== 'tag') {
@@ -2104,8 +2105,8 @@ export function sortEntitiesList(entities, forceSearch) {
21042105
2105 // If we have search sorting, we take scores and use those2106 // If we have search sorting, we take scores and use those
2106 if (isSearch) {2107 if (isSearch) {
2107 const aScore = entitiesFilter.getScore(FILTER_TYPES.SEARCH, `${a.type}.${a.id}`);2108 const aScore = filterHelper.getScore(FILTER_TYPES.SEARCH, `${a.type}.${a.id}`);
2108 const bScore = entitiesFilter.getScore(FILTER_TYPES.SEARCH, `${b.type}.${b.id}`);2109 const bScore = filterHelper.getScore(FILTER_TYPES.SEARCH, `${b.type}.${b.id}`);
2109 return (aScore - bScore);2110 return (aScore - bScore);
2110 }2111 }
21112112