π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Lowercased + searchable
Manav Rathie9a6b55ba42a
diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.tsindex cd19fb0c9f..42f2054ced 100644--- a/web/apps/photos/src/services/searchService.ts+++ b/web/apps/photos/src/services/searchService.ts@@ -48,7 +48,6 @@ export const getAutoCompleteSuggestions =// - getDateSuggestion(searchPhrase),// - getLocationSuggestion(searchPhrase),...(await createSearchQuery(searchPhrase)),- ...getFileTypeSuggestion(searchPhrase2),...getCollectionSuggestion(searchPhrase2, collections),getFileNameSuggestion(searchPhrase2, files),getFileCaptionSuggestion(searchPhrase2, files),@@ -85,27 +84,6 @@ async function convertSuggestionsToOptions(}return previewImageAppendedOptions;}-function getFileTypeSuggestion(searchPhrase: string): Suggestion[] {- return [- {- label: t("IMAGE"),- value: FileType.image,- type: SuggestionType.FILE_TYPE,- },- {- label: t("VIDEO"),- value: FileType.video,- type: SuggestionType.FILE_TYPE,- },- {- label: t("LIVE_PHOTO"),- value: FileType.livePhoto,- type: SuggestionType.FILE_TYPE,- },- ].filter((suggestion) =>- suggestion.label.toLowerCase().includes(searchPhrase),- );-}export async function getAllPeopleSuggestion(): Promise<Array<Suggestion>> {try {diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.tsindex 7a8dd9e749..cfd7a0ca21 100644--- a/web/packages/new/photos/services/search/index.ts+++ b/web/packages/new/photos/services/search/index.ts@@ -121,8 +121,14 @@ let _localizedSearchData: LocalizedSearchData | undefined;const localizedSearchData = () =>(_localizedSearchData ??= {locale: i18n.language,- holidays: holidays(),- labelledFileTypes: labelledFileTypes(),+ holidays: holidays().map((h) => ({+ ...h,+ lowercasedName: h.label.toLowerCase(),+ })),+ labelledFileTypes: labelledFileTypes().map((t) => ({+ ...t,+ lowercasedName: t.label.toLowerCase(),+ })),});/**diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.tsindex 9066f12791..b2130e4bbc 100644--- a/web/packages/new/photos/services/search/types.ts+++ b/web/packages/new/photos/services/search/types.ts@@ -19,14 +19,28 @@ export interface LabelledFileType {label: string;}+/**+ * An annotated version of {@link T} that includes its searchable "lowercased"+ * label or name.+ *+ * Precomputing these lowercased values saves us from doing the lowercasing+ * during the search itself.+ */+export type Searchable<T> = T & {+ /**+ * The name or label of T, lowercased.+ */+ lowercasedName: string;+};+/*** Various bits of static but locale specific data that the search worker needs* during searching.*/export interface LocalizedSearchData {locale: string;- holidays: DateSearchResult[];- labelledFileTypes: LabelledFileType[];+ holidays: Searchable<DateSearchResult>[];+ labelledFileTypes: Searchable<LabelledFileType>[];}/**diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.tsindex 62e21af4bf..ca842d40d6 100644--- a/web/packages/new/photos/services/search/worker.ts+++ b/web/packages/new/photos/services/search/worker.ts@@ -16,36 +16,23 @@ import {import type {City,DateSearchResult,+ LabelledFileType,LocalizedSearchData,+ Searchable,SearchDateComponents,SearchQuery,Suggestion,} from "./types";import { SuggestionType } from "./types";-type SearchableCity = City & {- /**- * Name of the city, lowercased. Precomputed to save an op during search.- */- lowercasedName: string;-};--type SearchableLocationTag = LocationTag & {- /**- * Name of the location tag, lowercased. Precomputed to save an op during- * search.- */- lowercasedName: string;-};-/*** A web worker that runs the search asynchronously so that the main thread* remains responsive.*/export class SearchWorker {private enteFiles: EnteFile[] = [];- private locationTags: SearchableLocationTag[] = [];- private cities: SearchableCity[] = [];+ private locationTags: Searchable<LocationTag>[] = [];+ private cities: Searchable<City>[] = [];/*** Fetch any state we might need when the actual search happens.@@ -103,19 +90,20 @@ expose(SearchWorker);const createSearchQuery = (s: string,- { locale, holidays }: LocalizedSearchData,- locationTags: SearchableLocationTag[],- cities: SearchableCity[],+ { locale, holidays, labelledFileTypes }: LocalizedSearchData,+ locationTags: Searchable<LocationTag>[],+ cities: Searchable<City>[],): Suggestion[] =>[dateSuggestions(s, locale, holidays),locationSuggestions(s, locationTags, cities),+ fileTypeSuggestions(s, labelledFileTypes),].flat();const dateSuggestions = (s: string,locale: string,- holidays: DateSearchResult[],+ holidays: Searchable<DateSearchResult>[],) =>parseDateComponents(s, locale, holidays).map(({ components, label }) => ({type: SuggestionType.DATE,@@ -140,12 +128,12 @@ const dateSuggestions = (const parseDateComponents = (s: string,locale: string,- holidays: DateSearchResult[],+ holidays: Searchable<DateSearchResult>[],): DateSearchResult[] =>[parseChrono(s, locale),parseYearComponents(s),- parseHolidayComponents(s, holidays),+ holidays.filter(searchableIncludes(s)),].flat();const parseChrono = (s: string, locale: string): DateSearchResult[] =>@@ -194,8 +182,13 @@ const parseYearComponents = (s: string): DateSearchResult[] => {return [];};-const parseHolidayComponents = (s: string, holidays: DateSearchResult[]) =>- holidays.filter(({ label }) => label.toLowerCase().includes(s));+/**+ * A helper function to directly pass to filters on Searchable<T>[].+ */+const searchableIncludes =+ (s: string) =>+ ({ lowercasedName }: { lowercasedName: string }) =>+ lowercasedName.includes(s);/*** Zod schema describing world_cities.json.@@ -222,12 +215,10 @@ const fetchCities = async () => {const locationSuggestions = (s: string,- locationTags: SearchableLocationTag[],- cities: SearchableCity[],+ locationTags: Searchable<LocationTag>[],+ cities: Searchable<City>[],) => {- const matchingLocationTags = locationTags.filter((t) =>- t.lowercasedName.includes(s),- );+ const matchingLocationTags = locationTags.filter(searchableIncludes(s));const matchingLocationTagLNames = new Set(matchingLocationTags.map((t) => t.lowercasedName),@@ -253,6 +244,18 @@ const locationSuggestions = (].flat();};+const fileTypeSuggestions = (+ s: string,+ labelledFileTypes: Searchable<LabelledFileType>[],+) =>+ labelledFileTypes+ .filter(searchableIncludes(s))+ .map(({ fileType, label }) => ({+ label,+ value: fileType,+ type: SuggestionType.FILE_TYPE,+ }));+/*** Return true if file satisfies the given {@link query}.*/