]> gitweb.factorcode.org Git - factor.git/blob - basis/help/search/search.factor
help.search: allow searching within help articles.
[factor.git] / basis / help / search / search.factor
1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: fry help help.markup help.topics io kernel memoize
5 sequences sequences.deep sorting splitting strings unicode.case
6 unicode.categories ;
7
8 IN: help.search
9
10 <PRIVATE
11
12 : (article-words) ( name -- words )
13     article-content [ string? ] filter
14     [ >lower [ blank? ] split-when ] map concat
15     [ CHAR: - over member? [ "-" split ] when ] map
16     flatten harvest ;
17
18 MEMO: article-words ( name -- words )
19     (article-words) [
20         dup [ letter? not ] any? [
21             [ [ letter? ] [ digit? ] bi or not ] split-when
22         ] when
23     ] map flatten [ [ digit? ] all? not ] filter harvest ;
24
25 PRIVATE>
26
27 : search-docs ( string -- seq' )
28     [ all-articles ] dip >lower [ blank? ] split-when
29     '[ article-words [ _ member? ] any? ] filter
30     [ article-name ] sort-with ;
31
32 : search-docs. ( string -- )
33     search-docs [ ($link) nl ] each ;