/[webpac2]/Webpacus2/lib/Webpacus/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 /Webpacus2/lib/Webpacus/Action/Search.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 934 - (hide annotations)
Wed Oct 31 11:26:39 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 1419 byte(s)
make a search using KinoSearch::Simple
1 dpavlin 930 use strict;
2     use warnings;
3    
4     =head1 NAME
5    
6     Webpacus::Action::Search
7    
8     =cut
9    
10     package Webpacus::Action::Search;
11     use base qw/Webpacus::Action Jifty::Action/;
12    
13     use Data::Dump qw/dump/;
14 dpavlin 934 use Webpacus::Webpac;
15     use KinoSearch::Simple;
16 dpavlin 930
17     use Jifty::Param::Schema;
18     use Jifty::Action schema {
19    
20 dpavlin 931 param field =>
21 dpavlin 930 label is _("Field name"),
22     available are defer {
23     my $coll = Webpacus::Model::SearchCollection->new;
24     $coll->unlimit;
25     [ '', {
26     display_from => 'name',
27     value_from => 'id',
28     collection => $coll,
29     }];
30     },
31     render as 'Select';
32    
33 dpavlin 931 param query =>
34 dpavlin 930 label is _("Search for"),
35     is mandatory;
36    
37    
38     };
39    
40     sub sticky_on_success { 1 }
41     sub sticky_on_failure { 1 }
42    
43     =head2 take_action
44    
45     =cut
46    
47     sub take_action {
48     my $self = shift;
49    
50 dpavlin 931 my $search = Webpacus::Model::Search->load( $self->argument_value( 'field' ) );
51 dpavlin 934 my $query = $self->argument_value( 'query' );
52 dpavlin 930
53     warn "## search = ",dump( $search );
54    
55 dpavlin 934 my $index_path = Webpacus::Webpac->index_path;
56    
57     warn "## index_path = $index_path";
58    
59     my $index = KinoSearch::Simple->new(
60     path => $index_path,
61     language => 'en',
62     );
63    
64     my $total_hits = $index->search(
65     query => $query,
66     offset => 0,
67     num_wanted => 100,
68     );
69    
70 dpavlin 931 my $message =
71 dpavlin 934 _('Found') . " $total_hits " .
72     _('results for') . " '$query' " .
73 dpavlin 931 _('on field') . ' ' . $search->name;
74 dpavlin 930
75 dpavlin 934
76     while ( my $hit = $index->fetch_hit_hashref ) {
77     warn dump($hit);
78     }
79    
80    
81 dpavlin 930 $self->result->message( $message );
82    
83     return 1;
84     }
85    
86     1;
87    

  ViewVC Help
Powered by ViewVC 1.1.26