Fuzzy search for groups
This commit is contained in:
parent
32745609a2
commit
15db16ee8d
|
@ -74,6 +74,7 @@ import {
|
|||
getCustomStoppingStrings,
|
||||
fuzzySearchCharacters,
|
||||
MAX_CONTEXT_DEFAULT,
|
||||
fuzzySearchGroups,
|
||||
} from "./scripts/power-user.js";
|
||||
|
||||
import {
|
||||
|
@ -7335,14 +7336,22 @@ $(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) : [];
|
||||
const fuzzySearchCharactersResults = power_user.fuzzy_search ? fuzzySearchCharacters(searchValue) : [];
|
||||
const fuzzySearchGroupsResults = power_user.fuzzy_search ? fuzzySearchGroups(searchValue) : [];
|
||||
|
||||
function getIsValidSearch(_this) {
|
||||
const name = $(_this).find(".ch_name").text().toLowerCase();
|
||||
const chid = $(_this).attr("chid");
|
||||
const grid = $(_this).attr("grid");
|
||||
|
||||
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 {
|
||||
return name.includes(searchValue);
|
||||
|
|
|
@ -953,11 +953,28 @@ export function fuzzySearchCharacters(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);
|
||||
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) {
|
||||
let includeNames = isNarrator ? false : power_user.instruct.names;
|
||||
|
||||
|
|
Loading…
Reference in New Issue