@@ -22,17 +22,22 @@ function matchCaseSensitive(declName, lowerDeclName, pat) {
22
22
}
23
23
}
24
24
25
- function loadDecls ( declBmpCnt ) {
26
- return declBmpCnt . split ( '\n' ) . map ( d => [ d , d . toLowerCase ( ) ] ) ;
25
+ function loadDecls ( searchableDataCnt ) {
26
+ return searchableDataCnt . map ( ( { name , description } ) => [ name , name . toLowerCase ( ) , description . toLowerCase ( ) ] )
27
27
}
28
28
29
- function getMatches ( decls , pat , maxResults = 20 ) {
30
- // const lowerPat = pat.toLowerCase();
31
- // const caseSensitive = pat !== lowerPat;
29
+ function getMatches ( decls , pat , maxResults = 30 ) {
30
+ const lowerPats = pat . toLowerCase ( ) . split ( / \s / g) ;
32
31
const patNoSpaces = pat . replace ( / \s / g, '' ) ;
33
32
const results = [ ] ;
34
- for ( const [ decl , lowerDecl ] of decls ) {
35
- const err = matchCaseSensitive ( decl , lowerDecl , patNoSpaces ) ;
33
+ for ( const [ decl , lowerDecl , lowerDoc ] of decls ) {
34
+ let err = matchCaseSensitive ( decl , lowerDecl , patNoSpaces ) ;
35
+
36
+ // match all words as substrings of docstring
37
+ if ( ! ( err < 3 ) && pat . length > 3 && lowerPats . every ( l => lowerDoc . indexOf ( l ) != - 1 ) ) {
38
+ err = 3 ;
39
+ }
40
+
36
41
if ( err !== undefined ) {
37
42
results . push ( { decl, err} ) ;
38
43
}
@@ -41,6 +46,6 @@ function getMatches(decls, pat, maxResults = 20) {
41
46
}
42
47
43
48
if ( typeof process === 'object' ) { // NodeJS
44
- const declNames = loadDecls ( require ( 'fs' ) . readFileSync ( 'html/decl .bmp' ) . toString ( ) ) ;
45
- console . log ( getMatches ( declNames , process . argv [ 2 ] || 'ltltle' , 20 ) ) ;
49
+ const data = loadDecls ( JSON . parse ( require ( 'fs' ) . readFileSync ( 'searchable_data .bmp' ) . toString ( ) ) ) ;
50
+ console . log ( getMatches ( data , process . argv [ 2 ] || 'ltltle' ) ) ;
46
51
}
0 commit comments