--- trunk/all2xml.pl 2003/01/11 16:44:03 7 +++ trunk/all2xml.pl 2003/01/11 19:55:30 9 @@ -7,8 +7,15 @@ use XML::Simple; use Text::Unaccent 1.02; # 1.01 won't compile on my platform, require Unicode::Map8; +use DBI; my $config=XMLin(undef, forcearray => [ 'isis' ], forcecontent => 1); +my $dbh = DBI->connect("DBI:Pg:dbname=webpac","","") || die $DBI::errstr; # FIX +# FIX; select relname from pg_class where relname like 'index_%' ; +$dbh->begin_work || die $dbh->errstr(); + +$dbh->do("delete from index_author") || die $dbh->errstr(); +$dbh->do("delete from index_title") || die $dbh->errstr(); my %opts; @@ -57,19 +64,23 @@ foreach my $field (keys %{$config->{indexer}}) { my $display_data = ""; + my $swish_data = ""; my $index_data = ""; foreach my $x (@{$config->{indexer}->{$field}->{isis}}) { my $display_tmp = ""; + my $swish_tmp = ""; my $index_tmp = ""; my $format = $x->{content}; - my $i = 1; # index only + my $s = 1; # swish only my $d = 1; # display only - $i = 0 if (lc($x->{type}) eq "display"); - $d = 0 if (lc($x->{type}) eq "index"); -#print "## i: $i d: $d ## $format ##"; + my $i = 0; # index only + $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"); +#print STDERR "## s: $s d: $d i: $i ## $format ##\n"; # parse format my $prefix = ""; if ($format =~ s/^([^\d]+)//) { @@ -81,8 +92,9 @@ if ($isis_tmp) { # $display_tmp .= $prefix . "/$1/$2/".$isis_tmp if ($d); $display_tmp .= $prefix . $isis_tmp if ($d); - $index_tmp .= $isis_tmp." " if ($i); -#print " $isis_tmp <--\n"; + $swish_tmp .= $isis_tmp." " if ($s); + $index_tmp .= $prefix . $isis_tmp if ($i); +#print STDERR " $isis_tmp <--\n"; } $prefix = ""; } elsif ($format =~ s/^([^\d]+)//) { @@ -94,19 +106,35 @@ } # add suffix $display_tmp .= $prefix if ($display_tmp); + $index_tmp .= $prefix if ($index_tmp); # $display_data .= $display_tmp if ($display_tmp ne ""); -# $index_data .= $index_tmp if ($index_tmp ne ""); +# $swish_data .= $swish_tmp if ($swish_tmp ne ""); $display_data .= $display_tmp; + $swish_data .= $swish_tmp; $index_data .= $index_tmp; } -#print "--display:$display_data\n--index:$index_data\n"; +#print "--display:$display_data\n--swish:$swish_data\n"; #$xml->{$field."_display"} = $isis_map->tou($display_data)->utf8 if ($display_data); - #$xml->{$field."_index"} = unac_string($config->{isis_codepage},$index_data) if ($index_data); + #$xml->{$field."_swish"} = unac_string($config->{isis_codepage},$swish_data) if ($swish_data); $xml->{$field."_display" } = [ $isis_map->tou($display_data)->utf8 ] if ($display_data); - $xml->{$field."_index"} = [ unac_string($config->{isis_codepage},$index_data)." jabuka" ] if ($index_data); - + $xml->{$field."_swish"} = [ unac_string($config->{isis_codepage},$swish_data) ] if ($swish_data); + + # index + if ($index_data && $index_data ne "") { + my $sql = "select $field from index_$field where upper($field)=upper(?)"; + my $sth = $dbh->prepare($sql) || die $dbh->errstr(); + $sth->execute($index_data) || die "SQL: $sql; ".$dbh->errstr(); +#print STDERR "--->$index_data<---\n"; + if (! $sth->fetchrow_hashref) { + my $sql = "insert into index_$field values (?)"; + my $sth = $dbh->prepare($sql) || die $dbh->errstr(); +#print STDERR "$sql: $index_data