Refactor search functionality in Lora and Recipe scanners to utilize fuzzy matching

- Introduced a new fuzzy_match utility function for improved search accuracy across Lora and Recipe scanners.
- Updated search logic in LoraScanner and RecipeScanner to leverage fuzzy matching for titles, tags, and filenames, enhancing user experience.
- Removed deprecated search methods to streamline the codebase and improve maintainability.
- Adjusted API routes to ensure compatibility with the new search options, including recursive search handling.
This commit is contained in:
Will Miao
2025-03-20 16:55:51 +08:00
parent 19ff2ebfe1
commit 607ab35cce
7 changed files with 98 additions and 106 deletions

View File

@@ -18,6 +18,7 @@ export async function loadMoreLoras(resetPage = false, updateFolders = false) {
// Clear grid if resetting
const grid = document.getElementById('loraGrid');
if (grid) grid.innerHTML = '';
initializeInfiniteScroll();
}
const params = new URLSearchParams({
@@ -26,12 +27,8 @@ export async function loadMoreLoras(resetPage = false, updateFolders = false) {
sort_by: pageState.sortBy
});
// Use pageState instead of state
const isRecursiveSearch = pageState.searchOptions?.recursive ?? false;
if (pageState.activeFolder !== null) {
params.append('folder', pageState.activeFolder);
params.append('recursive', isRecursiveSearch.toString());
}
// Add search parameters if there's a search term
@@ -44,6 +41,7 @@ export async function loadMoreLoras(resetPage = false, updateFolders = false) {
params.append('search_filename', pageState.searchOptions.filename.toString());
params.append('search_modelname', pageState.searchOptions.modelname.toString());
params.append('search_tags', (pageState.searchOptions.tags || false).toString());
params.append('recursive', (pageState.searchOptions?.recursive ?? false).toString());
}
}

View File

@@ -131,8 +131,8 @@ class RecipeManager {
// Update recipes grid
this.updateRecipesGrid(data, resetPage);
// Update pagination state
this.pageState.hasMore = data.has_more || false;
// Update pagination state based on current page and total pages
this.pageState.hasMore = data.page < data.total_pages;
} catch (error) {
console.error('Error loading recipes:', error);