@@ -9,6 +9,8 @@ let cyrillicIndex = null
9
9
let cjkIndex = null
10
10
let pagesByPath = null
11
11
12
+ const cjkRegex = / [ \u4E00 - \u9FCC \u3400 - \u4DB5 \uFA0E \uFA0F \uFA11 \uFA13 \uFA14 \uFA1F \uFA21 \uFA23 \uFA24 \uFA27 - \uFA29 ] | [ \ud840 - \ud868 ] [ \udc00 - \udfff ] | \ud869 [ \udc00 - \uded6 \udf00 - \udfff ] | [ \ud86a - \ud86c ] [ \udc00 - \udfff ] | \ud86d [ \udc00 - \udf34 \udf40 - \udfff ] | \ud86e [ \udc00 - \udc1d ] / giu
13
+
12
14
export default {
13
15
buildIndex ( pages ) {
14
16
const indexSettings = {
@@ -31,16 +33,29 @@ export default {
31
33
if ( cyrillicPages . length ) {
32
34
cyrillicIndex = new Flexsearch ( {
33
35
...indexSettings ,
34
- // charset: cyrillicCharset,
36
+ encode : false ,
37
+ split : / \s + / ,
38
+ tokenize : 'forward' ,
35
39
} )
36
- cyrillicIndex . push ( cyrillicPages )
40
+ cyrillicIndex . add ( cyrillicPages )
37
41
}
38
42
if ( cjkPages . length ) {
39
43
cjkIndex = new Flexsearch ( {
40
44
...indexSettings ,
41
- // charset: cjkCharset,
45
+ encode : false ,
46
+ tokenize : function ( str ) {
47
+ const cjkWords = [ ]
48
+ let m = null
49
+ do {
50
+ m = cjkRegex . exec ( str )
51
+ if ( m ) {
52
+ cjkWords . push ( m [ 0 ] )
53
+ }
54
+ } while ( m )
55
+ return cjkWords
56
+ } ,
42
57
} )
43
- cjkIndex . push ( cjkPages )
58
+ cjkIndex . add ( cjkPages )
44
59
}
45
60
pagesByPath = _ . keyBy ( pages , 'path' )
46
61
} ,
@@ -67,7 +82,7 @@ export default {
67
82
const searchResult1 = await index . search ( searchParams )
68
83
const searchResult2 = cyrillicIndex ? await cyrillicIndex . search ( searchParams ) : [ ]
69
84
const searchResult3 = cjkIndex ? await cjkIndex . search ( searchParams ) : [ ]
70
- const searchResult = [ ...searchResult1 , ...searchResult2 , ...searchResult3 ]
85
+ const searchResult = _ . uniqBy ( [ ...searchResult1 , ...searchResult2 , ...searchResult3 ] , 'path' )
71
86
const result = searchResult . map ( page => ( {
72
87
...page ,
73
88
parentPageTitle : getParentPageTitle ( page ) ,
0 commit comments