This commit is contained in:
Manav Rathi
2024-09-12 16:03:56 +05:30
parent 38b3e04718
commit 2990ba855f
2 changed files with 39 additions and 13 deletions

View File

@@ -102,19 +102,31 @@ const clipSuggestion = async (
return { type: "clip", clipScoreForFileID: matches, label: searchString };
};
const suggestionsToOptions = async (suggestions: SearchSuggestion[]) =>
Promise.all(
suggestions.map(async (suggestion) => {
const matchingFiles = await filterSearchableFiles(suggestion);
return matchingFiles.length
? {
suggestion,
fileCount: matchingFiles.length,
previewFiles: matchingFiles.slice(0, 3),
}
: undefined;
}),
).then((r) => r.filter((o) => !!o));
// const suggestionsToOptions = async (suggestions: SearchSuggestion[]) =>
// Promise.all(
// suggestions.map(async (suggestion) => {
// const matchingFiles = await filterSearchableFiles(suggestion);
// return matchingFiles.length
// ? {
// suggestion,
// fileCount: matchingFiles.length,
// previewFiles: matchingFiles.slice(0, 3),
// }
// : undefined;
// }),
// ).then((r) => r.filter((o) => !!o));
const suggestionsToOptions = async (suggestions: SearchSuggestion[]) => {
const filess = await filterSearchableFiles2(suggestions);
const f2 = filess.map((f, i) => [f, suggestions[i]!] as const);
return f2
.filter(([fs]) => fs.length)
.map(([f, s]) => ({
// suggestion: suggestions[i],
suggestion: s,
fileCount: f.length,
previewFiles: f.slice(0, 3),
}));
};
/**
* Return the list of {@link EnteFile}s (from amongst the previously set
@@ -123,6 +135,9 @@ const suggestionsToOptions = async (suggestions: SearchSuggestion[]) =>
export const filterSearchableFiles = async (suggestion: SearchSuggestion) =>
worker().then((w) => w.filterSearchableFiles(suggestion));
export const filterSearchableFiles2 = async (suggestion: SearchSuggestion[]) =>
worker().then((w) => w.filterSearchableFiles2(suggestion));
/**
* Cached value of {@link localizedSearchData}.
*/

View File

@@ -96,6 +96,17 @@ export class SearchWorker {
suggestion,
);
}
filterSearchableFiles2(suggestions: SearchSuggestion[]) {
return suggestions.map((suggestion) => {
return sortMatchesIfNeeded(
this.searchableData.files.filter((f) =>
isMatchingFile(f, suggestion),
),
suggestion,
);
});
}
}
expose(SearchWorker);