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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 109 - (hide annotations)
Tue Nov 22 20:26:52 2005 UTC (18 years, 5 months ago) by dpavlin
File size: 1454 byte(s)
 r9057@llin:  dpavlin | 2005-11-22 21:28:28 +0100
 "the great renaming"

1 dpavlin 109 package Webpacus::Controller::Search;
2    
3     use strict;
4     use warnings;
5     use base 'Catalyst::Controller';
6    
7     use lib '/data/webpac2/lib';
8     use WebPAC::Search::Estraier;
9    
10     =head1 NAME
11    
12     Webpacus::Controller::Search - Catalyst Controller
13    
14     =head1 SYNOPSIS
15    
16     See L<Webpacus>
17    
18     =head1 DESCRIPTION
19    
20     Catalyst Controller for autocompleting search fields.
21    
22     =head1 METHODS
23    
24     =over 4
25    
26     =item default
27    
28     =cut
29    
30     sub default : Private {
31     my ( $self, $c ) = @_;
32     $c->stash->{template} = 'search.tt';
33     }
34    
35     =item suggest
36    
37     Returns results for URLs like C<search/suggest/FieldName>
38    
39     =cut
40    
41     sub suggest : Regex('^search/suggest/*([^/]*)') {
42     my ( $self, $c ) = @_;
43    
44     my $what = $c->request->snippets->[0];
45    
46     my $log = $c->log;
47    
48     my $est = new WebPAC::Search::Estraier(
49     url => 'http://localhost:1978/node/webpac2',
50     user => 'admin',
51     passwd => 'admin',
52     encoding => 'UTF-8',
53     log => $c->log,
54     );
55    
56    
57     my $q = $c->req->params->{$what};
58     my @suggestions;
59    
60     $log->info("search for '$q' in $what\n");
61     my @hits = $est->search( query => $q, max => 10, attr => [ $what ] );
62    
63     my $used;
64    
65     foreach my $res (@hits) {
66     my $v = $res->{ $what } || next;
67     next if ($used->{ $v }++);
68     push @suggestions, $v;
69     }
70    
71     $c->res->body( $c->prototype->auto_complete_result( \@suggestions ) );
72     }
73    
74     =back
75    
76    
77     =head1 AUTHOR
78    
79     Dobrica Pavlinusic,,,
80    
81     =head1 LICENSE
82    
83     This library is free software, you can redistribute it and/or modify
84     it under the same terms as Perl itself.
85    
86     =cut
87    
88     1;

  ViewVC Help
Powered by ViewVC 1.1.26