mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Advanced Character Search #786
This commit is contained in:
@ -2372,6 +2372,10 @@
|
|||||||
<input id="swipes-checkbox" type="checkbox" />
|
<input id="swipes-checkbox" type="checkbox" />
|
||||||
<span data-i18n="Swipes">Swipes</span>
|
<span data-i18n="Swipes">Swipes</span>
|
||||||
</label>
|
</label>
|
||||||
|
<label for="fuzzy_search_checkbox">
|
||||||
|
<input id="fuzzy_search_checkbox" type="checkbox" />
|
||||||
|
<span data-i18n="Advanced Character Search">Advanced Character Search</span>
|
||||||
|
</label>
|
||||||
<label for="prefer_character_prompt" title="If checked and the character card contains a prompt override (System Prompt), use that instead." data-i18n="[title]If checked and the character card contains a prompt override (System Prompt), use that instead." class="checkbox_label">
|
<label for="prefer_character_prompt" title="If checked and the character card contains a prompt override (System Prompt), use that instead." data-i18n="[title]If checked and the character card contains a prompt override (System Prompt), use that instead." class="checkbox_label">
|
||||||
<input id="prefer_character_prompt" type="checkbox" />
|
<input id="prefer_character_prompt" type="checkbox" />
|
||||||
<span data-i18n="Prefer Character Card Prompt">Prefer Char. Prompt</span>
|
<span data-i18n="Prefer Character Card Prompt">Prefer Char. Prompt</span>
|
||||||
|
@ -76,6 +76,7 @@ import {
|
|||||||
persona_description_positions,
|
persona_description_positions,
|
||||||
loadMovingUIState,
|
loadMovingUIState,
|
||||||
getCustomStoppingStrings,
|
getCustomStoppingStrings,
|
||||||
|
fuzzySearchCharacters,
|
||||||
MAX_CONTEXT_DEFAULT,
|
MAX_CONTEXT_DEFAULT,
|
||||||
} from "./scripts/power-user.js";
|
} from "./scripts/power-user.js";
|
||||||
|
|
||||||
@ -7037,18 +7038,26 @@ $(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) : [];
|
||||||
|
|
||||||
|
function getIsValidSearch(_this) {
|
||||||
|
const name = $(_this).find(".ch_name").text().toLowerCase();
|
||||||
|
const chid = $(_this).attr("chid");
|
||||||
|
|
||||||
|
if (power_user.fuzzy_search) {
|
||||||
|
return fuzzySearchResults.includes(parseInt(chid));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return name.includes(searchValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!searchValue) {
|
if (!searchValue) {
|
||||||
$(selector).removeClass('hiddenBySearch');
|
$(selector).removeClass('hiddenBySearch');
|
||||||
updateVisibleDivs('#rm_print_characters_block', true);
|
updateVisibleDivs('#rm_print_characters_block', true);
|
||||||
} else {
|
} else {
|
||||||
$(selector).each(function () {
|
$(selector).each(function () {
|
||||||
const isValidSearch = $(this)
|
const isValidSearch = getIsValidSearch(this);
|
||||||
.find(".ch_name")
|
|
||||||
.text()
|
|
||||||
.toLowerCase()
|
|
||||||
.includes(searchValue);
|
|
||||||
|
|
||||||
$(this).toggleClass('hiddenBySearch', !isValidSearch);
|
$(this).toggleClass('hiddenBySearch', !isValidSearch);
|
||||||
});
|
});
|
||||||
updateVisibleDivs('#rm_print_characters_block', true);
|
updateVisibleDivs('#rm_print_characters_block', true);
|
||||||
@ -7234,7 +7243,7 @@ $(document).ready(function () {
|
|||||||
const data = { old_bg, new_bg };
|
const data = { old_bg, new_bg };
|
||||||
const response = await fetch('/renamebackground', {
|
const response = await fetch('/renamebackground', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers:getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
});
|
});
|
||||||
|
@ -186,6 +186,7 @@ let power_user = {
|
|||||||
persona_description_position: persona_description_positions.BEFORE_CHAR,
|
persona_description_position: persona_description_positions.BEFORE_CHAR,
|
||||||
|
|
||||||
custom_stopping_strings: '',
|
custom_stopping_strings: '',
|
||||||
|
fuzzy_search: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let themes = [];
|
let themes = [];
|
||||||
@ -676,6 +677,7 @@ function loadPowerUserSettings(settings, data) {
|
|||||||
$('#auto_swipe_blacklist').val(power_user.auto_swipe_blacklist.join(", "));
|
$('#auto_swipe_blacklist').val(power_user.auto_swipe_blacklist.join(", "));
|
||||||
$('#auto_swipe_blacklist_threshold').val(power_user.auto_swipe_blacklist_threshold);
|
$('#auto_swipe_blacklist_threshold').val(power_user.auto_swipe_blacklist_threshold);
|
||||||
$('#custom_stopping_strings').val(power_user.custom_stopping_strings);
|
$('#custom_stopping_strings').val(power_user.custom_stopping_strings);
|
||||||
|
$('#fuzzy_search_checkbox').prop("checked", power_user.fuzzy_search);
|
||||||
|
|
||||||
$("#console_log_prompts").prop("checked", power_user.console_log_prompts);
|
$("#console_log_prompts").prop("checked", power_user.console_log_prompts);
|
||||||
$('#auto_fix_generated_markdown').prop("checked", power_user.auto_fix_generated_markdown);
|
$('#auto_fix_generated_markdown').prop("checked", power_user.auto_fix_generated_markdown);
|
||||||
@ -896,6 +898,31 @@ function loadInstructMode() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fuzzySearchCharacters(searchValue) {
|
||||||
|
const fuse = new Fuse(characters, {
|
||||||
|
keys: [
|
||||||
|
{ name: 'data.name', weight: 5 },
|
||||||
|
{ name: 'data.description', weight: 3 },
|
||||||
|
{ name: 'data.mes_example', weight: 3 },
|
||||||
|
{ name: 'data.scenario', weight: 2 },
|
||||||
|
{ name: 'data.personality', weight: 2 },
|
||||||
|
{ name: 'data.first_mes', weight: 2 },
|
||||||
|
{ name: 'data.creator_notes', weight: 2 },
|
||||||
|
{ name: 'data.creator', weight: 1 },
|
||||||
|
{ name: 'data.tags', weight: 1 },
|
||||||
|
{ name: 'data.alternate_greetings', weight: 1 }
|
||||||
|
],
|
||||||
|
includeScore: true,
|
||||||
|
ignoreLocation: true,
|
||||||
|
threshold: 0.2,
|
||||||
|
});
|
||||||
|
|
||||||
|
const results = fuse.search(searchValue);
|
||||||
|
console.debug('Fuzzy search results for ' + searchValue, results)
|
||||||
|
const indices = results.map(x => x.refIndex);
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2) {
|
export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvatar, name1, name2) {
|
||||||
const includeNames = isNarrator ? false : (power_user.instruct.names || !!selected_group || !!forceAvatar);
|
const includeNames = isNarrator ? false : (power_user.instruct.names || !!selected_group || !!forceAvatar);
|
||||||
let sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence;
|
let sequence = (isUser || isNarrator) ? power_user.instruct.input_sequence : power_user.instruct.output_sequence;
|
||||||
@ -1972,6 +1999,11 @@ $(document).ready(() => {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#fuzzy_search_checkbox').on('input', function () {
|
||||||
|
power_user.fuzzy_search = !!$(this).prop('checked');
|
||||||
|
saveSettingsDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
$(window).on('focus', function () {
|
$(window).on('focus', function () {
|
||||||
browser_has_focus = true;
|
browser_has_focus = true;
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user