Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fn

Manav Rathi57cf26c01ced
diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts
index eb84ce3b33..ab491e524d 100644
--- a/web/packages/new/photos/services/search/index.ts
+++ b/web/packages/new/photos/services/search/index.ts
@@ -183,7 +183,6 @@ export const getAutoCompleteSuggestions =
// - getLocationSuggestion(searchPhrase),
// - getFileTypeSuggestion(searchPhrase),
...(await createSearchQuery(searchPhrase)),
- getFileNameSuggestion(searchPhrase2, files),
getFileCaptionSuggestion(searchPhrase2, files),
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
].filter((suggestion) => !!suggestion);
@@ -221,18 +220,6 @@ async function convertSuggestionsToOptions(
return previewImageAppendedOptions;
}
-function getFileNameSuggestion(
- searchPhrase: string,
- files: EnteFile[],
-): Suggestion {
- const matchedFiles = searchFilesByName(searchPhrase, files);
- return {
- type: SuggestionType.FILE_NAME,
- value: matchedFiles.map((file) => file.id),
- label: searchPhrase,
- };
-}
-
function getFileCaptionSuggestion(
searchPhrase: string,
files: EnteFile[],
@@ -245,23 +232,6 @@ function getFileCaptionSuggestion(
};
}
-function searchCollection(
- searchPhrase: string,
- collections: Collection[],
-): Collection[] {
- return collections.filter((collection) =>
- collection.name.toLowerCase().includes(searchPhrase),
- );
-}
-
-function searchFilesByName(searchPhrase: string, files: EnteFile[]) {
- return files.filter(
- (file) =>
- file.id.toString().includes(searchPhrase) ||
- file.metadata.title.toLowerCase().includes(searchPhrase),
- );
-}
-
function searchFilesByCaption(searchPhrase: string, files: EnteFile[]) {
return files.filter(
(file) =>
diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.ts
index d45c85bf24..5bd934b1eb 100644
--- a/web/packages/new/photos/services/search/worker.ts
+++ b/web/packages/new/photos/services/search/worker.ts
@@ -95,15 +95,16 @@ expose(SearchWorker);
const createSearchQuery = (
s: string,
- { collections }: SearchableData,
+ { collections, files }: SearchableData,
{ locale, holidays, labelledFileTypes }: LocalizedSearchData,
locationTags: Searchable<LocationTag>[],
cities: Searchable<City>[],
): Suggestion[] =>
[
- collectionSuggestions(s, collections),
dateSuggestions(s, locale, holidays),
locationSuggestions(s, locationTags, cities),
+ collectionSuggestions(s, collections),
+ fileNameSuggestions(s, files),
fileTypeSuggestions(s, labelledFileTypes),
].flat();
@@ -116,6 +117,24 @@ const collectionSuggestions = (s: string, collections: Collection[]) =>
label: name,
}));
+const fileNameSuggestions = (s: string, files: EnteFile[]) => {
+ // Convert the search string to a number. This allows searching a file by
+ // its exact (integral) ID.
+ const sn = Number(s) || undefined;
+
+ const matchingFiles = files.filter(
+ ({ id, metadata }) =>
+ id === sn || metadata.title.toLowerCase().includes(s),
+ );
+ return matchingFiles.length
+ ? {
+ type: SuggestionType.FILE_NAME,
+ value: matchingFiles.map((f) => f.id),
+ label: s,
+ }
+ : [];
+};
+
const dateSuggestions = (
s: string,
locale: string,