/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (hide annotations)
Sat Jun 9 09:15:41 2007 UTC (16 years, 11 months ago) by dpavlin
File size: 1279 byte(s)
debug log from action
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    
12 dpavlin 47 use Grep::Search;
13    
14 dpavlin 28 use Data::Dump qw/dump/;
15     use Time::HiRes qw/time/;
16    
17 dpavlin 47 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 dpavlin 55 label is 'Display format',
27 dpavlin 47 render as 'select',
28     available are qw/long short title/;
29    
30 dpavlin 55 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 dpavlin 47 };
37    
38 dpavlin 28 =head2 take_action
39    
40     =cut
41    
42     sub take_action {
43     my $self = shift;
44    
45 dpavlin 59 my $q = $self->argument_value('q');
46 dpavlin 29
47 dpavlin 59 return $self->result->error("Need search query") unless ($q);
48 dpavlin 28
49 dpavlin 109 my $search = Grep::Search->new();
50    
51 dpavlin 149 $self->log->debug("action is searching for $q");
52    
53 dpavlin 109 my $coll = $search->collection( $q ) ||
54 dpavlin 59 return $self->result->error("No results");
55 dpavlin 28
56 dpavlin 59 $self->log->fatal('result not collection but ', dump( $coll ))
57     if ( !$coll || !$coll->isa('Jifty::Collection') );
58    
59 dpavlin 141 my $hits = $search->hits;
60 dpavlin 28
61 dpavlin 141 if ($hits > 0) {
62     $self->result->message( "Found $hits results for '$q'" );
63 dpavlin 28 } else {
64 dpavlin 38 $self->result->error('No local results, try remote feeds...');
65 dpavlin 28 }
66    
67 dpavlin 47 $self->result->content( search => $coll );
68    
69 dpavlin 28 return $coll;
70     }
71    
72     1;
73    

  ViewVC Help
Powered by ViewVC 1.1.26