]> gitweb.factorcode.org Git - factor.git/commitdiff
help.search: allow searching within help articles.
authorJohn Benediktsson <mrjbq7@gmail.com>
Tue, 31 Jul 2012 17:31:05 +0000 (10:31 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 31 Jul 2012 17:31:05 +0000 (10:31 -0700)
basis/help/search/authors.txt [new file with mode: 0644]
basis/help/search/search.factor [new file with mode: 0644]
basis/help/search/summary [new file with mode: 0644]

diff --git a/basis/help/search/authors.txt b/basis/help/search/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/basis/help/search/search.factor b/basis/help/search/search.factor
new file mode 100644 (file)
index 0000000..a2f671c
--- /dev/null
@@ -0,0 +1,33 @@
+! Copyright (C) 2012 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: fry help help.markup help.topics io kernel memoize
+sequences sequences.deep sorting splitting strings unicode.case
+unicode.categories ;
+
+IN: help.search
+
+<PRIVATE
+
+: (article-words) ( name -- words )
+    article-content [ string? ] filter
+    [ >lower [ blank? ] split-when ] map concat
+    [ CHAR: - over member? [ "-" split ] when ] map
+    flatten harvest ;
+
+MEMO: article-words ( name -- words )
+    (article-words) [
+        dup [ letter? not ] any? [
+            [ [ letter? ] [ digit? ] bi or not ] split-when
+        ] when
+    ] map flatten [ [ digit? ] all? not ] filter harvest ;
+
+PRIVATE>
+
+: search-docs ( string -- seq' )
+    [ all-articles ] dip >lower [ blank? ] split-when
+    '[ article-words [ _ member? ] any? ] filter
+    [ article-name ] sort-with ;
+
+: search-docs. ( string -- )
+    search-docs [ ($link) nl ] each ;
diff --git a/basis/help/search/summary b/basis/help/search/summary
new file mode 100644 (file)
index 0000000..04be82b
--- /dev/null
@@ -0,0 +1 @@
+Search within help articles