WebPAC::Output::Webpacus - integrate WebPAC front-end with Jifty back-end
-=head1 VERSION
-
-Version 0.01
-
=cut
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 SYNOPSIS
$log->debug("id: $id ds = ",sub { dump($ds) });
- my $hash = $self->ds_to_hash( $ds, 'sorted' ) || return;
+ my $stat;
+
+ foreach my $type ( $self->consume_outputs ) {
+
+ my $hash = $self->ds_to_hash( $ds, $type ) || next;
+
+ $log->debug("$type has following data: ", sub { dump( $hash ) });
- foreach my $f ( keys %$hash ) {
- $self->{fields}->{$f}++;
+ foreach my $f ( keys %$hash ) {
+ $self->{fields}->{$type}->{$f}++;
+ $stat->{$type}->{$f}++;
+ }
}
+ $log->debug("this record added following fields: ", sub { dump( $stat ) });
+
return 1;
}
Close index
- $index->finish;
+ my $affected = $index->finish;
+
+Returns of records saved in total
=cut
my $log = $self->_get_logger();
my $fields = $self->{fields} || confess "no fields?";
+
+ $log->debug("fields = ", sub { dump $fields });
+
my $path = $self->path || confess "no path?";
+ my $webpac_dir = getcwd();
+ chdir $path || $log->logdie("can't chdir($path) $!");
+
+ my $affected = 0;
- my @field_names = %$fields;
+ foreach my $type ( $self->consume_outputs ) {
+ next unless defined $fields->{$type};
+ $affected += $self->_sync_field( $fields->{$type} );
+ }
+
+ return $affected;
+};
+
+sub _sync_field {
+ my $self = shift;
+
+ my $field_hash = shift || confess "no field?";
+ my $path = $self->path || confess "no path?";
+
+ my $log = $self->_get_logger();
+
+ $log->debug("field_hash = ",sub { dump($field_hash) });
+
+ my @field_names = keys %$field_hash;
if ( ! @field_names ) {
$log->warn("normalization rules don't produce any data for search!");
$log->info("syncing search fields: ", join(", ", @field_names));
- $log->debug("fields = ", sub { dump $fields });
-
- my $webpac_dir = getcwd();
-
- chdir $path || $log->logdie("can't chdir($path) $!");
-
# push @INC, $path;
Jifty->new();
my $system_user = Webpacus::CurrentUser->superuser;
my ( $count, $new, $updated ) = ( 0, 0, 0 );
foreach my $field ( @field_names ) {
- my $items = $fields->{$field} || confess "no field?";
+ my $items = $field_hash->{$field} || confess "no field?";
my ( $id, $msg ) = $o->load_by_cols( name => $field );
}
+=head2 consume_outputs
+
+Returns array with names of supported output types for this module
+
+=cut
+
+sub consume_outputs {
+ return qw/search sorted/;
+}
=head1 AUTHOR
use strict;
use blib;
-use Test::More tests => 10;
+use Test::More tests => 11;
BEGIN {
use_ok( 'WebPAC::Test' );
%LOG
}), "new");
+ok( $out->consume_outputs, 'consume_outputs' );
+
+diag "consume_outputs = ",dump( $out->consume_outputs ) if $debug;
+
ok( $out->init, 'init' );
my $ds = {
diag "path: ",$out->path if $debug;
-ok( $out->finish, 'finish' );
+cmp_ok( $out->finish, '==', 4, 'finish' );