]> gitweb.factorcode.org Git - factor.git/commitdiff
help.html: faster qualified search using an index
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 19 Jun 2022 16:08:10 +0000 (09:08 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 19 Jun 2022 16:08:10 +0000 (09:08 -0700)
basis/help/html/html.factor

index 6b3cfa9d52bef87df71ab4ce534b8836df3deac3..52cac654362e85b67031f655b174c9607c1571b0 100644 (file)
@@ -306,12 +306,21 @@ MEMO: load-index ( name -- index )
 : vocab-apropos ( string -- results )
     "vocabs.idx" offline-apropos ;
 
+: generate-qualified-index ( index -- )
+    H{ } clone [
+        '[
+            over "," split1 nip ".html" ?tail drop
+            [ swap ":" glue 2array ] [ _ push-at ] bi
+        ] assoc-each
+    ] keep [ swap ] { } assoc-map-as
+    "qualified.idx" binary [ serialize ] with-file-writer ;
+
 : qualified-index ( str index -- str index' )
-    over ":" split1 [
-        drop vocab-apropos values [ "," ".html" surround ] map
-        '[ drop _ [ tail? ] with any? ] dupd assoc-filter
-        [ over ".html" ?tail drop "," split1-last nip swap ":" glue ] assoc-map append
-    ] [ drop ] if* ;
+    over ":" split1 drop [ f ] [
+        "qualified.idx"
+        dup file-exists? [ pick generate-qualified-index ] unless
+        load-index completions keys concat
+    ] if-empty [ append ] unless-empty ;
 
 : word-apropos ( string -- results )
     "words.idx" load-index qualified-index completions ;