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

Contents of /Webpacus/lib/Webpacus/Controller/Search.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (show annotations)
Wed Nov 23 21:52:25 2005 UTC (18 years, 5 months ago) by dpavlin
File size: 1524 byte(s)
 r9075@llin:  dpavlin | 2005-11-23 22:26:53 +0100
 - added filter to search with search words in ISTRINC on selected field.
 - added new form field to search over all results (with magic name "all"

1 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 $c->req->params->{all} || $c->res->output("no results");
59
60 my @suggestions;
61
62 $log->info("search for '$q' in $what\n");
63 my @hits = $est->search( phrase => $q, max => 10, get_attr => [ $what ] );
64
65 my $used;
66
67 foreach my $res (@hits) {
68 my $v = $res->{ $what } || next;
69 next if ($used->{ $v }++);
70 push @suggestions, $v;
71 }
72
73 $c->res->body( $c->prototype->auto_complete_result( \@suggestions ) );
74 }
75
76 =back
77
78
79 =head1 AUTHOR
80
81 Dobrica Pavlinusic,,,
82
83 =head1 LICENSE
84
85 This library is free software, you can redistribute it and/or modify
86 it under the same terms as Perl itself.
87
88 =cut
89
90 1;

  ViewVC Help
Powered by ViewVC 1.1.26