/[webpac]/trunk2/lib/WebPAC/jsFind.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk2/lib/WebPAC/jsFind.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 395 by dpavlin, Wed Jul 21 23:39:10 2004 UTC revision 540 by dpavlin, Sun Oct 24 14:51:53 2004 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use strict;  use strict;
5    
6  use Carp;  use Carp;
7  use jsFind 0.02;  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
# Line 26  Create new index object Line 26  Create new index object
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.
# Line 33  C<index> is path to location where jsFin Line 34  C<index> is path to location where jsFin
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 {
# Line 100  sub insert { Line 104  sub insert {
104          }          }
105          return unless (defined($args->{'words'}));          return unless (defined($args->{'words'}));
106    
107          my $words = $args->{'words'};          my $words = lc($args->{'words'});
108    
109          # chop leading and trailing spaces          # chop leading and trailing spaces
110          $words =~ s/^\s+//;          $words =~ s/^\s+//;
111          $words =~ s/\s+$//;          $words =~ s/\s+$//;
112    
113            my @words = split(/\s+/,$words);
114    
115          my %usage;          my %usage;
116          foreach (split(/\s+/,$words)) {          foreach (@words) {
117                  $usage{$_}++;                  $usage{$_}++;
118          }          }
119    
# Line 117  sub insert { Line 123  sub insert {
123                  " path: ",$args->{'path'}                  " path: ",$args->{'path'}
124          );          );
125    
126          foreach my $word (keys %usage) {          foreach my $word (@words) {
127    
128                  $self->tree($args->{'index_name'})->B_search(                  $self->tree($args->{'index_name'})->B_search(
129                          Key => $word,                          Key => $word,
# Line 141  This method will dump indexes to disk. Line 147  This method will dump indexes to disk.
147  This method will create directories if needed and store tree xml files  This method will create directories if needed and store tree xml files
148  for all indexes.  for all indexes.
149    
150    Turning debugging for this function by inserting
151    
152      log4perl.logger.WebPAC.jsFind.close=DEBUG
153    
154    into C<log.conf> will also result in creation of GraphViz C<.dot> files
155    for each index in current directory.
156    
157  =cut  =cut
158    
# Line 154  sub close { Line 166  sub close {
166                    
167                  $log->debug("saving index '$index_name' xml files to '$path'");                  $log->debug("saving index '$index_name' xml files to '$path'");
168    
169                  $self->tree($index_name)->to_jsfind($path,'ISO-8859-2','UTF-8');                  $self->tree($index_name)->to_jsfind(
170                            dir => $path,
171                            data_codepage => 'ISO-8859-2',
172                            index_codepage => 'UTF-8'
173                    );
174    
175                    if ($log->is_debug()) {
176                            my $dot_file = $index_name.".dot";
177                    
178                            $log->debug("saving graphviz file for '$index_name' to '$dot_file'");
179    
180                            open(DOT, ">", $dot_file) || $log->logdie("can't open '$dot_file': $!");
181                            print DOT $self->tree($index_name)->to_dot;
182                            close(DOT);
183                    }
184          }          }
185    
186  }  }

Legend:
Removed from v.395  
changed lines
  Added in v.540

  ViewVC Help
Powered by ViewVC 1.1.26