23 |
|
|
24 |
WebPAC::Output::Webpacus - integrate WebPAC front-end with Jifty back-end |
WebPAC::Output::Webpacus - integrate WebPAC front-end with Jifty back-end |
25 |
|
|
|
=head1 VERSION |
|
|
|
|
|
Version 0.01 |
|
|
|
|
26 |
=cut |
=cut |
27 |
|
|
28 |
our $VERSION = '0.01'; |
our $VERSION = '0.02'; |
29 |
|
|
30 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
31 |
|
|
88 |
|
|
89 |
$log->debug("id: $id ds = ",sub { dump($ds) }); |
$log->debug("id: $id ds = ",sub { dump($ds) }); |
90 |
|
|
91 |
my $hash = $self->ds_to_hash( $ds, 'sorted' ) || return; |
my $stat; |
92 |
|
|
93 |
|
foreach my $type ( $self->consume_outputs ) { |
94 |
|
|
95 |
|
my $hash = $self->ds_to_hash( $ds, $type ) || next; |
96 |
|
|
97 |
|
$log->debug("$type has following data: ", sub { dump( $hash ) }); |
98 |
|
|
99 |
foreach my $f ( keys %$hash ) { |
foreach my $f ( keys %$hash ) { |
100 |
$self->{fields}->{$f}++; |
$self->{fields}->{$type}->{$f}++; |
101 |
|
$stat->{$type}->{$f}++; |
102 |
|
} |
103 |
} |
} |
104 |
|
|
105 |
|
$log->debug("this record added following fields: ", sub { dump( $stat ) }); |
106 |
|
|
107 |
return 1; |
return 1; |
108 |
} |
} |
109 |
|
|
111 |
|
|
112 |
Close index |
Close index |
113 |
|
|
114 |
$index->finish; |
my $affected = $index->finish; |
115 |
|
|
116 |
|
Returns of records saved in total |
117 |
|
|
118 |
=cut |
=cut |
119 |
|
|
123 |
my $log = $self->_get_logger(); |
my $log = $self->_get_logger(); |
124 |
|
|
125 |
my $fields = $self->{fields} || confess "no fields?"; |
my $fields = $self->{fields} || confess "no fields?"; |
126 |
|
|
127 |
|
$log->debug("fields = ", sub { dump $fields }); |
128 |
|
|
129 |
my $path = $self->path || confess "no path?"; |
my $path = $self->path || confess "no path?"; |
130 |
|
my $webpac_dir = getcwd(); |
131 |
|
chdir $path || $log->logdie("can't chdir($path) $!"); |
132 |
|
|
133 |
|
my $affected = 0; |
134 |
|
|
135 |
my @field_names = %$fields; |
foreach my $type ( $self->consume_outputs ) { |
136 |
|
next unless defined $fields->{$type}; |
137 |
|
$affected += $self->_sync_field( $fields->{$type} ); |
138 |
|
} |
139 |
|
|
140 |
|
return $affected; |
141 |
|
}; |
142 |
|
|
143 |
|
sub _sync_field { |
144 |
|
my $self = shift; |
145 |
|
|
146 |
|
my $field_hash = shift || confess "no field?"; |
147 |
|
my $path = $self->path || confess "no path?"; |
148 |
|
|
149 |
|
my $log = $self->_get_logger(); |
150 |
|
|
151 |
|
$log->debug("field_hash = ",sub { dump($field_hash) }); |
152 |
|
|
153 |
|
my @field_names = keys %$field_hash; |
154 |
|
|
155 |
if ( ! @field_names ) { |
if ( ! @field_names ) { |
156 |
$log->warn("normalization rules don't produce any data for search!"); |
$log->warn("normalization rules don't produce any data for search!"); |
159 |
|
|
160 |
$log->info("syncing search fields: ", join(", ", @field_names)); |
$log->info("syncing search fields: ", join(", ", @field_names)); |
161 |
|
|
|
$log->debug("fields = ", sub { dump $fields }); |
|
|
|
|
|
my $webpac_dir = getcwd(); |
|
|
|
|
|
chdir $path || $log->logdie("can't chdir($path) $!"); |
|
|
|
|
162 |
# push @INC, $path; |
# push @INC, $path; |
163 |
Jifty->new(); |
Jifty->new(); |
164 |
my $system_user = Webpacus::CurrentUser->superuser; |
my $system_user = Webpacus::CurrentUser->superuser; |
167 |
my ( $count, $new, $updated ) = ( 0, 0, 0 ); |
my ( $count, $new, $updated ) = ( 0, 0, 0 ); |
168 |
|
|
169 |
foreach my $field ( @field_names ) { |
foreach my $field ( @field_names ) { |
170 |
my $items = $fields->{$field} || confess "no field?"; |
my $items = $field_hash->{$field} || confess "no field?"; |
171 |
|
|
172 |
my ( $id, $msg ) = $o->load_by_cols( name => $field ); |
my ( $id, $msg ) = $o->load_by_cols( name => $field ); |
173 |
|
|
218 |
|
|
219 |
} |
} |
220 |
|
|
221 |
|
=head2 consume_outputs |
222 |
|
|
223 |
|
Returns array with names of supported output types for this module |
224 |
|
|
225 |
|
=cut |
226 |
|
|
227 |
|
sub consume_outputs { |
228 |
|
return qw/search sorted/; |
229 |
|
} |
230 |
|
|
231 |
=head1 AUTHOR |
=head1 AUTHOR |
232 |
|
|