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 |
dpavlin |
29 |
my $q = $self->argument_value('content_contains') || warn "can't find content_contains"; |
24 |
|
|
|
25 |
dpavlin |
28 |
$self->SUPER::take_action( @_ ); |
26 |
|
|
|
27 |
|
|
my $coll = $self->result->content('search'); |
28 |
|
|
|
29 |
|
|
Jifty->log->error('result not collection but ', dump( $coll )) |
30 |
|
|
unless ( $coll->isa('Jifty::Collection') ); |
31 |
|
|
|
32 |
dpavlin |
29 |
my $results = $coll->count; |
33 |
dpavlin |
28 |
|
34 |
dpavlin |
29 |
if ($results > 0) { |
35 |
|
|
$self->result->message( "Found $results results" ); |
36 |
|
|
|
37 |
dpavlin |
28 |
warn "### about to fork!"; |
38 |
|
|
|
39 |
|
|
if (fork) { |
40 |
dpavlin |
29 |
my $t = $results; |
41 |
dpavlin |
28 |
warn "### sleeping $t s..."; |
42 |
|
|
sleep $t; |
43 |
dpavlin |
29 |
warn "### pushing results for $q after $t s"; |
44 |
|
|
|
45 |
|
|
Jifty->log->error('result not collection but ', dump( $coll )) |
46 |
|
|
unless ( $coll->isa('Jifty::Collection') ); |
47 |
|
|
Grep::Event::Result->new({ q => $q, coll => $coll, item_fragment => 'long' })->publish; |
48 |
dpavlin |
28 |
exit 0; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
} else { |
52 |
|
|
$self->result->error('No local results found, wait for remote results to arrive...'); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
return $coll; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
1; |
59 |
|
|
|