--- lib/Grep/Action/Search.pm 2007/02/19 16:28:00 28 +++ lib/Grep/Action/Search.pm 2007/02/21 16:19:31 55 @@ -8,11 +8,33 @@ =cut package Grep::Action::Search; -use base qw/Grep::Action::SearchItem/; + +use Grep::Search; use Data::Dump qw/dump/; use Time::HiRes qw/time/; +use Jifty::Param::Schema; +use Jifty::Action schema { + + param q => + type is 'text', + label is 'Search for', + hint is 'enter few words to search for'; + + param item_fragment => + label is 'Display format', + render as 'select', + available are qw/long short title/; + + param max => + label is 'Number or results', + render as 'select', + available are qw/10 20 50 100/; + default is '20'; + +}; + =head2 take_action =cut @@ -20,30 +42,23 @@ sub take_action { my $self = shift; - $self->SUPER::take_action( @_ ); + my $q = $self->argument_value('q') || warn "no q?"; - my $coll = $self->result->content('search'); + my $coll = Grep::Search->collection( $q ); Jifty->log->error('result not collection but ', dump( $coll )) unless ( $coll->isa('Jifty::Collection') ); - if ($coll->count > 0) { - $self->result->message( 'Found ' . $coll->count . ' results' ); - - warn "### about to fork!"; - - if (fork) { - my $t = $coll->count; - warn "### sleeping $t s..."; - sleep $t; - Grep::Event::Result->new({ coll => $coll, item_fragment => 'title' })->publish; - exit 0; - } + my $results = $coll->count; + if ($results > 0) { + $self->result->message( "Found $results results for '$q'" ); } else { - $self->result->error('No local results found, wait for remote results to arrive...'); + $self->result->error('No local results, try remote feeds...'); } + $self->result->content( search => $coll ); + return $coll; }