feat: enhance search with include/exclude tokens and improved sorting

- Add token parsing to support include/exclude search terms using "-" prefix
- Implement token-based matching logic for relative path searches
- Improve search result sorting by prioritizing prefix matches and match position
- Add frontend test for multi-token highlighting with exclusion support
This commit is contained in:
Will Miao
2025-11-21 19:48:43 +08:00
parent 9a789f8f08
commit ea1d1a49c9
4 changed files with 167 additions and 12 deletions

View File

@@ -136,4 +136,23 @@ describe('AutoComplete widget interactions', () => {
expect(input.focus).toHaveBeenCalled();
expect(input.setSelectionRange).toHaveBeenCalled();
});
it('highlights multiple include tokens while ignoring excluded ones', async () => {
const input = document.createElement('textarea');
document.body.append(input);
const { AutoComplete } = await import(AUTOCOMPLETE_MODULE);
const autoComplete = new AutoComplete(input, 'loras', { showPreview: false });
const highlighted = autoComplete.highlightMatch(
'models/flux/beta-detail.safetensors',
'flux detail -beta',
);
const highlightCount = (highlighted.match(/<span/g) || []).length;
expect(highlightCount).toBe(2);
expect(highlighted).toContain('flux');
expect(highlighted).toContain('detail');
expect(highlighted).not.toMatch(/beta<\/span>/i);
});
});