line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::Search; |
2
|
1
|
|
|
1
|
|
33702
|
use Kwiki::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
4
|
|
|
|
|
|
|
use Kwiki ':char_classes'; |
5
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
const class_id => 'search'; |
8
|
|
|
|
|
|
|
const cgi_class => 'Kwiki::Search::CGI'; |
9
|
|
|
|
|
|
|
const css_file => 'search.css'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub register { |
12
|
|
|
|
|
|
|
my $registry = shift; |
13
|
|
|
|
|
|
|
$registry->add(action => 'search'); |
14
|
|
|
|
|
|
|
$registry->add(toolbar => 'search_box', |
15
|
|
|
|
|
|
|
template => 'search_box.html', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub search { |
20
|
|
|
|
|
|
|
my $pages = $self->perform_search; |
21
|
|
|
|
|
|
|
my $term = $self->cgi->search_term; |
22
|
|
|
|
|
|
|
my $num = @$pages; |
23
|
|
|
|
|
|
|
my $screen_title = length($term) |
24
|
|
|
|
|
|
|
? "$num Pages Matching '$term'" |
25
|
|
|
|
|
|
|
: "All $num Pages"; |
26
|
|
|
|
|
|
|
$self->render_screen( |
27
|
|
|
|
|
|
|
screen_title => $screen_title, |
28
|
|
|
|
|
|
|
pages => $pages, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub perform_search { |
33
|
|
|
|
|
|
|
my $search = $self->cgi->search_term; |
34
|
|
|
|
|
|
|
$search =~ s/[^$WORD\ \-\.\^\$\*\|\:]//g; |
35
|
|
|
|
|
|
|
[ |
36
|
|
|
|
|
|
|
grep { |
37
|
|
|
|
|
|
|
($_->id =~ m{$search}i || |
38
|
|
|
|
|
|
|
$_->content =~ m{$search}i |
39
|
|
|
|
|
|
|
) and $_->active |
40
|
|
|
|
|
|
|
} $self->pages->all |
41
|
|
|
|
|
|
|
] |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
package Kwiki::Search::CGI; |
45
|
|
|
|
|
|
|
use Kwiki::CGI -base; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
cgi search_term => -utf8; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
package Kwiki::Search; |
50
|
|
|
|
|
|
|
__DATA__ |