From 728e40fbfa328e00a081ae34a846af949a8eb27d Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 7 Apr 2021 22:51:34 +0800 Subject: [PATCH] Optimize isSearchable for Chinese. (#330) * Optimize isSearchable for Chinese. * Fix lint. * Fix lint. --- src/services/search.service.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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; }