θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import strDistance from "js-levenshtein";

const LEVENSHTEIN_MIN = 8;
const LEVENSHTEIN_MIN = 2;

// Regular expression pattern to match the v4 UUID and the ending .json
const uuidPattern =
Expand All @@ -18,20 +18,33 @@ export const stripUuidAndJsonFromString = (input = "") => {
export function filterFileSearchResults(files = [], searchTerm = "") {
if (!searchTerm) return files?.items || [];

const normalizedSearchTerm = searchTerm.toLowerCase().trim();

const searchResult = [];
for (const folder of files?.items) {
// If folder is a good match then add all its children
if (strDistance(folder.name, searchTerm) <= LEVENSHTEIN_MIN) {
const folderNameNormalized = folder.name.toLowerCase();

// Check for exact match first, then fuzzy match
if (folderNameNormalized.includes(normalizedSearchTerm)) {
searchResult.push(folder);
continue;
}

// Otherwise check children for good results
// Check children for matches
const fileSearchResults = [];
for (const file of folder?.items) {
if (
strDistance(stripUuidAndJsonFromString(file.name), searchTerm) <=
LEVENSHTEIN_MIN
const fileNameNormalized = stripUuidAndJsonFromString(
file.name
).toLowerCase();

// Exact match check
if (fileNameNormalized.includes(normalizedSearchTerm)) {
fileSearchResults.push(file);
}
// Fuzzy match only if no exact matches found
else if (
fileSearchResults.length === 0 &&
strDistance(fileNameNormalized, normalizedSearchTerm) <= LEVENSHTEIN_MIN
) {
fileSearchResults.push(file);
}
Expand Down