4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Carp; |
use Carp; |
7 |
use jsFind 0.04; |
use jsFind 0.06; |
8 |
use Log::Log4perl qw(get_logger :levels); |
use Log::Log4perl qw(get_logger :levels); |
9 |
|
|
10 |
=head1 NAME |
=head1 NAME |
26 |
my $index = new WebPAC::jsFind( |
my $index = new WebPAC::jsFind( |
27 |
index_path => '/path/to/jsFind/index', |
index_path => '/path/to/jsFind/index', |
28 |
keys => 10, |
keys => 10, |
29 |
|
log => 'log4perl.conf', |
30 |
); |
); |
31 |
|
|
32 |
C<index> is path to location where jsFind index should be created. |
C<index> is path to location where jsFind index should be created. |
34 |
C<keys> is optional parametar which specify number of keys in each node |
C<keys> is optional parametar which specify number of keys in each node |
35 |
(which has to be even number). Default is 10. |
(which has to be even number). Default is 10. |
36 |
|
|
37 |
|
C<log> is optional parametar which specify filename of L<Log::Log4Perl> |
38 |
|
config file. Default is C<log.conf>. |
39 |
|
|
40 |
=cut |
=cut |
41 |
|
|
42 |
sub new { |
sub new { |
102 |
carp "no headline for ",$args->{'path'}," ?"; |
carp "no headline for ",$args->{'path'}," ?"; |
103 |
$args->{'headline'} = "no headline: ".$args->{'path'}; |
$args->{'headline'} = "no headline: ".$args->{'path'}; |
104 |
} |
} |
105 |
return unless (defined($args->{'words'})); |
if (! defined($args->{'words'})) { |
106 |
|
$log->warn("no words to insert for headline ",$args->{'headline'}); |
107 |
|
return; |
108 |
|
} |
109 |
|
|
110 |
my $words = $args->{'words'}; |
my $words = lc($args->{'words'}); |
111 |
|
|
112 |
# chop leading and trailing spaces |
# chop leading and trailing spaces |
113 |
$words =~ s/^\s+//; |
$words =~ s/^\s+//; |
114 |
$words =~ s/\s+$//; |
$words =~ s/\s+$//; |
115 |
|
|
116 |
|
my @words = split(/\s+/,$words); |
117 |
|
|
118 |
my %usage; |
my %usage; |
119 |
foreach (split(/\s+/,$words)) { |
foreach (@words) { |
120 |
$usage{$_}++; |
$usage{$_}++; |
121 |
} |
} |
122 |
|
|
126 |
" path: ",$args->{'path'} |
" path: ",$args->{'path'} |
127 |
); |
); |
128 |
|
|
129 |
foreach my $word (keys %usage) { |
foreach my $word (@words) { |
130 |
|
|
131 |
$self->tree($args->{'index_name'})->B_search( |
$self->tree($args->{'index_name'})->B_search( |
132 |
Key => $word, |
Key => $word, |
150 |
This method will create directories if needed and store tree xml files |
This method will create directories if needed and store tree xml files |
151 |
for all indexes. |
for all indexes. |
152 |
|
|
153 |
|
Turning debugging for this function by inserting |
154 |
|
|
155 |
|
log4perl.logger.WebPAC.jsFind.close=DEBUG |
156 |
|
|
157 |
|
into C<log.conf> will also result in creation of GraphViz C<.dot> files |
158 |
|
for each index in current directory. |
159 |
|
|
160 |
=cut |
=cut |
161 |
|
|
169 |
|
|
170 |
$log->debug("saving index '$index_name' xml files to '$path'"); |
$log->debug("saving index '$index_name' xml files to '$path'"); |
171 |
|
|
172 |
$self->tree($index_name)->to_jsfind($path,'ISO-8859-2','UTF-8'); |
$self->tree($index_name)->to_jsfind( |
173 |
|
dir => $path, |
174 |
|
data_codepage => 'ISO-8859-2', |
175 |
|
index_codepage => 'UTF-8' |
176 |
|
); |
177 |
|
|
178 |
|
if ($log->is_debug()) { |
179 |
|
my $dot_file = $index_name.".dot"; |
180 |
|
|
181 |
|
$log->debug("saving graphviz file for '$index_name' to '$dot_file'"); |
182 |
|
|
183 |
|
open(DOT, ">", $dot_file) || $log->logdie("can't open '$dot_file': $!"); |
184 |
|
print DOT $self->tree($index_name)->to_dot; |
185 |
|
close(DOT); |
186 |
|
} |
187 |
} |
} |
188 |
|
|
189 |
} |
} |