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

Contents of /Webpacus2/lib/Webpacus/Action/Search.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 935 - (show annotations)
Wed Oct 31 12:01:07 2007 UTC (16 years, 6 months ago) by dpavlin
File size: 1774 byte(s)
create results in Webpacus::Search::Results which is class which
somewhat mimics Jifty Collection usage while getting data from WebPAC
1 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 use Webpacus::Webpac;
15 use KinoSearch::Simple;
16
17 use Jifty::Param::Schema;
18 use Jifty::Action schema {
19
20 param field =>
21 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 param query =>
34 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 my $search = Webpacus::Model::Search->load( $self->argument_value( 'field' ) );
51 my $query = $self->argument_value( 'query' );
52
53 warn "## search = ",dump( $search );
54
55 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 my $message =
71 _('Found') . " $total_hits " .
72 _('results for') . " '$query' " .
73 _('on field') . ' ' . $search->name;
74
75 $self->result->content(
76 results => Webpacus::Search::Results->new({
77 count => $total_hits,
78 index => $index,
79 }),
80 );
81
82 $self->result->message( $message );
83
84 return 1;
85 }
86
87 package Webpacus::Search::Results;
88
89 use strict;
90 use warnings;
91 use base qw( Class::Accessor );
92 __PACKAGE__->mk_accessors( qw(
93 count
94 index
95 ) );
96
97 use Data::Dump qw/dump/;
98
99 sub next {
100 my $self = shift;
101 my $row = $self->index->fetch_hit_hashref;
102
103 warn "## next row = ", dump( $row );
104
105 return $row;
106 }
107
108 1;
109

  ViewVC Help
Powered by ViewVC 1.1.26