/[webpac2]/trunk/lib/WebPAC/Search/Estraier.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

Diff of /trunk/lib/WebPAC/Search/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 534 by dpavlin, Wed May 10 13:56:28 2006 UTC revision 535 by dpavlin, Mon Jun 26 16:39:42 2006 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use strict;  use strict;
5    
6  use Search::Estraier;  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
# Line 13  WebPAC::Search::Estraier - search Hyper Line 13  WebPAC::Search::Estraier - search Hyper
13    
14  =head1 VERSION  =head1 VERSION
15    
16  Version 0.06  Version 0.07
17    
18  =cut  =cut
19    
20  our $VERSION = '0.06';  our $VERSION = '0.07';
21    
22  =head1 SYNOPSIS  =head1 SYNOPSIS
23    
# Line 94  sub new { Line 94  sub new {
94          $self->{db}->set_url($self->{'url'});          $self->{db}->set_url($self->{'url'});
95          $self->{db}->set_auth($self->{'user'}, $self->{'passwd'});          $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  }  }
# Line 153  sub search { Line 150  sub search {
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    
# Line 193  sub search { Line 190  sub search {
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) {
# Line 235  sub confess { Line 232  sub confess {
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

Legend:
Removed from v.534  
changed lines
  Added in v.535

  ViewVC Help
Powered by ViewVC 1.1.26