--- trunk/all2xml.pl 2003/06/25 12:09:27 56 +++ trunk/all2xml.pl 2003/07/04 17:57:11 59 @@ -18,7 +18,8 @@ my $config; -use index_DBI; # there is no other, right now ;-) +#use index_DBI; # default DBI module for index +use index_DBI_cache; # faster DBI module using memory cache my $index; my %opts; @@ -33,7 +34,7 @@ my $path; # this is name of database -Text::Iconv->raise_error(1); # Conversion errors raise exceptions +Text::Iconv->raise_error(0); # Conversion errors don't raise exceptions # this is encoding of all files on disk, including import_xml/*.xml file and # filter/*.pm files! It will be used to store strings in perl internally! @@ -65,6 +66,9 @@ my $type = shift @_; my $row = shift @_; my $add_xml = shift @_; + # needed to read values from configuration file + my $cfg = shift @_; + my $database = shift @_; my $xml; @@ -169,6 +173,24 @@ } } + # now try to parse variables from configuration file + foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) { + + my $val = $cfg->val($database, x($x->{content})); + + my ($s,$d,$i) = (1,1,0); # swish, display default + $s = 0 if (lc($x->{type}) eq "display"); + $d = 0 if (lc($x->{type}) eq "swish"); + ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index"); + + if ($val) { + $display_data .= $val if ($d); + $swish_data .= $val if ($s); + $index->insert($field, $val, $path) if ($i); + } + + } + if ($display_data) { @@ -240,14 +262,18 @@ print STDERR "reading ./import_xml/$type.xml\n"; - $config=XMLin("./import_xml/$type.xml", forcearray => [ $type2tag{$type} ], forcecontent => 1); + # extract just type basic + my $type_base = $type; + $type_base =~ s/_.+$//g; + + $config=XMLin("./import_xml/$type.xml", forcearray => [ $type2tag{$type_base}, 'config' ], forcecontent => 1); # output current progress indicator my $last_p = 0; sub progress { #return if (! $opts{q}); # FIXME my $current = shift; - my $total = shift; + my $total = shift || 1; my $p = int($current * 100 / $total); if ($p != $last_p) { printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$current,$total,"=" x ($p/2).">", $p ); @@ -258,7 +284,8 @@ # now read database print STDERR "using: $type...\n"; - if ($type eq "isis") { + if ($type_base eq "isis") { + my $isis_db = $cfg -> val($database, 'isis_db') || die "$database doesn't have 'isis_db' defined!"; $import2cp = Text::Iconv->new($config->{isis_codepage},$codepage); @@ -278,7 +305,7 @@ my $swishpath = $path."#".int($row->{mfn}); - if (my $xml = data2xml($type,$row,$add_xml)) { + if (my $xml = data2xml($type_base,$row,$add_xml,$cfg,$database)) { $xml = $cp2utf->convert($xml); use bytes; # as opposed to chars print "Path-Name: $swishpath\n"; @@ -289,7 +316,7 @@ } print STDERR "\n"; - } elsif ($type eq "excel") { + } elsif ($type_base eq "excel") { use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::Utility qw(int2col); @@ -335,7 +362,7 @@ next if (! $row); - if (my $xml = data2xml($type,$row,$add_xml)) { + if (my $xml = data2xml($type_base,$row,$add_xml,$cfg,$database)) { $xml = $cp2utf->convert($xml); use bytes; # as opposed to chars print "Path-Name: $swishpath\n";