| 1 |
wakaba |
1.1 |
use strict; |
| 2 |
|
|
package SuikaWiki::Plugin::Registry; |
| 3 |
|
|
|
| 4 |
|
|
|
| 5 |
|
|
our %Info; |
| 6 |
|
|
$Info{q#Search#}->{Name} = q#Search#; |
| 7 |
|
|
$Info{q#Search#}->{q#Version#} = q#2004.0831.0328#; |
| 8 |
|
|
$Info{q#Search#}->{q#InterfaceVersion#} = q#2.9.1#; |
| 9 |
|
|
$Info{q#Search#}->{q#mkpluginVersion#} = q#2.1.19#; |
| 10 |
|
|
$Info{q#Search#}->{q#module_name#} = q#SuikaWiki::Plugin::plugin::Search1040731032809Rm7Z#; |
| 11 |
|
|
$Info{q#Search#}->{q#Date.RCS#} = q#$Date: 2004/04/01 04:39:58 $#; |
| 12 |
|
|
$Info{q#Search#}->{RequiredPlugin} = [q#WikiLinking#]; |
| 13 |
|
|
$Info{q#Search#}->{Description} = [[q#Wiki internal full-text search#, q#en#, q##]]; |
| 14 |
|
|
$Info{q#Search#}->{License} = [[q#%%Perl%%#, q##, q##]]; |
| 15 |
|
|
$Info{q#Search#}->{Author} = [[[[q#Wakaba#, q#ja#, q#Latn#]], [[q#[email protected]#]], [q##]]]; |
| 16 |
|
|
package SuikaWiki::Plugin::plugin::Search1040731032809Rm7Z; |
| 17 |
|
|
|
| 18 |
|
|
|
| 19 |
|
|
#line 1 "(WikiPlugin module source search.wp2, block Plugin/Use)" |
| 20 |
|
|
use Message::Util::Error; |
| 21 |
|
|
my $WIKILINKING; |
| 22 |
|
|
my $WIKIRESOURCE; |
| 23 |
|
|
#line 1 "(WikiPlugin module Search, chunk 1)" |
| 24 |
|
|
|
| 25 |
|
|
{my $def = {q#Parameter#, {q#number#, {q#Type#, q#<<1*DIGIT>>#, q#Default#, q#(auto)#, q#Description#, [[q#(Reserved)#, q#en#, q##]]}, q#query#, {q#Type#, q#string#, q#Default#, q#""#, q#Description#, [[q#Query.#, q#en#, q##]]}, q#case_sensitive#, {q#Type#, q#boolean#, q#Default#, q#"0"#, q#Description#, [[q#Case sensitivility of search.#, q#en#, q##]]}, q#start#, {q#Type#, q#<<1*DIGIT>>#, q#Default#, q#"0"#, q#Description#, []}}, q#Description#, [[q#Full-text search in wiki with given query string. |
| 26 |
|
|
|
| 27 |
|
|
This rule seek all (*1) wiki page contents whenever cache is not |
| 28 |
|
|
available. This rule should not be used within wiki that has |
| 29 |
|
|
lots of wiki pages. (*1 Number of wiki pages that is to be target |
| 30 |
|
|
of search is limited to C<$max_target> defined in this rule for |
| 31 |
|
|
safety.) |
| 32 |
|
|
|
| 33 |
|
|
This rule does not support multiple wiki page content formats. |
| 34 |
|
|
It handles contents as a plain text whatever its actual media type is. |
| 35 |
|
|
|
| 36 |
|
|
This rule requires C<m__search_result> WikiDB property to be enabled |
| 37 |
|
|
for caching. (See C<suikawiki-config.ph>.) |
| 38 |
|
|
|
| 39 |
|
|
Namazu WikiPlugin module provides more clever search engine.#, q#en#, q##]], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
| 40 |
|
|
|
| 41 |
|
|
#line 1 "(WikiPlugin module source search.wp2, block FormattingRule[name()='[q#form-input#, q#view#, q#view-resource#]/search_result']/Formatting)" |
| 42 |
|
|
$p->{q#query#} = do { my $r = $f->parse_attr ($p=>q#query#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r}; |
| 43 |
|
|
$p->{query} ||= ($o->{wiki}->{input} ? |
| 44 |
|
|
$o->{wiki}->{input}->parameter ('search__query') : undef) |
| 45 |
|
|
|| $o->{wiki}->{var}->{page}->stringify (wiki => $o->{wiki}); |
| 46 |
|
|
$p->{q#case_sensitive#} = do { my $r = $f->parse_attr ($p=>q#case_sensitive#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r}; |
| 47 |
|
|
my $word = $p->{case_sensitive} ? $p->{query} : lc $p->{query}; |
| 48 |
|
|
my $max_target = 1023; |
| 49 |
|
|
my @r; |
| 50 |
|
|
my $sr = $o->{wiki}->{db}->get (m__search_result => [$word]); |
| 51 |
|
|
unless ($sr) { |
| 52 |
|
|
my $n = 0; |
| 53 |
|
|
for my $page ($o->{wiki}->{db}->keys ('content')) { |
| 54 |
|
|
last if $n++ == $max_target; |
| 55 |
|
|
my $content; |
| 56 |
|
|
try { |
| 57 |
|
|
$content = $o->{wiki}->{db}->get (content => $page); |
| 58 |
|
|
} catch SuikaWiki::DB::Util::Error with { |
| 59 |
|
|
my $err = shift; |
| 60 |
|
|
$err->throw if $err->{-type} eq 'ERROR_REPORTED'; |
| 61 |
|
|
$content = undef; |
| 62 |
|
|
}; |
| 63 |
|
|
$content = $p->{case_sensitive} ? $content : lc $content; |
| 64 |
|
|
$content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s; |
| 65 |
|
|
$page = $o->{wiki}->name ($page); |
| 66 |
|
|
my $n_page = $page->stringify (wiki => $o->{wiki}); |
| 67 |
|
|
$n_page = lc $n_page unless $p->{case_sensible}; |
| 68 |
|
|
if (index ($n_page, $word) > -1) { |
| 69 |
|
|
my $c = $content =~ s/\Q$word\E//g; |
| 70 |
|
|
push @r, [$page, $c+20]; |
| 71 |
|
|
} elsif (index ($word, $n_page) > -1) { |
| 72 |
|
|
my $c = $content =~ s/\Q$word\E//g; |
| 73 |
|
|
push @r, [$page, $c+10]; |
| 74 |
|
|
} elsif (my $c = $content =~ s/\Q$word\E//g) { |
| 75 |
|
|
push @r, [$page, $c]; |
| 76 |
|
|
} |
| 77 |
|
|
} |
| 78 |
|
|
@r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; |
| 79 |
|
|
$sr = join "\x1E", |
| 80 |
|
|
map {$_->[0]->stringify (wiki => $o->{wiki}, delimiter => "\x1D") |
| 81 |
|
|
."\x1F".$_->[1]} @r; |
| 82 |
|
|
$o->{wiki}->{db}->set (m__search_result => [$word] => $sr); |
| 83 |
|
|
} else { |
| 84 |
|
|
@r = map {[$o->{wiki}->name ($_->[0], delimiter_reg => qr/\x1D/), $_->[1]]} |
| 85 |
|
|
map {[split /\x1F/, $_, 2]} split /\x1E/, $sr; |
| 86 |
|
|
} |
| 87 |
|
|
return unless @r; |
| 88 |
|
|
my $list = $p->{-parent}->append_new_node |
| 89 |
|
|
(type => '#element', |
| 90 |
|
|
namespace_uri => q#http://www.w3.org/1999/xhtml#, |
| 91 |
|
|
local_name => 'ol'); |
| 92 |
|
|
$p->{q#template#} = do { my $r = $f->parse_attr ($p=>q#template#, $o, -non_parsed_to_node => 1, %opt); ref $r?$r->inner_text:$r}; |
| 93 |
|
|
$p->{template} ||= ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get |
| 94 |
|
|
(name => 'Link:toWikiPage:SourceLabelLong:SearchResult', |
| 95 |
|
|
wiki => $o->{wiki}, o => $o); |
| 96 |
|
|
for (@r) { |
| 97 |
|
|
($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))->to_wikipage_in_html ({ |
| 98 |
|
|
label => $p->{template}, |
| 99 |
|
|
} => { |
| 100 |
|
|
base => $o->{wiki}->{var}->{page}, |
| 101 |
|
|
page_name_relative => $_->[0], |
| 102 |
|
|
wiki_mode => $p->{mode}, |
| 103 |
|
|
}, { |
| 104 |
|
|
o => $o, |
| 105 |
|
|
parent => $list->append_new_node |
| 106 |
|
|
(type => '#element', |
| 107 |
|
|
namespace_uri => q#http://www.w3.org/1999/xhtml#, |
| 108 |
|
|
local_name => 'li'), |
| 109 |
|
|
-m__weight => $_->[1], |
| 110 |
|
|
}); |
| 111 |
|
|
}}} |
| 112 |
|
|
#line 1 "(WikiPlugin module Search, chunk 2)" |
| 113 |
|
|
; |
| 114 |
|
|
$SuikaWiki::Plugin::Rule{form_input}->{search_result} = $def; |
| 115 |
|
|
$SuikaWiki::Plugin::Rule{view}->{search_result} = $def; |
| 116 |
|
|
$SuikaWiki::Plugin::Rule{view_resource}->{search_result} = $def; |
| 117 |
|
|
}; |
| 118 |
|
|
|
| 119 |
|
|
{my $def = {q#Parameter#, {q#fragment#, {q#Type#, q#URI:fragment#, q#Default#, q#(none)#, q#Description#, [[q#Fragment identifier of destination resource#, q#en#, q##]]}}, q#Description#, [], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
| 120 |
|
|
|
| 121 |
|
|
#line 1 "(WikiPlugin module source search.wp2, block FormattingRule[name()='[q#view#, q#view-resource#, q#form-input#]/search__result_navigation']/Formatting)" |
| 122 |
|
|
my $result = $o->{var}->{search__result}; |
| 123 |
|
|
return if $result->{min} == $result->{start} and |
| 124 |
|
|
$result->{max} == $result->{end}; |
| 125 |
|
|
my $number = $result->{number}; # $result->{end} - $result->{start} + 1; |
| 126 |
|
|
my @range; |
| 127 |
|
|
my $first = ($result->{start} - $result->{min}) % $number; |
| 128 |
|
|
if ($first) { |
| 129 |
|
|
push @range, {start => $result->{min}, end => $first - 1, |
| 130 |
|
|
number => $first, |
| 131 |
|
|
dir => 'prev', seq => 0}; |
| 132 |
|
|
} |
| 133 |
|
|
my $dir; |
| 134 |
|
|
use integer; |
| 135 |
|
|
for my $i (0..(($result->{max} - $result->{min} + 1 - $first) / $number - 1)) { |
| 136 |
|
|
my $start = $result->{min} + $first + $number * $i; |
| 137 |
|
|
push @range, {start => $start, |
| 138 |
|
|
end => $start + $number - 1, |
| 139 |
|
|
number => $number, |
| 140 |
|
|
dir => $dir || (($result->{start} == $start) ? |
| 141 |
|
|
($dir = 'next' and 'current') : 'prev'), |
| 142 |
|
|
seq => scalar @range}; |
| 143 |
|
|
} |
| 144 |
|
|
if ($range[-1]->{end} < $result->{max}) { |
| 145 |
|
|
push @range, {start => $range[-1]->{end} + 1, |
| 146 |
|
|
end => $result->{max}, |
| 147 |
|
|
dir => $dir || 'current', |
| 148 |
|
|
number => $number, |
| 149 |
|
|
seq => scalar @range}; |
| 150 |
|
|
} |
| 151 |
|
|
my %template; |
| 152 |
|
|
for (@range) { |
| 153 |
|
|
$template{$_->{dir}} ||= ($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))->get_text |
| 154 |
|
|
(name => 'Search:Navigation:'.$_->{dir}, |
| 155 |
|
|
o => $o, wiki => $o->{wiki}); |
| 156 |
|
|
($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))->to_wikipage_in_html ({ |
| 157 |
|
|
label => $template{$_->{dir}}, |
| 158 |
|
|
} => { |
| 159 |
|
|
base => $o->{wiki}->{var}->{page}, |
| 160 |
|
|
page_name_relative => $o->{wiki}->{var}->{page}, |
| 161 |
|
|
param => { |
| 162 |
|
|
$result->{param_prefix}.'__query' => $result->{query}, |
| 163 |
|
|
$result->{param_prefix}.'__range_start' => $_->{start}, |
| 164 |
|
|
$result->{param_prefix}.'__range_number' => $_->{number}, |
| 165 |
|
|
}, |
| 166 |
|
|
search__range => $_, |
| 167 |
|
|
page_anchor_name => $p->{fragment}, |
| 168 |
|
|
wiki_mode => $o->{wiki}->{var}->{mode}, |
| 169 |
|
|
}, { |
| 170 |
|
|
o => $o, |
| 171 |
|
|
parent => $p->{-parent}, |
| 172 |
|
|
}); |
| 173 |
|
|
}}} |
| 174 |
|
|
#line 1 "(WikiPlugin module Search, chunk 4)" |
| 175 |
|
|
; |
| 176 |
|
|
$SuikaWiki::Plugin::Rule{view}->{search__result_navigation} = $def; |
| 177 |
|
|
$SuikaWiki::Plugin::Rule{view_resource}->{search__result_navigation} = $def; |
| 178 |
|
|
$SuikaWiki::Plugin::Rule{form_input}->{search__result_navigation} = $def; |
| 179 |
|
|
}; |
| 180 |
|
|
|
| 181 |
|
|
$SuikaWiki::Plugin::Rule{page_link}->{search__result_navigation_seq} = {q#Parameter#, {}, q#Description#, [], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
| 182 |
|
|
|
| 183 |
|
|
#line 1 "(WikiPlugin module source search.wp2, block FormattingRule[name()='[q#page-link#]/search__result_navigation_seq']/Formatting)" |
| 184 |
|
|
$p->{-parent}->append_text ($o->{link}->{dest}->{search__range}->{seq} + 1);}} |
| 185 |
|
|
#line 1 "(WikiPlugin module Search, chunk 6)" |
| 186 |
|
|
; |
| 187 |
|
|
|
| 188 |
|
|
$SuikaWiki::Plugin::Rule{page_link}->{search__result_query} = {q#Parameter#, {}, q#Description#, [], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
| 189 |
|
|
|
| 190 |
|
|
#line 1 "(WikiPlugin module source search.wp2, block FormattingRule[name()='[q#page-link#]/search__result_query']/Formatting)" |
| 191 |
|
|
$p->{-parent}->append_text ($o->{link}->{dest}->{param}->{search__query});}} |
| 192 |
|
|
#line 1 "(WikiPlugin module Search, chunk 8)" |
| 193 |
|
|
; |
| 194 |
|
|
|
| 195 |
|
|
$SuikaWiki::Plugin::Rule{page_link}->{search__result_start} = {q#Parameter#, {}, q#Description#, [], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
| 196 |
|
|
|
| 197 |
|
|
#line 1 "(WikiPlugin module source search.wp2, block FormattingRule[name()='[q#page-link#]/search__result_start']/Formatting)" |
| 198 |
|
|
$p->{-parent}->append_text ($o->{link}->{dest}->{search__range}->{start} + 1);}} |
| 199 |
|
|
#line 1 "(WikiPlugin module Search, chunk 10)" |
| 200 |
|
|
; |
| 201 |
|
|
|
| 202 |
|
|
$SuikaWiki::Plugin::Rule{page_link}->{search__result_end} = {q#Parameter#, {}, q#Description#, [], q#main#, sub {my ($f, $rule_name, $p, $o, %opt) = @_; |
| 203 |
|
|
|
| 204 |
|
|
#line 1 "(WikiPlugin module source search.wp2, block FormattingRule[name()='[q#page-link#]/search__result_end']/Formatting)" |
| 205 |
|
|
$p->{-parent}->append_text ($o->{link}->{dest}->{search__range}->{end} + 1);}} |
| 206 |
|
|
#line 1 "(WikiPlugin module Search, chunk 12)" |
| 207 |
|
|
; |
| 208 |
|
|
|
| 209 |
|
|
push @{$SuikaWiki::View::Implementation::TemplateFragment{q#ws__post_content#}}, { |
| 210 |
|
|
Main => q#%section ( |
| 211 |
|
|
id => see-also, |
| 212 |
|
|
title => {%res(name=>SeeAlso);}p, heading, |
| 213 |
|
|
content => {%search-result ( |
| 214 |
|
|
post-list => { |
| 215 |
|
|
%search--result-navigation ( |
| 216 |
|
|
fragment => see-also, |
| 217 |
|
|
); |
| 218 |
|
|
}p, |
| 219 |
|
|
);}p, |
| 220 |
|
|
);#, |
| 221 |
|
|
Order => 101, |
| 222 |
|
|
Description => [[q#After content body -- Backward links#, q#en#, q##]], |
| 223 |
|
|
}; |
| 224 |
|
|
|
| 225 |
|
|
package SuikaWiki::Plugin::Resource; |
| 226 |
|
|
|
| 227 |
|
|
our $BaseResource; |
| 228 |
|
|
$BaseResource->{q#und#}->{q##}->{q#Link:toWikiPage:SourceLabelLong:SearchResult#} = q#{%m--link-weight;} %link-to-it( label=>{%page-title(relative);}p, description=>{%page-name(absolute);}p, ); %span(class=>headline,content=>{%page-headline;}p);#; |
| 229 |
|
|
$BaseResource->{q#und#}->{q##}->{q#Search:Navigation:prev#} = q#[%link-to-it ( label => {%search--result-navigation-seq;}p, description => {%search--result-query; [%search--result-start;-%search--result-end;]}p, );] #; |
| 230 |
|
|
$BaseResource->{q#und#}->{q##}->{q#Search:Navigation:current#} = q#[%search--result-navigation-seq;] #; |
| 231 |
|
|
$BaseResource->{q#und#}->{q##}->{q#Search:Navigation:next#} = q#[%link-to-it ( label => {%search--result-navigation-seq;}p, description => {%search--result-query; [%search--result-start;-%search--result-end;]}p, );] #; |
| 232 |
|
|
package SuikaWiki::Plugin::Registry; |
| 233 |
|
|
|
| 234 |
|
|
$Info{q#Search#}->{provide} = {q#rule#, {q#form_input#, [q#search_result#, q#search__result_navigation#], q#view#, [q#search_result#, q#search__result_navigation#], q#view_resource#, [q#search_result#, q#search__result_navigation#], q#page_link#, [q#search__result_navigation_seq#, q#search__result_query#, q#search__result_start#, q#search__result_end#]}, q#viewfragment#, [{q#Name#, q#ws__post_content#}]}; |
| 235 |
|
|
|
| 236 |
|
|
1; |