Advanced Character Search #786
This commit is contained in:
parent
ddf485f354
commit
707ce62017
|
@ -2372,6 +2372,10 @@
|
|||
<input id="swipes-checkbox" type="checkbox" />
|
||||
<span data-i18n="Swipes">Swipes</span>
|
||||
</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">
|
||||
<input id="prefer_character_prompt" type="checkbox" />
|
||||
<span data-i18n="Prefer Character Card Prompt">Prefer Char. Prompt</span>
|
||||
|
|
|
@ -76,6 +76,7 @@ import {
|
|||
persona_description_positions,
|
||||
loadMovingUIState,
|
||||
getCustomStoppingStrings,
|
||||
fuzzySearchCharacters,
|
||||
MAX_CONTEXT_DEFAULT,
|
||||
} from "./scripts/power-user.js";
|
||||
|
||||
|
@ -7037,18 +7038,26 @@ $(document).ready(function () {
|
|||
$("#character_search_bar").on("input", function () {
|
||||
const selector = ['#rm_print_characters_block .character_select', '#rm_print_characters_block .group_select'].join(',');
|
||||
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) {
|
||||
$(selector).removeClass('hiddenBySearch');
|
||||
updateVisibleDivs('#rm_print_characters_block', true);
|
||||
} else {
|
||||
$(selector).each(function () {
|
||||
const isValidSearch = $(this)
|
||||
.find(".ch_name")
|
||||
.text()
|
||||
.toLowerCase()
|
||||
.includes(searchValue);
|
||||
|
||||
const isValidSearch = getIsValidSearch(this);
|
||||
$(this).toggleClass('hiddenBySearch', !isValidSearch);
|
||||
});
|
||||
updateVisibleDivs('#rm_print_characters_block', true);
|
||||
|
@ -7234,7 +7243,7 @@ $(document).ready(function () {
|
|||
const data = { old_bg, new_bg };
|
||||
const response = await fetch('/renamebackground', {
|
||||
method: 'POST',
|
||||
headers:getRequestHeaders(),
|
||||
headers: getRequestHeaders(),
|
||||
body: JSON.stringify(data),
|
||||
cache: 'no-cache',
|
||||
});
|
||||
|
@ -7973,7 +7982,7 @@ $(document).ready(function () {
|
|||
.append(
|
||||
`<textarea id='curEditTextarea' class='edit_textarea' style='max-width:auto;'></textarea>`
|
||||
);
|
||||
$('#curEditTextarea').val(text);
|
||||
$('#curEditTextarea').val(text);
|
||||
let edit_textarea = $(this)
|
||||
.closest(".mes_block")
|
||||
.find(".edit_textarea");
|
||||
|
|
|
@ -186,6 +186,7 @@ let power_user = {
|
|||
persona_description_position: persona_description_positions.BEFORE_CHAR,
|
||||
|
||||
custom_stopping_strings: '',
|
||||
fuzzy_search: false,
|
||||
};
|
||||
|
||||
let themes = [];
|
||||
|
@ -676,6 +677,7 @@ function loadPowerUserSettings(settings, data) {
|
|||
$('#auto_swipe_blacklist').val(power_user.auto_swipe_blacklist.join(", "));
|
||||
$('#auto_swipe_blacklist_threshold').val(power_user.auto_swipe_blacklist_threshold);
|
||||
$('#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);
|
||||
$('#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) {
|
||||
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;
|
||||
|
@ -1972,6 +1999,11 @@ $(document).ready(() => {
|
|||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#fuzzy_search_checkbox').on('input', function () {
|
||||
power_user.fuzzy_search = !!$(this).prop('checked');
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$(window).on('focus', function () {
|
||||
browser_has_focus = true;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue