--- trunk/all2xml.pl 2003/11/29 19:07:00 188 +++ trunk/all2xml.pl 2003/12/21 03:27:02 197 @@ -72,6 +72,8 @@ # if you are tight on memory, turn this off my $use_lhash_cache = 1; +my $last_field_name; # cache to prevent repeated fields + sub data2xml { use xmlify; @@ -138,7 +140,13 @@ print STDERR "WARNING: field '$field' doesn't have 'name' attribute!"; } if ($field_name) { - return x($field_name); + if (! $last_field_name) { + $last_field_name = x($field_name); + return $last_field_name; + } elsif ($field_name ne $last_field_name) { + $last_field_name = x($field_name); + return $last_field_name; + } } } @@ -167,6 +175,13 @@ my $page_line_delimiter = $config->{indexer}->{$field}->{page_line_delimiter} || '
'; $cache->{index_delimiter}->{$field} = $config->{indexer}->{$field}->{index_delimiter}; + my $format_name = $config->{indexer}->{$field}->{format_name}; + my $format_delimiter = $config->{indexer}->{$field}->{format_delimiter}; + if ($format_name && $format_delimiter) { + $cache->{format}->{$field}->{format_name} = $format_name; + $cache->{format}->{$field}->{format_delimiter} = $format_delimiter; + } + foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) { my $format = x($x->{content}); @@ -195,7 +210,7 @@ # placeholder for all repeatable entries for index - sub mkformat { + sub mkformat($$) { my $x = shift || die "mkformat needs tag reference"; my $data = shift || return; my $format_name = x($x->{format_name}) || return $data; @@ -267,11 +282,11 @@ no strict 'refs'; my $tmp = join(" ",&$filter($swish)) if ($s || $se); $swish_data .= $tmp if ($s); - $swish_exact_data .= $tmp if ($se); + $swish_exact_data .= "xxbxx $tmp xxexx " if ($se && $tmp ne ""); } else { $swish_data .= $swish if ($s); - $swish_exact_data .= $swish if ($se); + $swish_exact_data .= "xxbxx $swish xxexx " if ($se && $swish ne ""); } } @@ -362,7 +377,11 @@ @index_data = @{$cache->{index_data}->{$field}->[$page]}; } if ($x->{append}) { - $index_data[$#index_data] .= $idisplay; + if (@index_data) { + $index_data[$#index_data] .= $idisplay; + } else { + push @index_data, $idisplay; + } } else { push @index_data, $idisplay; } @@ -430,8 +449,12 @@ #print STDERR "field '$field' iterate over ",($nr_pages || 0)," pages...\n"; #print STDERR Dumper($cache->{display_data}); for (my $page=0; $page <= $nr_pages; $page++) { - - my $display_data = $cache->{display_data}->{$field}->[$page]; + my $display_data; + if ($cache->{format}->{$field}) { + $display_data=mkformat($cache->{format}->{$field},$cache->{display_data}->{$field}->[$page]); + } else { + $display_data = $cache->{display_data}->{$field}->[$page]; + } if ($display_data) { # default if ($field eq "headline") { $xml .= xmlify("headline", $display_data); @@ -459,7 +482,7 @@ # add delimiters before and after word. # That is required to produce exact match - $xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx')); + $xml .= xmlify($field."_swish_exact", unac_string($codepage,$swish_exact_data)); } my $idel = $cache->{index_delimiter}->{$field}; @@ -501,7 +524,7 @@ # add delimiters before and after word. # That is required to produce exact match - $xml .= xmlify($field."_swish_exact", unac_string($codepage,'xxbxx '.$swish_exact_data.' xxexx')); + $xml .= xmlify($field."_swish_exact", unac_string($codepage,$swish_exact_data)); } } }