1 |
dpavlin |
28 |
use strict; |
2 |
|
|
use warnings; |
3 |
|
|
|
4 |
|
|
=head1 NAME |
5 |
|
|
|
6 |
|
|
Grep::Action::Search |
7 |
|
|
|
8 |
|
|
=cut |
9 |
|
|
|
10 |
|
|
package Grep::Action::Search; |
11 |
|
|
use base qw/Grep::Action::SearchItem/; |
12 |
|
|
|
13 |
|
|
use Data::Dump qw/dump/; |
14 |
|
|
use Time::HiRes qw/time/; |
15 |
|
|
|
16 |
|
|
=head2 take_action |
17 |
|
|
|
18 |
|
|
=cut |
19 |
|
|
|
20 |
|
|
sub take_action { |
21 |
|
|
my $self = shift; |
22 |
|
|
|
23 |
|
|
$self->SUPER::take_action( @_ ); |
24 |
|
|
|
25 |
|
|
my $coll = $self->result->content('search'); |
26 |
|
|
|
27 |
|
|
Jifty->log->error('result not collection but ', dump( $coll )) |
28 |
|
|
unless ( $coll->isa('Jifty::Collection') ); |
29 |
|
|
|
30 |
|
|
if ($coll->count > 0) { |
31 |
|
|
$self->result->message( 'Found ' . $coll->count . ' results' ); |
32 |
|
|
|
33 |
|
|
warn "### about to fork!"; |
34 |
|
|
|
35 |
|
|
if (fork) { |
36 |
|
|
my $t = $coll->count; |
37 |
|
|
warn "### sleeping $t s..."; |
38 |
|
|
sleep $t; |
39 |
|
|
Grep::Event::Result->new({ coll => $coll, item_fragment => 'title' })->publish; |
40 |
|
|
exit 0; |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
} else { |
44 |
|
|
$self->result->error('No local results found, wait for remote results to arrive...'); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
return $coll; |
48 |
|
|
} |
49 |
|
|
|
50 |
|
|
1; |
51 |
|
|
|