8 |
=cut |
=cut |
9 |
|
|
10 |
package Grep::Action::Search; |
package Grep::Action::Search; |
11 |
use base qw/Grep::Action::SearchItem/; |
|
12 |
|
use Grep::Search; |
13 |
|
|
14 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
15 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
16 |
|
|
17 |
|
use Jifty::Param::Schema; |
18 |
|
use Jifty::Action schema { |
19 |
|
|
20 |
|
param q => |
21 |
|
type is 'text', |
22 |
|
label is 'Search for', |
23 |
|
hint is 'enter few words to search for'; |
24 |
|
|
25 |
|
param item_fragment => |
26 |
|
label is 'Display format', |
27 |
|
render as 'select', |
28 |
|
available are qw/long short title/; |
29 |
|
|
30 |
|
param max => |
31 |
|
label is 'Number or results', |
32 |
|
render as 'select', |
33 |
|
available are qw/10 20 50 100/; |
34 |
|
default is '20'; |
35 |
|
|
36 |
|
}; |
37 |
|
|
38 |
=head2 take_action |
=head2 take_action |
39 |
|
|
40 |
=cut |
=cut |
42 |
sub take_action { |
sub take_action { |
43 |
my $self = shift; |
my $self = shift; |
44 |
|
|
45 |
my $q = $self->argument_value('content_contains') || warn "can't find content_contains"; |
my $q = $self->argument_value('q') || warn "no q?"; |
|
|
|
|
$self->SUPER::take_action( @_ ); |
|
46 |
|
|
47 |
my $coll = $self->result->content('search'); |
my $coll = Grep::Search->collection( $q ); |
48 |
|
|
49 |
Jifty->log->error('result not collection but ', dump( $coll )) |
Jifty->log->error('result not collection but ', dump( $coll )) |
50 |
unless ( $coll->isa('Jifty::Collection') ); |
unless ( $coll->isa('Jifty::Collection') ); |
52 |
my $results = $coll->count; |
my $results = $coll->count; |
53 |
|
|
54 |
if ($results > 0) { |
if ($results > 0) { |
55 |
$self->result->message( "Found $results results" ); |
$self->result->message( "Found $results results for '$q'" ); |
|
|
|
|
warn "### about to fork!"; |
|
|
|
|
|
if (fork) { |
|
|
my $t = $results; |
|
|
warn "### sleeping $t s..."; |
|
|
sleep $t; |
|
|
warn "### pushing results for $q after $t s"; |
|
|
|
|
|
Jifty->log->error('result not collection but ', dump( $coll )) |
|
|
unless ( $coll->isa('Jifty::Collection') ); |
|
|
Grep::Event::Result->new({ q => $q, coll => $coll, item_fragment => 'long' })->publish; |
|
|
exit 0; |
|
|
} |
|
|
|
|
56 |
} else { |
} else { |
57 |
$self->result->error('No local results found, wait for remote results to arrive...'); |
$self->result->error('No local results, try remote feeds...'); |
58 |
} |
} |
59 |
|
|
60 |
|
$self->result->content( search => $coll ); |
61 |
|
|
62 |
return $coll; |
return $coll; |
63 |
} |
} |
64 |
|
|