3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use HyperEstraier; |
use Search::Estraier; |
7 |
use Text::Iconv; |
use Encode qw/from_to/; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
10 |
=head1 NAME |
=head1 NAME |
13 |
|
|
14 |
=head1 VERSION |
=head1 VERSION |
15 |
|
|
16 |
Version 0.05 |
Version 0.07 |
17 |
|
|
18 |
=cut |
=cut |
19 |
|
|
20 |
our $VERSION = '0.05'; |
our $VERSION = '0.07'; |
21 |
|
|
22 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
23 |
|
|
90 |
|
|
91 |
$log->info("opening Hyper Estraier index $self->{'url'} as $self->{'user'}"); |
$log->info("opening Hyper Estraier index $self->{'url'} as $self->{'user'}"); |
92 |
|
|
93 |
$self->{'db'} = HyperEstraier::Node->new($self->{'url'}); |
$self->{db} = Search::Estraier::Node->new; |
94 |
$self->{'db'}->set_auth($self->{'user'}, $self->{'passwd'}); |
$self->{db}->set_url($self->{'url'}); |
95 |
|
$self->{db}->set_auth($self->{'user'}, $self->{'passwd'}); |
96 |
|
|
97 |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
$self->{'encoding'} ||= 'ISO-8859-2'; |
98 |
$log->info("using encoding $encoding"); |
$log->info("using encoding ",$self->{encoding}); |
|
|
|
|
$self->{'iconv'} = new Text::Iconv('UTF-8', $encoding) or |
|
|
$log->die("can't create conversion from UTF-8 to $encoding"); |
|
99 |
|
|
100 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
101 |
} |
} |
146 |
|
|
147 |
$log->debug("args: " . Dumper( $args )); |
$log->debug("args: " . Dumper( $args )); |
148 |
|
|
149 |
my $cond = HyperEstraier::Condition->new(); |
my $cond = Search::Estraier::Condition->new(); |
150 |
if ( ref($args->{add_attr}) eq 'ARRAY' ) { |
if ( ref($args->{add_attr}) eq 'ARRAY' ) { |
151 |
$log->debug("adding search attributes: " . join(", ", @{ $args->{add_attr} }) ); |
$log->debug("adding search attributes: " . join(", ", @{ $args->{add_attr} }) ); |
152 |
map { |
map { |
153 |
$cond->add_attr( $self->{iconv}->convert( $_ ) ); |
$cond->add_attr( $self->convert( $_ ) ); |
154 |
$log->debug(" + $_"); |
$log->debug(" + $_"); |
155 |
} @{ $args->{add_attr} }; |
} @{ $args->{add_attr} }; |
156 |
}; |
}; |
157 |
|
|
158 |
$cond->set_phrase( $self->{iconv}->convert($q) ) if ($q); |
$cond->set_phrase( $self->convert($q) ) if ($q); |
159 |
$cond->set_options( $args->{options} ) if ($args->{options}); |
$cond->set_options( $args->{options} ) if ($args->{options}); |
160 |
$cond->set_order( $args->{order} ) if ($args->{order}); |
$cond->set_order( $args->{order} ) if ($args->{order}); |
161 |
|
|
169 |
$cond->set_max( $page * $max ); |
$cond->set_max( $page * $max ); |
170 |
|
|
171 |
my $result = $self->{db}->search($cond, ( $args->{depth} || 0 )) || |
my $result = $self->{db}->search($cond, ( $args->{depth} || 0 )) || |
172 |
$log->die("can't search for ", sub { Dumper( $args ) }); |
$log->logdie("can't search for ", sub { Dumper( $args ) }); |
173 |
|
|
174 |
my $hits = $result->doc_num; |
my $hits = $result->doc_num; |
175 |
$log->debug("found $hits hits for '$q'"); |
$log->debug("found $hits hits for '$q'"); |
190 |
foreach my $attr (@{ $args->{get_attr} }) { |
foreach my $attr (@{ $args->{get_attr} }) { |
191 |
my $val = $doc->attr( $attr ); |
my $val = $doc->attr( $attr ); |
192 |
#$log->debug("attr $attr = ", $val || 'undef'); |
#$log->debug("attr $attr = ", $val || 'undef'); |
193 |
$hash->{$attr} = $self->{iconv}->convert( $val ) if (defined($val)); |
$hash->{$attr} = $self->convert( $val ) if (defined($val)); |
194 |
} |
} |
195 |
|
|
196 |
if ($hash) { |
if ($hash) { |
232 |
} |
} |
233 |
} |
} |
234 |
|
|
235 |
|
=head2 convert |
236 |
|
|
237 |
|
convert internal encoding to UTF-8 |
238 |
|
|
239 |
|
my $utf8 = $self->convert( $text ); |
240 |
|
|
241 |
|
=cut |
242 |
|
|
243 |
|
sub convert { |
244 |
|
my $self = shift; |
245 |
|
|
246 |
|
my $text = shift || return; |
247 |
|
|
248 |
|
from_to($text, $self->{encoding}, 'UTF-8'); |
249 |
|
return $text; |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
=head2 _get_logger |
=head2 _get_logger |
254 |
|
|
255 |
For compatibility with same method from L<WebPAC::Common>, but without |
For compatibility with same method from L<WebPAC::Common>, but without |