[Code] Improve the document search highlights for non-english query (#38154) (#38189)

This commit is contained in:
Mengwei Ding 2019-06-06 15:27:58 -07:00 committed by GitHub
parent ef94824a16
commit 8c7c74aed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -344,12 +344,13 @@ export class DocumentSearchClient extends AbstractSearchClient {
}
private termsToHits(source: string, terms: string[]): SourceHit[] {
if (terms.length === 0) {
const filteredTerms = terms.filter(t => t.trim().length > 0);
if (filteredTerms.length === 0) {
return [];
}
const lineMapper = new LineMapper(source);
const regex = new RegExp(`(${terms.join('|')})`, 'g');
const regex = new RegExp(`(${filteredTerms.join('|')})`, 'g');
let match;
const hits: SourceHit[] = [];
do {