/[Grep]/lib/Grep/Action/Search.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/Grep/Action/Search.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 59 - (show annotations)
Wed Feb 21 19:11:06 2007 UTC (17 years, 2 months ago) by dpavlin
File size: 1205 byte(s)
better error messages which enable Grep to actually work without index for the first time
1 use strict;
2 use warnings;
3
4 =head1 NAME
5
6 Grep::Action::Search
7
8 =cut
9
10 package Grep::Action::Search;
11
12 use Grep::Search;
13
14 use Data::Dump qw/dump/;
15 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
39
40 =cut
41
42 sub take_action {
43 my $self = shift;
44
45 my $q = $self->argument_value('q');
46
47 return $self->result->error("Need search query") unless ($q);
48
49 my $coll = Grep::Search->collection( $q ) ||
50 return $self->result->error("No results");
51
52 $self->log->fatal('result not collection but ', dump( $coll ))
53 if ( !$coll || !$coll->isa('Jifty::Collection') );
54
55 my $results = $coll->count;
56
57 if ($results > 0) {
58 $self->result->message( "Found $results results for '$q'" );
59 } else {
60 $self->result->error('No local results, try remote feeds...');
61 }
62
63 $self->result->content( search => $coll );
64
65 return $coll;
66 }
67
68 1;
69

  ViewVC Help
Powered by ViewVC 1.1.26