--- branches/tehnika/all2xml.pl 2004/03/12 15:33:13 264 +++ branches/tehnika/all2xml.pl 2004/03/14 20:34:24 291 @@ -151,6 +151,56 @@ } + # init variables for different types + sub init_visible_type($) { + my $type = shift; + + # swish, swish_exact, display, index, index_lookup + # swish and display defaults + my ($s,$se,$d,$i,$il) = (1,0,1,0,0); + if (lc($type) eq "display") { + $s = 0; + } elsif (lc($type) eq "swish") { + $d = 0; + } elsif (lc($type) eq "index") { + ($s,$se,$d,$i) = (0,1,0,1); + } elsif (lc($type) eq "swish_exact") { + ($s,$se,$d,$i) = (0,1,0,0); + } elsif (lc($type) =~ /^lookup/) { + ($s,$se,$d,$i,$il) = (0,1,0,0,1); + } + return ($s,$se,$d,$i,$il); + } + + + # convert + # + # + # , + # 200a + # + # + # to + # + # 200a + # + # but without loosing spaces in delimiter (becasue + # new XML::Simple strips spaces in attribute values + # as defined in XML specification) + # + sub unroll_x($) { + my $x = shift; + + if (defined $x->{value}) { + my ($v,$d) = ($x->{value}->{content}, $x->{delimiter}->{content}); + delete $x->{value}; + delete $x->{delimiter}; + $x->{content} = $v; + $x->{delimiter} = $d; + } + return $x; + } + # begin real work: go field by field foreach my $field (@sorted_tags) { @@ -184,23 +234,18 @@ foreach my $x (@{$config->{indexer}->{$field}->{$tag}}) { + $x = unroll_x($x); + my $format = x($x->{content}); my $delimiter = x($x->{delimiter}) || ' '; my $repeat_off = 0; # init repeatable offset - # swish, swish_exact, display, index, index_lookup - # swish and display defaults - my ($s,$se,$d,$i,$il) = (1,0,1,0,0); - $s = 0 if (lc($x->{type}) eq "display"); - $d = 0 if (lc($x->{type}) eq "swish"); - ($s,$se,$d,$i) = (0,1,0,1) if (lc($x->{type}) eq "index"); - ($s,$se,$d,$i) = (0,1,0,0) if (lc($x->{type}) eq "swish_exact"); - ($s,$se,$d,$i,$il) = (0,1,0,0,1) if (lc($x->{type}) =~ /^lookup/); + my ($s,$se,$d,$i,$il) = init_visible_type($x->{type}); # what will separate last line from this one? if ($display_data && $x->{append}) { - $line_delimiter = ' '; + $line_delimiter = $delimiter; } elsif ($display_data) { $line_delimiter = '
'; } @@ -417,19 +462,17 @@ # now try to parse variables from configuration file foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) { + $x = unroll_x($x); + my $delimiter = x($x->{delimiter}) || ' '; 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"); - # no support for swish exact in config. - # IMHO, it's useless - ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index"); + # FIXME index_lookup is not supported! + my ($s,$se,$d,$i,$il) = init_visible_type($x->{type}); if ($val) { $display_data .= $delimiter.$val if ($d); - $swish_data .= $val if ($s); + $swish_data .= " ".$val if ($s); $index->insert($field, $val, $path) if ($i); } @@ -605,7 +648,7 @@ my $type_base = $type; $type_base =~ s/_.+$//g; - $config=XMLin("./import_xml/$type.xml", forcearray => [ $type2tag{$type_base}, 'config', 'format' ], forcecontent => 1); + $config=XMLin("./import_xml/$type.xml", ForceArray => [ $type2tag{$type_base}, 'config', 'format' ], ForceContent => 1 ); # output current progress indicator my $last_p = 0;