mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix group candidates fuzzy filter
This commit is contained in:
@ -75,6 +75,7 @@
|
|||||||
* @property {string} [source_url] - The source URL associated with the character.
|
* @property {string} [source_url] - The source URL associated with the character.
|
||||||
* @property {{full_path: string}} [chub] - The Chub-specific data associated with the character.
|
* @property {{full_path: string}} [chub] - The Chub-specific data associated with the character.
|
||||||
* @property {{source: string[]}} [risuai] - The RisuAI-specific data associated with the character.
|
* @property {{source: string[]}} [risuai] - The RisuAI-specific data associated with the character.
|
||||||
|
* @property {{positive: string, negative: string}} [sd_character_prompt] - SD-specific data associated with the character.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1265,7 +1265,7 @@ function getGroupCharacters({ doFilter, onlyMembers } = {}) {
|
|||||||
const thisGroup = openGroupId && groups.find((x) => x.id == openGroupId);
|
const thisGroup = openGroupId && groups.find((x) => x.id == openGroupId);
|
||||||
let candidates = characters
|
let candidates = characters
|
||||||
.filter((x) => isGroupMember(thisGroup, x.avatar) == onlyMembers)
|
.filter((x) => isGroupMember(thisGroup, x.avatar) == onlyMembers)
|
||||||
.map((x, index) => ({ item: x, id: index, type: 'character' }));
|
.map((x) => ({ item: x, id: characters.indexOf(x), type: 'character' }));
|
||||||
|
|
||||||
if (doFilter) {
|
if (doFilter) {
|
||||||
candidates = groupCandidatesFilter.applyFilters(candidates);
|
candidates = groupCandidatesFilter.applyFilters(candidates);
|
||||||
@ -1275,9 +1275,10 @@ function getGroupCharacters({ doFilter, onlyMembers } = {}) {
|
|||||||
candidates.sort(sortMembersFn);
|
candidates.sort(sortMembersFn);
|
||||||
} else {
|
} else {
|
||||||
const useFilterOrder = doFilter && !!$('#rm_group_filter').val();
|
const useFilterOrder = doFilter && !!$('#rm_group_filter').val();
|
||||||
sortEntitiesList(candidates, useFilterOrder);
|
sortEntitiesList(candidates, useFilterOrder, groupCandidatesFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
groupCandidatesFilter.clearFuzzySearchCaches();
|
||||||
return candidates;
|
return candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1836,7 +1836,7 @@ async function loadContextSettings() {
|
|||||||
* Common function to perform fuzzy search with optional caching
|
* Common function to perform fuzzy search with optional caching
|
||||||
* @param {string} type - Type of search from fuzzySearchCategories
|
* @param {string} type - Type of search from fuzzySearchCategories
|
||||||
* @param {any[]} data - Data array to search in
|
* @param {any[]} data - Data array to search in
|
||||||
* @param {Array<{name: string, weight: number, getFn?: Function}>} keys - Fuse.js keys configuration
|
* @param {Array<{name: string, weight: number, getFn?: (obj: any) => string}>} keys - Fuse.js keys configuration
|
||||||
* @param {string} searchValue - The search term
|
* @param {string} searchValue - The search term
|
||||||
* @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - Optional fuzzy search caches
|
* @param {Object.<string, { resultMap: Map<string, any> }>} [fuzzySearchCaches=null] - Optional fuzzy search caches
|
||||||
* @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score
|
* @returns {import('fuse.js').FuseResult<any>[]} Results as items with their score
|
||||||
@ -1850,7 +1850,6 @@ function performFuzzySearch(type, data, keys, searchValue, fuzzySearchCaches = n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
const fuse = new Fuse(data, {
|
const fuse = new Fuse(data, {
|
||||||
keys: keys,
|
keys: keys,
|
||||||
includeScore: true,
|
includeScore: true,
|
||||||
@ -1924,7 +1923,7 @@ export function fuzzySearchPersonas(data, searchValue, fuzzySearchCaches = null)
|
|||||||
const mappedData = data.map(x => ({
|
const mappedData = data.map(x => ({
|
||||||
key: x,
|
key: x,
|
||||||
name: power_user.personas[x] ?? '',
|
name: power_user.personas[x] ?? '',
|
||||||
description: power_user.persona_descriptions[x]?.description ?? ''
|
description: power_user.persona_descriptions[x]?.description ?? '',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const keys = [
|
const keys = [
|
||||||
@ -2080,19 +2079,21 @@ const compareFunc = (first, second) => {
|
|||||||
* Sorts an array of entities based on the current sort settings
|
* Sorts an array of entities based on the current sort settings
|
||||||
* @param {any[]} entities An array of objects with an `item` property
|
* @param {any[]} entities An array of objects with an `item` property
|
||||||
* @param {boolean} forceSearch Whether to force search sorting
|
* @param {boolean} forceSearch Whether to force search sorting
|
||||||
|
* @param {import('./filters.js').FilterHelper} [filterHelper=null] Filter helper to use
|
||||||
*/
|
*/
|
||||||
export function sortEntitiesList(entities, forceSearch) {
|
export function sortEntitiesList(entities, forceSearch, filterHelper = null) {
|
||||||
|
filterHelper = filterHelper ?? entitiesFilter;
|
||||||
if (power_user.sort_field == undefined || entities.length === 0) {
|
if (power_user.sort_field == undefined || entities.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (power_user.sort_order === 'random') {
|
const isSearch = forceSearch || $('#character_sort_order option[data-field="search"]').is(':selected');
|
||||||
|
|
||||||
|
if (!isSearch && power_user.sort_order === 'random') {
|
||||||
shuffle(entities);
|
shuffle(entities);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSearch = forceSearch || $('#character_sort_order option[data-field="search"]').is(':selected');
|
|
||||||
|
|
||||||
entities.sort((a, b) => {
|
entities.sort((a, b) => {
|
||||||
// Sort tags/folders will always be at the top
|
// Sort tags/folders will always be at the top
|
||||||
if (a.type === 'tag' && b.type !== 'tag') {
|
if (a.type === 'tag' && b.type !== 'tag') {
|
||||||
@ -2104,8 +2105,8 @@ export function sortEntitiesList(entities, forceSearch) {
|
|||||||
|
|
||||||
// If we have search sorting, we take scores and use those
|
// If we have search sorting, we take scores and use those
|
||||||
if (isSearch) {
|
if (isSearch) {
|
||||||
const aScore = entitiesFilter.getScore(FILTER_TYPES.SEARCH, `${a.type}.${a.id}`);
|
const aScore = filterHelper.getScore(FILTER_TYPES.SEARCH, `${a.type}.${a.id}`);
|
||||||
const bScore = entitiesFilter.getScore(FILTER_TYPES.SEARCH, `${b.type}.${b.id}`);
|
const bScore = filterHelper.getScore(FILTER_TYPES.SEARCH, `${b.type}.${b.id}`);
|
||||||
return (aScore - bScore);
|
return (aScore - bScore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user