mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fuzzy search for groups
This commit is contained in:
@ -74,6 +74,7 @@ import {
|
|||||||
getCustomStoppingStrings,
|
getCustomStoppingStrings,
|
||||||
fuzzySearchCharacters,
|
fuzzySearchCharacters,
|
||||||
MAX_CONTEXT_DEFAULT,
|
MAX_CONTEXT_DEFAULT,
|
||||||
|
fuzzySearchGroups,
|
||||||
} from "./scripts/power-user.js";
|
} from "./scripts/power-user.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -7335,14 +7336,22 @@ $(document).ready(function () {
|
|||||||
$("#character_search_bar").on("input", function () {
|
$("#character_search_bar").on("input", function () {
|
||||||
const selector = ['#rm_print_characters_block .character_select', '#rm_print_characters_block .group_select'].join(',');
|
const selector = ['#rm_print_characters_block .character_select', '#rm_print_characters_block .group_select'].join(',');
|
||||||
const searchValue = $(this).val().trim().toLowerCase();
|
const searchValue = $(this).val().trim().toLowerCase();
|
||||||
const fuzzySearchResults = power_user.fuzzy_search ? fuzzySearchCharacters(searchValue) : [];
|
const fuzzySearchCharactersResults = power_user.fuzzy_search ? fuzzySearchCharacters(searchValue) : [];
|
||||||
|
const fuzzySearchGroupsResults = power_user.fuzzy_search ? fuzzySearchGroups(searchValue) : [];
|
||||||
|
|
||||||
function getIsValidSearch(_this) {
|
function getIsValidSearch(_this) {
|
||||||
const name = $(_this).find(".ch_name").text().toLowerCase();
|
const name = $(_this).find(".ch_name").text().toLowerCase();
|
||||||
const chid = $(_this).attr("chid");
|
const chid = $(_this).attr("chid");
|
||||||
|
const grid = $(_this).attr("grid");
|
||||||
|
|
||||||
if (power_user.fuzzy_search) {
|
if (power_user.fuzzy_search) {
|
||||||
return fuzzySearchResults.includes(parseInt(chid));
|
if (chid !== undefined) {
|
||||||
|
return fuzzySearchCharactersResults.includes(parseInt(chid));
|
||||||
|
} else if (grid !== undefined) {
|
||||||
|
return fuzzySearchGroupsResults.includes(String(grid));
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return name.includes(searchValue);
|
return name.includes(searchValue);
|
||||||
|
@ -953,11 +953,28 @@ export function fuzzySearchCharacters(searchValue) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const results = fuse.search(searchValue);
|
const results = fuse.search(searchValue);
|
||||||
console.debug('Fuzzy search results for ' + searchValue, results)
|
console.debug('Characters fuzzy search results for ' + searchValue, results);
|
||||||
const indices = results.map(x => x.refIndex);
|
const indices = results.map(x => x.refIndex);
|
||||||
return indices;
|
return indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fuzzySearchGroups(searchValue) {
|
||||||
|
const fuse = new Fuse(groups, {
|
||||||
|
keys: [
|
||||||
|
{ name: 'name', weight: 3 },
|
||||||
|
{ name: 'members', weight: 1 },
|
||||||
|
],
|
||||||
|
includeScore: true,
|
||||||
|
ignoreLocation: true,
|
||||||
|
threshold: 0.2,
|
||||||
|
});
|
||||||
|
|
||||||
|
const results = fuse.search(searchValue);
|
||||||
|
console.debug('Groups fuzzy search results for ' + searchValue, results);
|
||||||
|
const ids = results.map(x => String(x.item?.id)).filter(x => x);
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2) {
|
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2) {
|
||||||
let includeNames = isNarrator ? false : power_user.instruct.names;
|
let includeNames = isNarrator ? false : power_user.instruct.names;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user