1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-19 02:51:14 +02:00

Optimize isSearchable for Chinese. (#330)

* Optimize isSearchable for Chinese.

* Fix lint.

* Fix lint.
This commit is contained in:
Steven 2021-04-07 22:51:34 +08:00 committed by GitHub
parent 97ece68dec
commit 728e40fbfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ import * as lunr from 'lunr';
import { CipherView } from '../models/view/cipherView'; import { CipherView } from '../models/view/cipherView';
import { CipherService } from '../abstractions/cipher.service'; import { CipherService } from '../abstractions/cipher.service';
import { I18nService } from '../abstractions/i18n.service';
import { LogService } from '../abstractions/log.service'; import { LogService } from '../abstractions/log.service';
import { SearchService as SearchServiceAbstraction } from '../abstractions/search.service'; import { SearchService as SearchServiceAbstraction } from '../abstractions/search.service';
@ -14,8 +15,13 @@ import { SendView } from '../models/view/sendView';
export class SearchService implements SearchServiceAbstraction { export class SearchService implements SearchServiceAbstraction {
private indexing = false; private indexing = false;
private index: lunr.Index = null; 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 { clearIndex(): void {
@ -23,8 +29,8 @@ export class SearchService implements SearchServiceAbstraction {
} }
isSearchable(query: string): boolean { isSearchable(query: string): boolean {
const notSearchable = query == null || (this.index == null && query.length < 2) || const notSearchable = query == null || (this.index == null && query.length < this.searchableMinLength) ||
(this.index != null && query.length < 2 && query.indexOf('>') !== 0); (this.index != null && query.length < this.searchableMinLength && query.indexOf('>') !== 0);
return !notSearchable; return !notSearchable;
} }