/[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 150 - (show annotations)
Fri Nov 25 19:19:55 2005 UTC (18 years, 5 months ago) by dpavlin
File size: 2047 byte(s)
 r11136@llin:  dpavlin | 2005-11-25 20:22:07 +0100
 changed Model to take parametars from hash

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

  ViewVC Help
Powered by ViewVC 1.1.26