1 |
wakaba |
1.1 |
#?SuikaWikiConfig/2.0 |
2 |
|
|
|
3 |
|
|
Plugin: |
4 |
|
|
@Name: Search |
5 |
|
|
@Description: |
6 |
|
|
@@@: |
7 |
|
|
Wiki internal full-text search |
8 |
|
|
@@lang:en |
9 |
|
|
@License: %%Perl%% |
10 |
|
|
@Author: |
11 |
|
|
@@Name: |
12 |
|
|
@@@@: Wakaba |
13 |
|
|
@@@lang:ja |
14 |
|
|
@@@script:Latn |
15 |
|
|
@@Mail[list]: w@suika.fam.cx |
16 |
|
|
@Date.RCS: |
17 |
wakaba |
1.3 |
$Date: 2004/03/19 11:24:47 $ |
18 |
wakaba |
1.1 |
@RequiredPlugin[list]: |
19 |
|
|
WikiLinking |
20 |
|
|
@Use: |
21 |
|
|
use Message::Util::Error; |
22 |
|
|
my $WIKILINKING; |
23 |
|
|
my $WIKIRESOURCE; |
24 |
|
|
|
25 |
|
|
PluginConst: |
26 |
|
|
@NS_XHTML1: |
27 |
|
|
http://www.w3.org/1999/xhtml |
28 |
|
|
@WIKILINKING: |
29 |
|
|
{($WIKILINKING ||= SuikaWiki::Plugin->module_package ('WikiLinking'))} |
30 |
|
|
@WIKIRESOURCE: |
31 |
|
|
{($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))} |
32 |
|
|
|
33 |
|
|
FormattingRule: |
34 |
|
|
@Category[list]: |
35 |
|
|
form-input |
36 |
|
|
view |
37 |
|
|
view-resource |
38 |
|
|
@Name: search-result |
39 |
|
|
@Description: |
40 |
|
|
@@@: |
41 |
|
|
Full-text search in wiki with given query string. |
42 |
|
|
\ |
43 |
|
|
This rule seek all (*1) wiki page contents whenever cache is not |
44 |
|
|
available. This rule should not be used within wiki that has |
45 |
|
|
lots of wiki pages. (*1 Number of wiki pages that is to be target |
46 |
|
|
of search is limited to C<$max_target> defined in this rule for |
47 |
|
|
safety.) |
48 |
|
|
\ |
49 |
|
|
This rule does not support multiple wiki page content formats. |
50 |
|
|
It handles contents as a plain text whatever its actual media type is. |
51 |
|
|
\ |
52 |
|
|
This rule requires C<m__search_result> WikiDB property to be enabled |
53 |
|
|
for caching. (See C<suikawiki-config.ph>.) |
54 |
|
|
\ |
55 |
|
|
Namazu WikiPlugin module provides more clever search engine. |
56 |
|
|
@@lang: en |
57 |
|
|
@Parameter: |
58 |
|
|
@@Name: case-sensitive |
59 |
|
|
@@Type: boolean |
60 |
|
|
@@Default: "0" |
61 |
|
|
@@Description: |
62 |
|
|
@@@@: Case sensitivility of search. |
63 |
|
|
@@@lang: en |
64 |
|
|
@Parameter: |
65 |
|
|
@@Name: number |
66 |
|
|
@@Type: <<1*DIGIT>> |
67 |
|
|
@@Default: (auto) |
68 |
|
|
@@Description: |
69 |
|
|
@@@@: (Reserved) |
70 |
|
|
@@@lang: en |
71 |
|
|
@Parameter: |
72 |
|
|
@@Name: query |
73 |
|
|
@@Type: string |
74 |
|
|
@@Default: "" |
75 |
|
|
@@Description: |
76 |
|
|
@@@@: Query. |
77 |
|
|
@@@lang: en |
78 |
|
|
@Parameter: |
79 |
|
|
@@Name: start |
80 |
|
|
@@Type: <<1*DIGIT>> |
81 |
|
|
@@Default: "0" |
82 |
|
|
@@Descuription: |
83 |
|
|
@@@@: (Reserved) |
84 |
|
|
@@@lang: en |
85 |
|
|
@Formatting: |
86 |
|
|
__ATTRTEXT:%query__; |
87 |
|
|
$p->{query} ||= ($o->{wiki}->{input} ? |
88 |
|
|
$o->{wiki}->{input}->parameter ('search__query') : undef) |
89 |
|
|
|| $o->{wiki}->{var}->{page}->stringify (wiki => $o->{wiki}); |
90 |
|
|
__ATTRTEXT:%case_sensitive__; |
91 |
|
|
my $word = $p->{case_sensitive} ? $p->{query} : lc $p->{query}; |
92 |
|
|
my $max_target = 1023; |
93 |
|
|
my @r; |
94 |
|
|
my $sr = $o->{wiki}->{db}->get (m__search_result => [$word]); |
95 |
|
|
unless ($sr) { |
96 |
|
|
my $n = 0; |
97 |
|
|
for my $page ($o->{wiki}->{db}->keys ('content')) { |
98 |
|
|
last if $n++ == $max_target; |
99 |
|
|
my $content; |
100 |
|
|
try { |
101 |
|
|
$content = $o->{wiki}->{db}->get (content => $page); |
102 |
|
|
} catch SuikaWiki::DB::Util::Error with { |
103 |
|
|
my $err = shift; |
104 |
|
|
$err->throw if $err->{-type} eq 'ERROR_REPORTED'; |
105 |
|
|
$content = undef; |
106 |
|
|
}; |
107 |
|
|
$content = $p->{case_sensitive} ? $content : lc $content; |
108 |
|
|
$content =~ s/^[^\x0A\x0D]+[\x0D\x0A]+//s; |
109 |
|
|
$page = $o->{wiki}->name ($page); |
110 |
|
|
my $n_page = $page->stringify (wiki => $o->{wiki}); |
111 |
|
|
$n_page = lc $n_page unless $p->{case_sensible}; |
112 |
|
|
if (index ($n_page, $word) > -1) { |
113 |
|
|
my $c = $content =~ s/\Q$word\E//g; |
114 |
|
|
push @r, [$page, $c+20]; |
115 |
|
|
} elsif (index ($word, $n_page) > -1) { |
116 |
|
|
my $c = $content =~ s/\Q$word\E//g; |
117 |
|
|
push @r, [$page, $c+10]; |
118 |
|
|
} elsif (my $c = $content =~ s/\Q$word\E//g) { |
119 |
|
|
push @r, [$page, $c]; |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
@r = sort {$b->[1] <=> $a->[1] || $a->[0] cmp $b->[0]} @r; |
123 |
|
|
$sr = join "\x1E", |
124 |
|
|
map {$_->[0]->stringify (wiki => $o->{wiki}, delimiter => "\x1D") |
125 |
|
|
."\x1F".$_->[1]} @r; |
126 |
|
|
$o->{wiki}->{db}->set (m__search_result => [$word] => $sr); |
127 |
|
|
## TODO: Cache & case-sensitivility |
128 |
|
|
} else { |
129 |
|
|
@r = map {[$o->{wiki}->name ($_->[0], delimiter_reg => qr/\x1D/), $_->[1]]} |
130 |
|
|
map {[split /\x1F/, $_, 2]} split /\x1E/, $sr; |
131 |
|
|
} |
132 |
|
|
return unless @r; |
133 |
|
|
my $list = $p->{-parent}->append_new_node |
134 |
|
|
(type => '#element', |
135 |
|
|
namespace_uri => $NS_XHTML1, |
136 |
|
|
local_name => 'ol'); |
137 |
|
|
__ATTRTEXT:%template__; |
138 |
|
|
$p->{template} ||= $WIKIRESOURCE->get |
139 |
|
|
(name => 'Link:toWikiPage:SourceLabelLong:SearchResult', |
140 |
|
|
wiki => $o->{wiki}, o => $o); |
141 |
|
|
for (@r) { |
142 |
|
|
$WIKILINKING->to_wikipage_in_html ({ |
143 |
|
|
label => $p->{template}, |
144 |
|
|
} => { |
145 |
|
|
base => $o->{wiki}->{var}->{page}, |
146 |
|
|
page_name_relative => $_->[0], |
147 |
|
|
wiki_mode => $p->{mode}, |
148 |
|
|
}, { |
149 |
|
|
o => $o, |
150 |
|
|
parent => $list->append_new_node |
151 |
|
|
(type => '#element', |
152 |
|
|
namespace_uri => $NS_XHTML1, |
153 |
|
|
local_name => 'li'), |
154 |
|
|
-m__weight => $_->[1], |
155 |
|
|
}); |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
FormattingRule: |
159 |
|
|
@Category[list]: |
160 |
|
|
view |
161 |
|
|
view-resource |
162 |
|
|
form-input |
163 |
|
|
@Name: search--result-navigation |
164 |
wakaba |
1.3 |
@Parameter: |
165 |
|
|
@@Name: fragment |
166 |
|
|
@@Type: |
167 |
|
|
URI:fragment |
168 |
|
|
@@Default: (none) |
169 |
|
|
@@Description: |
170 |
|
|
@@@@: Fragment identifier of destination resource |
171 |
|
|
@@@lang: en |
172 |
wakaba |
1.1 |
@Formatting: |
173 |
|
|
my $result = $o->{var}->{search__result}; |
174 |
|
|
return if $result->{min} == $result->{start} and |
175 |
|
|
$result->{max} == $result->{end}; |
176 |
|
|
my $number = $result->{number}; # $result->{end} - $result->{start} + 1; |
177 |
|
|
my @range; |
178 |
|
|
my $first = ($result->{start} - $result->{min}) % $number; |
179 |
|
|
if ($first) { |
180 |
|
|
push @range, {start => $result->{min}, end => $first - 1, |
181 |
|
|
number => $first, |
182 |
|
|
dir => 'prev', seq => 0}; |
183 |
|
|
} |
184 |
|
|
my $dir; |
185 |
|
|
use integer; |
186 |
|
|
for my $i (0..(($result->{max} - $result->{min} + 1 - $first) / $number - 1)) { |
187 |
|
|
my $start = $result->{min} + $first + $number * $i; |
188 |
|
|
push @range, {start => $start, |
189 |
|
|
end => $start + $number - 1, |
190 |
|
|
number => $number, |
191 |
|
|
dir => $dir || (($result->{start} == $start) ? |
192 |
wakaba |
1.2 |
($dir = 'next' and 'current') : 'prev'), |
193 |
wakaba |
1.1 |
seq => scalar @range}; |
194 |
|
|
} |
195 |
|
|
if ($range[-1]->{end} < $result->{max}) { |
196 |
|
|
push @range, {start => $range[-1]->{end} + 1, |
197 |
|
|
end => $result->{max}, |
198 |
|
|
dir => $dir || 'current', |
199 |
|
|
number => $number, |
200 |
|
|
seq => scalar @range}; |
201 |
|
|
} |
202 |
|
|
my %template; |
203 |
|
|
for (@range) { |
204 |
|
|
$template{$_->{dir}} ||= $WIKIRESOURCE->get_text |
205 |
|
|
(name => 'Search:Navigation:'.$_->{dir}, |
206 |
|
|
o => $o, wiki => $o->{wiki}); |
207 |
|
|
$WIKILINKING->to_wikipage_in_html ({ |
208 |
|
|
label => $template{$_->{dir}}, |
209 |
|
|
} => { |
210 |
|
|
base => $o->{wiki}->{var}->{page}, |
211 |
|
|
page_name_relative => $o->{wiki}->{var}->{page}, |
212 |
|
|
param => { |
213 |
wakaba |
1.3 |
$result->{param_prefix}.'__query' => $result->{query}, |
214 |
|
|
$result->{param_prefix}.'__range_start' => $_->{start}, |
215 |
|
|
$result->{param_prefix}.'__range_number' => $_->{number}, |
216 |
wakaba |
1.1 |
}, |
217 |
|
|
search__range => $_, |
218 |
wakaba |
1.3 |
page_anchor_name => $p->{fragment}, |
219 |
wakaba |
1.1 |
}, { |
220 |
|
|
o => $o, |
221 |
|
|
parent => $p->{-parent}, |
222 |
|
|
}); |
223 |
|
|
} |
224 |
|
|
|
225 |
|
|
FormattingRule: |
226 |
|
|
@Category[list]: |
227 |
|
|
page-link |
228 |
|
|
@Name: search--result-navigation-seq |
229 |
|
|
@Formatting: |
230 |
|
|
$p->{-parent}->append_text ($o->{link}->{dest}->{search__range}->{seq} + 1); |
231 |
|
|
|
232 |
|
|
FormattingRule: |
233 |
|
|
@Category[list]: |
234 |
|
|
page-link |
235 |
|
|
@Name: search--result-query |
236 |
|
|
@Formatting: |
237 |
|
|
$p->{-parent}->append_text ($o->{link}->{dest}->{param}->{search__query}); |
238 |
|
|
|
239 |
|
|
FormattingRule: |
240 |
|
|
@Category[list]: |
241 |
|
|
page-link |
242 |
|
|
@Name: search--result-start |
243 |
|
|
@Formatting: |
244 |
|
|
$p->{-parent}->append_text ($o->{link}->{dest}->{search__range}->{start} + 1); |
245 |
|
|
|
246 |
|
|
FormattingRule: |
247 |
|
|
@Category[list]: |
248 |
|
|
page-link |
249 |
|
|
@Name: search--result-end |
250 |
|
|
@Formatting: |
251 |
|
|
$p->{-parent}->append_text ($o->{link}->{dest}->{search__range}->{end} + 1); |
252 |
|
|
|
253 |
|
|
ViewFragment: |
254 |
|
|
@Name: ws--post-content |
255 |
|
|
@Description: |
256 |
|
|
@@@: After content body -- Backward links |
257 |
|
|
@@lang:en |
258 |
|
|
@Order: 101 |
259 |
|
|
@Formatting: |
260 |
|
|
%section ( |
261 |
|
|
id => see-also, |
262 |
|
|
title => {%res(name=>SeeAlso);}p, heading, |
263 |
|
|
content => {%search-result ( |
264 |
|
|
post-list => { |
265 |
wakaba |
1.3 |
%search--result-navigation ( |
266 |
|
|
fragment => see-also, |
267 |
|
|
); |
268 |
wakaba |
1.1 |
}p, |
269 |
|
|
);}p, |
270 |
|
|
); |
271 |
|
|
|
272 |
|
|
Resource: |
273 |
|
|
@Link:toWikiPage:SourceLabelLong:SearchResult: |
274 |
|
|
{%m--link-weight;} |
275 |
|
|
%link-to-it( |
276 |
|
|
label=>{%page-title(relative);}p, |
277 |
|
|
description=>{%page-name(absolute);}p, |
278 |
|
|
); |
279 |
|
|
%span(class=>headline,content=>{%page-headline;}p); |
280 |
|
|
@Search:Navigation:prev: |
281 |
|
|
[%link-to-it ( |
282 |
|
|
label => {%search--result-navigation-seq;}p, |
283 |
|
|
description => {%search--result-query; [%search--result-start;-%search--result-end;]}p, |
284 |
|
|
);] |
285 |
|
|
@Search:Navigation:current: |
286 |
|
|
[%search--result-navigation-seq;] |
287 |
|
|
@Search:Navigation:next: |
288 |
|
|
[%link-to-it ( |
289 |
|
|
label => {%search--result-navigation-seq;}p, |
290 |
|
|
description => {%search--result-query; [%search--result-start;-%search--result-end;]}p, |
291 |
|
|
);] |
292 |
|
|
|