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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 133 - (show annotations)
Thu Nov 24 16:30:11 2005 UTC (18 years, 5 months ago) by dpavlin
File size: 1596 byte(s)
 r9103@llin:  dpavlin | 2005-11-24 15:00:27 +0100
 added ability to specify word operator by inserting field which is called
 same as search fields but begins with underscore (_). You can put Hyper
 Estraier operator in there (e.g. AND, OR) to force search engine to
 insert those characters between words entered in that field

1 package Webpacus::Controller::Results;
2
3 use strict;
4 use warnings;
5 use base qw/Catalyst::Controller/;
6 use Data::Dumper;
7
8 =head1 NAME
9
10 Webpacus::Controller::Results - Display results from WebPAC
11
12 =head1 SYNOPSIS
13
14 See L<Webpacus>
15
16 =head1 DESCRIPTION
17
18 Catalyst Controller.
19
20 =head1 METHODS
21
22 =over 4
23
24 =item default
25
26 =cut
27
28 sub default : Private {
29 my ( $self, $c ) = @_;
30
31 my $webpac = $c->comp('Model::WebPAC');
32 my $params = $c->req->params;
33 my $log = $c->log;
34
35 $log->debug("results got params: " . Dumper( $params ) );
36
37 my @attr;
38 my @words;
39 # default operator to join fields/words
40 my $operator = 'AND';
41
42 foreach my $f (keys %{ $params }) {
43
44 next if ($f =~ m/^_/o);
45
46 my $v = $params->{$f} || next;
47
48 if (my $op = $params->{ '_' . $f}) {
49 push @words, join(" $op ", split(/\s+/, $v) );
50 } else {
51 push @words, $v;
52 }
53
54 next if ($f eq 'all'); # don't add_attr for magic field all
55
56 if ($v !~ /\s/) {
57 push @attr, "$f ISTRINC $v";
58 } else {
59 map { push @attr, "$f ISTRINC $_"; } split(/\s+/, $v);
60 }
61 }
62
63 my $q = join(" $operator ", @words);
64
65 $c->stash->{html_results} = sub {
66 my $res = $webpac->search( $q, $params->{'_template'}, \@attr );
67 # $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res ));
68 return $res;
69 };
70
71 $c->stash->{phrase} = $q;
72 $c->stash->{attr} = \@attr;
73
74 $c->stash->{template} = 'results.tt';
75 }
76
77 =back
78
79
80 =head1 AUTHOR
81
82 Dobrica Pavlinusic,,,
83
84 =head1 LICENSE
85
86 This library is free software, you can redistribute it and/or modify
87 it under the same terms as Perl itself.
88
89 =cut
90
91 1;

  ViewVC Help
Powered by ViewVC 1.1.26