mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
Optimize isSearchable for Chinese. (#330)
* Optimize isSearchable for Chinese. * Fix lint. * Fix lint.
This commit is contained in:
parent
97ece68dec
commit
728e40fbfa
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user