3 |
use strict; |
use strict; |
4 |
use warnings; |
use warnings; |
5 |
use base qw/Catalyst::Controller/; |
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 |
=head1 NAME |
13 |
|
|
30 |
=cut |
=cut |
31 |
|
|
32 |
sub default : Private { |
sub default : Private { |
33 |
my ( $self, $c ) = @_; |
my ( $self, $c ) = @_; |
|
|
|
|
my $webpac = $c->comp('Model::WebPAC'); |
|
|
my $params = $c->req->params; |
|
|
my $log = $c->log; |
|
|
|
|
|
use Data::Dumper; |
|
|
$log->debug("results got params: " . Dumper( $params ) ); |
|
34 |
|
|
35 |
my $q; |
my $webpac = $c->comp('Model::WebPAC'); |
36 |
my @attr; |
my $params = $c->req->params; |
37 |
|
my $log = $c->log; |
38 |
foreach my $f (keys %{ $params }) { |
|
39 |
|
$log->debug("results got params: " . Dumper( $params ) ); |
40 |
next if ($f =~ m/^_/o); |
|
41 |
|
my @attr; |
42 |
my $v = $params->{$f} || next; |
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 |
$q .= "$v "; |
my $q = join(" $operator ", @words); |
76 |
|
|
77 |
next if ($f eq 'all'); # don't add_attr for magic field all |
my $template = $params->{'_template'}; |
78 |
|
$log->debug("using template $template"); |
79 |
|
|
80 |
if ($v !~ /\s/) { |
$c->stash->{html_results} = sub { |
81 |
push @attr, "$f ISTRINC $v"; |
my $res = $webpac->search( $q, $template, \@attr ); |
82 |
} else { |
# $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res )); |
83 |
map { push @attr, "$f ISTRINC $_"; } split(/\s+/, $v); |
return $res; |
84 |
} |
}; |
|
} |
|
85 |
|
|
86 |
$c->stash->{html_results} = sub { |
$c->stash->{phrase} = $q; |
87 |
my $res = $webpac->search( $q, $params->{'_template'}, \@attr ); |
$c->stash->{attr} = \@attr; |
|
# $log->debug("controller got " . ( $#{$res} + 1 ) . " results for '$q' " . Dumper( $res )); |
|
|
return $res; |
|
|
}; |
|
88 |
|
|
89 |
$c->stash->{template} = 'results.tt'; |
$c->stash->{template} = 'results.tt'; |
90 |
} |
} |
91 |
|
|
92 |
=back |
=back |