File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ function initSearch() {
129129
130130 return token ;
131131 } ;
132+
132133 const index = elasticlunr ( function ( ) {
133134 this . addField ( "fnName" ) ;
134135 this . addField ( "desc" ) ;
@@ -139,6 +140,37 @@ function initSearch() {
139140 elasticlunr . Pipeline . registerFunction ( elasticlunr . trimmer , "trimmer" ) ;
140141 elasticlunr . tokenizer . seperator = / [ \s ~ ~ ] + / ;
141142 } ) ;
143+
144+ // Custom tokenizer to handle symbols with '/'
145+ const originalTokenizer = elasticlunr . tokenizer ;
146+ elasticlunr . tokenizer = function ( obj , metadata ) {
147+ if ( obj == null || obj == undefined ) {
148+ return [ ] ;
149+ }
150+
151+ if ( Array . isArray ( obj ) ) {
152+ return obj . reduce ( function ( tokens , token ) {
153+ return tokens . concat ( elasticlunr . tokenizer ( token , metadata ) ) ;
154+ } , [ ] ) ;
155+ }
156+
157+ const str = obj . toString ( ) . toLowerCase ( ) ;
158+ const tokens = originalTokenizer ( str , metadata ) ;
159+
160+ // Add additional tokens for strings containing '/'
161+ if ( str . includes ( '/' ) ) {
162+ const parts = str . split ( '/' ) ;
163+ if ( parts . length > 1 ) {
164+ const lastPart = parts [ parts . length - 1 ] ;
165+ if ( lastPart ) {
166+ tokens . push ( lastPart ) ;
167+ }
168+ }
169+ }
170+
171+ return tokens ;
172+ } ;
173+
142174 // Load symbols into elasticlunr object
143175 window . searchIndexApi . forEach ( item => index . addDoc ( item ) ) ;
144176
You can’t perform that action at this time.
0 commit comments