4 |
use strict; |
use strict; |
5 |
use warnings; |
use warnings; |
6 |
|
|
7 |
our $VERSION = '0.01'; |
our $VERSION = '0.02'; |
8 |
|
|
9 |
=head1 NAME |
=head1 NAME |
10 |
|
|
86 |
|
|
87 |
Search, insert, append or replace data in B-Tree |
Search, insert, append or replace data in B-Tree |
88 |
|
|
89 |
|
$t->B_search( |
90 |
|
Key => 'key value', |
91 |
|
Data => { "path" => { |
92 |
|
"t" => "title of document", |
93 |
|
"f" => 99, |
94 |
|
}, |
95 |
|
}, |
96 |
|
Insert => 1, |
97 |
|
Append => 1, |
98 |
|
); |
99 |
|
|
100 |
Semantics: |
Semantics: |
101 |
|
|
305 |
|
|
306 |
Returns number of nodes in created tree. |
Returns number of nodes in created tree. |
307 |
|
|
308 |
|
There is also longer version if you want to recode your data charset |
309 |
|
into different one (probably UTF-8): |
310 |
|
|
311 |
|
$root->to_jsfind('/full/path/to/index/dir/','ISO-8859-2','UTF-8'); |
312 |
|
|
313 |
=cut |
=cut |
314 |
|
|
315 |
|
my $iconv; |
316 |
|
|
317 |
sub to_jsfind { |
sub to_jsfind { |
318 |
my $self = shift; |
my $self = shift; |
319 |
|
|
320 |
my $path = shift || confess "to_jsfind need path to your index!"; |
my $path = shift || confess "to_jsfind need path to your index!"; |
321 |
|
|
322 |
|
my ($from_cp,$to_cp) = @_; |
323 |
|
if ($from_cp && $to_cp) { |
324 |
|
$iconv = Text::Iconv->new($from_cp,$to_cp); |
325 |
|
} |
326 |
|
|
327 |
$path .= "/" if ($path =~ /\/$/); |
$path .= "/" if ($path =~ /\/$/); |
328 |
carp "can't create index in '$path': $!" if (! -w $path); |
carp "create directory for index '$path': $!" if (! -w $path); |
329 |
|
|
330 |
return $self->root->to_jsfind($path,"0"); |
return $self->root->to_jsfind($path,"0"); |
331 |
} |
} |
336 |
$_[0] cmp $_[1]; |
$_[0] cmp $_[1]; |
337 |
} |
} |
338 |
|
|
339 |
|
=head3 _recode |
340 |
|
|
341 |
|
This is internal function to recode charset. |
342 |
|
|
343 |
|
=cut |
344 |
|
|
345 |
|
sub _recode { |
346 |
|
my $self = shift; |
347 |
|
my $text = shift || return; |
348 |
|
|
349 |
|
if ($iconv) { |
350 |
|
return $iconv->convert($text) || $text; |
351 |
|
} else { |
352 |
|
return $text; |
353 |
|
} |
354 |
|
} |
355 |
|
|
356 |
##################################################################### |
##################################################################### |
357 |
|
|
358 |
=head2 jsFind::Node methods |
=head2 jsFind::Node methods |
377 |
|
|
378 |
use Carp; |
use Carp; |
379 |
use File::Path; |
use File::Path; |
380 |
|
use Text::Iconv; |
381 |
|
|
382 |
|
use base 'jsFind'; |
383 |
|
|
384 |
my $KEYS = 0; |
my $KEYS = 0; |
385 |
my $DATA = 1; |
my $DATA = 1; |
727 |
|
|
728 |
Create jsFind xml files |
Create jsFind xml files |
729 |
|
|
730 |
my $nr=$tree->to_dot('/path/to/index','0'); |
my $nr=$tree->to_jsfind('/path/to/index','0'); |
731 |
|
|
732 |
Returns number of elements created |
Returns number of elements created |
733 |
|
|
739 |
|
|
740 |
return 0 if $self->is_empty; |
return 0 if $self->is_empty; |
741 |
|
|
742 |
|
confess("path is undefined.") unless ($path); |
743 |
|
confess("file is undefined. Did you call \$t->root->to_jsfind(..) instead of \$t->to_jsfind(..) ?") unless (defined($file)); |
744 |
|
|
745 |
my $nr_keys = 0; |
my $nr_keys = 0; |
746 |
|
|
747 |
my ($k, $d, $s) = @$self; |
my ($k, $d, $s) = @$self; |
777 |
open(K, "> ${path}/${file}.xml") || croak "can't open '$path/$file.xml': $!"; |
open(K, "> ${path}/${file}.xml") || croak "can't open '$path/$file.xml': $!"; |
778 |
open(D, "> ${path}/_${file}.xml") || croak "can't open '$path/_$file.xml': $!"; |
open(D, "> ${path}/_${file}.xml") || croak "can't open '$path/_$file.xml': $!"; |
779 |
|
|
780 |
print K $key_xml; |
print K $self->SUPER::_recode($key_xml); |
781 |
print D $data_xml; |
print D $self->SUPER::_recode($data_xml); |
782 |
|
|
783 |
close(K); |
close(K); |
784 |
close(D); |
close(D); |