--- trunk/lib/WebPAC/Normalize.pm 2005/11/12 21:21:50 38 +++ trunk/lib/WebPAC/Normalize.pm 2005/12/05 17:48:08 219 @@ -11,11 +11,11 @@ =head1 VERSION -Version 0.01 +Version 0.04 =cut -our $VERSION = '0.01'; +our $VERSION = '0.04'; =head1 SYNOPSIS @@ -82,11 +82,15 @@ db => $db_obj, lookup_regex => $lookup->regex, lookup => $lookup_obj, + prefix => 'foobar', ); Parametar C defines user supplied snippets of perl code which can be use with C notation. +C is used to form filename for database record (to support multiple +source files which are joined in one database). + Recommended parametar C is used to enable parsing of lookups in structures. If you pass this parametar, you must also pass C which is C object. @@ -111,6 +115,8 @@ $log->logdie("lookup must be WebPAC::Lookup object") if ($self->{'lookup'} && ! $self->{'lookup'}->isa('WebPAC::Lookup')); + $log->warn("no prefix defined. please check that!") unless ($self->{'prefix'}); + $self ? return $self : return undef; } @@ -122,13 +128,7 @@ This structures are used to produce output. - my @ds = $webpac->data_structure($rec); - -B - -This method will also set C<< $webpac->{'currnet_filename'} >> if there is -C<< >> tag and C<< $webpac->{'headline'} >> if there is -C<< >> tag. + my $ds = $webpac->data_structure($rec); =cut @@ -140,12 +140,18 @@ my $rec = shift; $log->logconfess("need HASH as first argument!") if ($rec !~ /HASH/o); + $log->debug("data_structure rec = ", sub { Dumper($rec) }); + + $log->logdie("need unique ID (mfn) in field 000 of record ", sub { Dumper($rec) } ) unless (defined($rec->{'000'})); + + my $id = $rec->{'000'}->[0] || $log->logdie("field 000 isn't array!"); + my $cache_file; if ($self->{'db'}) { - my @ds = $self->{'db'}->load_ds($rec); - $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper(@ds) }); - return @ds if ($#ds > 0); + my $ds = $self->{'db'}->load_ds( id => $id, prefix => $self->{prefix} ); + $log->debug("load_ds( rec = ", sub { Dumper($rec) }, ") = ", sub { Dumper($ds) }); + return $ds if ($ds); $log->debug("cache miss, creating"); } @@ -160,7 +166,7 @@ $self->{tags_by_order} = \@sorted_tags; } - my @ds; + my $ds; $log->debug("tags: ",sub { join(", ",@sorted_tags) }); @@ -195,22 +201,13 @@ @v = map { $self->apply_format($tag->{'format_name'},$tag->{'format_delimiter'},$_) } @v; } - if ($field eq 'filename') { - $self->{'current_filename'} = join('',@v); - $log->debug("filename: ",$self->{'current_filename'}); - } elsif ($field eq 'headline') { - $self->{'headline'} .= join('',@v); - $log->debug("headline: ",$self->{'headline'}); - next; # don't return headline in data_structure! - } - # delimiter will join repeatable fields if ($tag->{'delimiter'}) { @v = ( join($tag->{'delimiter'}, @v) ); } # default types - my @types = qw(display swish); + my @types = qw(display search); # override by type attribute @types = ( $tag->{'type'} ) if ($tag->{'type'}); @@ -243,14 +240,14 @@ # TODO: name_sigular, name_plural my $name = $self->{'import_xml'}->{'indexer'}->{$field}->{'name'}; - $row->{'name'} = $name ? $self->_x($name) : $field; + my $row_name = $name ? $self->_x($name) : $field; # post-sort all values in field if ($self->{'import_xml'}->{'indexer'}->{$field}->{'sort'}) { $log->warn("sort at field tag not implemented"); } - push @ds, $row; + $ds->{$row_name} = $row; $log->debug("row $field: ",sub { Dumper($row) }); } @@ -258,14 +255,16 @@ } $self->{'db'}->save_ds( - ds => \@ds, - current_filename => $self->{'current_filename'}, - headline => $self->{'headline'}, + id => $id, + ds => $ds, + prefix => $self->{prefix}, ) if ($self->{'db'}); - $log->debug("ds: ", sub { Dumper(@ds) }); + $log->debug("ds: ", sub { Dumper($ds) }); - return @ds; + $log->logconfess("data structure returned is not array any more!") if wantarray; + + return $ds; } @@ -538,7 +537,7 @@ if ($sf && $$rec->{$f}->[$i]->{$sf}) { $$found++ if (defined($$found)); return $$rec->{$f}->[$i]->{$sf}; - } elsif ($$rec->{$f}->[$i]) { + } elsif (! $sf && $$rec->{$f}->[$i]) { $$found++ if (defined($$found)); # it still might have subfield, just # not specified, so we'll dump all @@ -551,6 +550,8 @@ } else { return $$rec->{$f}->[$i]; } + } else { + return ''; } } else { return ''; @@ -674,4 +675,4 @@ =cut -1; # End of WebPAC::DB +1; # End of WebPAC::Normalize