Files
DemonGatanjieu-Anomalous_Mo…/tests/quick_search.mjs
T
DemonGatanjieuandClaude Opus 5.5 58b11deae0 Quick search on the canvas (Alt+B)
A bar over the canvas finds combos, models and saved prompts as you type
(GET /anomalous/quick_index lists the models in a few words) and puts the chosen one
where the pointer was. Also in the empty canvas's right-click menu, now registered.
Saved model paths in a linked model folder get their real place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:34:41 +08:00

38 lines
2.3 KiB
JavaScript

// The canvas quick search's matching (web/modules/quick_search_data.js).
import assert from 'node:assert/strict';
import { comboItem, modelItem, promptItem, queryTerms, searchQuick } from '../web/modules/quick_search_data.js';
const models = [
modelItem({ type: 'loras', subfolder: 'chars', filename: 'ahri_v2.safetensors', name: '', civitai_name: 'Ahri (LoL)', base: 'Illustrious', words: ['ahri', 'fox ears'] }),
modelItem({ type: 'checkpoints', subfolder: '', filename: 'waiIllustrious.safetensors', name: 'WAI Illustrious', civitai_name: '', base: 'Illustrious', words: [] }),
modelItem({ type: 'loras', subfolder: '', filename: 'kimono.safetensors', name: '', civitai_name: '', base: 'SDXL', words: ['kimono'] }),
];
const combos = [comboItem({ filename: 'a.json', name: 'Ahri · fox ears' }, { detail: 'WAI Illustrious · 1 LoRA' }), comboItem({ filename: 'b.json', name: 'Beach' })];
const prompts = [promptItem({ id: 'p1', title: 'Fox girl', content: '1girl, fox ears,\n kimono', role: 'positive' })];
const all = [...models, ...combos, ...prompts];
assert.deepEqual(queryTerms(' Fox Ears '), ['fox', 'ears']);
// A model's name: its own, else Civitai's, else the file's.
assert.deepEqual(models.map(item => item.title), ['Ahri (LoL)', 'WAI Illustrious', 'kimono']);
assert.equal(prompts[0].detail, '1girl, fox ears, kimono');
// Every word must appear; groups in the order combos, models, prompts.
let groups = searchQuick(all, 'fox ears');
assert.deepEqual(groups.map(group => group.kind), ['combo', 'model', 'prompt']);
assert.equal(groups[1].items[0].title, 'Ahri (LoL)'); // by its trigger words
// Names starting with the words come first.
groups = searchQuick(all, 'illustrious');
assert.deepEqual(groups.find(group => group.kind === 'model').items.map(item => item.title), ['WAI Illustrious', 'Ahri (LoL)']);
// One kind only, and a cap with how many more.
groups = searchQuick(all, 'a', { kind: 'model', perKind: 1 });
assert.equal(groups.length, 1);
assert.equal(groups[0].more, 2);
// No words: the combos as they are.
groups = searchQuick(all, '');
assert.deepEqual(groups.map(group => group.kind), ['combo']);
assert.equal(groups[0].items.length, 2);
assert.equal(searchQuick(all, '', { kind: 'prompt' })[0].items.length, 1);
// Nothing matches.
assert.deepEqual(searchQuick(all, 'zzz'), []);
console.log('quick search: ok');