diff --git a/src/services/search.service.ts b/src/services/search.service.ts index 0c82e1286e..f593e08bbf 100644 --- a/src/services/search.service.ts +++ b/src/services/search.service.ts @@ -3,6 +3,7 @@ import * as lunr from 'lunr'; import { CipherView } from '../models/view/cipherView'; import { CipherService } from '../abstractions/cipher.service'; +import { I18nService } from '../abstractions/i18n.service'; import { LogService } from '../abstractions/log.service'; import { SearchService as SearchServiceAbstraction } from '../abstractions/search.service'; @@ -14,8 +15,13 @@ import { SendView } from '../models/view/sendView'; export class SearchService implements SearchServiceAbstraction { private indexing = false; private index: lunr.Index = null; + private searchableMinLength = 2; - constructor(private cipherService: CipherService, private logService: LogService) { + constructor(private cipherService: CipherService, private logService: LogService, + private i18nService: I18nService) { + if (['zh-CN', 'zh-TW'].indexOf(i18nService.locale) !== -1) { + this.searchableMinLength = 1; + } } clearIndex(): void { @@ -23,8 +29,8 @@ export class SearchService implements SearchServiceAbstraction { } isSearchable(query: string): boolean { - const notSearchable = query == null || (this.index == null && query.length < 2) || - (this.index != null && query.length < 2 && query.indexOf('>') !== 0); + const notSearchable = query == null || (this.index == null && query.length < this.searchableMinLength) || + (this.index != null && query.length < this.searchableMinLength && query.indexOf('>') !== 0); return !notSearchable; }