56 |
# format in XML file |
# format in XML file |
57 |
my %type2tag = ( |
my %type2tag = ( |
58 |
'isis' => 'isis', |
'isis' => 'isis', |
59 |
'excel' => 'column' |
'excel' => 'column', |
60 |
|
'marc' => 'marc', |
61 |
); |
); |
62 |
|
|
63 |
sub data2xml { |
sub data2xml { |
177 |
# now try to parse variables from configuration file |
# now try to parse variables from configuration file |
178 |
foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) { |
foreach my $x (@{$config->{indexer}->{$field}->{'config'}}) { |
179 |
|
|
180 |
|
my $delimiter = x($x->{delimiter}) || ' '; |
181 |
my $val = $cfg->val($database, x($x->{content})); |
my $val = $cfg->val($database, x($x->{content})); |
182 |
|
|
183 |
my ($s,$d,$i) = (1,1,0); # swish, display default |
my ($s,$d,$i) = (1,1,0); # swish, display default |
186 |
($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index"); |
($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index"); |
187 |
|
|
188 |
if ($val) { |
if ($val) { |
189 |
$display_data .= $val if ($d); |
$display_data .= $delimiter.$val if ($d); |
190 |
$swish_data .= $val if ($s); |
$swish_data .= $val if ($s); |
191 |
$index->insert($field, $val, $path) if ($i); |
$index->insert($field, $val, $path) if ($i); |
192 |
} |
} |
368 |
$xml = $cp2utf->convert($xml); |
$xml = $cp2utf->convert($xml); |
369 |
use bytes; # as opposed to chars |
use bytes; # as opposed to chars |
370 |
print "Path-Name: $swishpath\n"; |
print "Path-Name: $swishpath\n"; |
371 |
|
print "Content-Length: ".(length($xml)+1)."\n"; |
372 |
|
print "Document-Type: XML\n\n$xml\n"; |
373 |
|
} |
374 |
|
} |
375 |
|
} elsif ($type_base eq "marc") { |
376 |
|
## XXX |
377 |
|
use MARC; |
378 |
|
|
379 |
|
$import2cp = Text::Iconv->new($config->{marc_codepage},$codepage); |
380 |
|
my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!"; |
381 |
|
|
382 |
|
# optional argument is format |
383 |
|
my $format = x($config->{format}) || 'usmarc'; |
384 |
|
|
385 |
|
my %id_stored; # to aviod duplicates |
386 |
|
|
387 |
|
print STDERR "Reading MARC file '$marc_file'\n"; |
388 |
|
|
389 |
|
my $marc = new MARC; |
390 |
|
my $nr = $marc->openmarc({ |
391 |
|
file=>$marc_file, format=>$format |
392 |
|
}) || die "Can't open MARC file '$marc_file'"; |
393 |
|
|
394 |
|
my $i=0; # record nr. |
395 |
|
my $inc=1; |
396 |
|
my $max_i=1000; |
397 |
|
|
398 |
|
my $rec; |
399 |
|
|
400 |
|
while ($marc->nextmarc(1)) { |
401 |
|
|
402 |
|
# XXX |
403 |
|
progress($i, $max_i); |
404 |
|
$i += $inc; |
405 |
|
$inc = -$inc if ($i > $max_i || $i < 0); |
406 |
|
|
407 |
|
my $swishpath = $database."#".$i; |
408 |
|
|
409 |
|
if (my $xml = data2xml($type_base,$marc,$add_xml,$cfg,$database)) { |
410 |
|
$xml = $cp2utf->convert($xml); |
411 |
|
use bytes; # as opposed to chars |
412 |
|
print "Path-Name: $swishpath\n"; |
413 |
print "Content-Length: ".(length($xml)+1)."\n"; |
print "Content-Length: ".(length($xml)+1)."\n"; |
414 |
print "Document-Type: XML\n\n$xml\n"; |
print "Document-Type: XML\n\n$xml\n"; |
415 |
} |
} |