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

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

revision 94 by dpavlin, Tue Nov 22 12:57:20 2005 UTC revision 101 by dpavlin, Tue Nov 22 15:29:06 2005 UTC
# Line 8  use base qw/ Line 8  use base qw/
8          WebPAC::Search::Estraier          WebPAC::Search::Estraier
9  /;  /;
10  use Data::Dumper;  use Data::Dumper;
11    use WebPAC::DB;
12    use WebPAC::Output::TT;
13    
14  =head1 NAME  =head1 NAME
15    
# Line 30  Configuration for hyperestraier in C<con Line 32  Configuration for hyperestraier in C<con
32    
33   # configuration for hyper estraier full text search engine   # configuration for hyper estraier full text search engine
34   hyperestraier:   hyperestraier:
35      url: 'http://localhost:1978/node/webpac2'    url: 'http://localhost:1978/node/webpac2'
36      user: 'admin'    user: 'admin'
37      passwd: 'admin'    passwd: 'admin'
38    
39     webpac:
40      db_path: '/data/webpac2/db'
41      template_path: '/data/webpac2/conf/output/tt'
42      template: 'html_ffzg_results_short.tt'
43      # encoding comming from webpac
44      webpac_encoding: 'iso-8859-2'
45      # encoding expected by Catalyst
46      out_encoding: 'UTF-8'
47    
48  =cut  =cut
49    
# Line 52  sub new { Line 63  sub new {
63    
64          $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } );          $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } );
65    
66            my $db_path = $c->config->{webpac}->{db_path};
67            my $template_path = $c->config->{webpac}->{template_path};
68    
69            $log->debug("using db path '$db_path', template path '$template_path'");
70    
71            $self->{db} = new WebPAC::DB(
72                    path => $db_path,
73                    read_only => 1,
74            );
75    
76            $self->{out} = new WebPAC::Output::TT(
77                    include_path => $template_path,
78                    filters => { foo => sub { shift } },
79            );
80    
81            # default template from config.yaml
82            $self->{template} ||= $c->config->{webpac}->{template};
83    
84            $self->{iconv} = new Text::Iconv(
85                    $c->config->{webpac}->{webpac_encoding},
86                    $c->config->{webpac}->{out_encoding}
87            );
88    
89            $log->debug("converting encoding from webpac_encoding '" .
90                    $c->config->{webpac}->{webpac_encoding} .
91                    "' to '" .
92                    $c->config->{webpac}->{out_encoding} .
93                    "'"
94            );
95    
96          return $self;          return $self;
97    
98  }  }
99    
100  sub search {  sub search {
101          my ( $self, $query ) = @_;          my ( $self, $query, $template ) = @_;
102    
103          $self->{log}->debug("search got query: $query<--");          my $log = $self->{log};
104    
105            $log->debug("search model query: -->$query<--");
106    
107            my $template_filename = $template || $self->{template};
108    
109          my @results = $self->{est}->search(          my @results = $self->{est}->search(
110                  query => $query,                  query => $query,
# Line 67  sub search { Line 112  sub search {
112                  max => 100,                  max => 100,
113          );          );
114    
115          return @results;          $log->debug("loading " . ($#results + 1) . " results");
116    
117            my @html_results;
118    
119            for my $i ( 0 .. $#results ) {
120    
121                    my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#);
122    
123                    # $log->debug("load_ds( $mfn )");
124    
125                    my $ds = $self->{db}->load_ds( $mfn ) || next;
126            
127                    my $html = $self->{out}->apply(
128                            template => $template_filename,
129                            data => $ds,
130                    );
131    
132                    $html = $self->{iconv}->convert( $html ) || $log->error("can't convert: $html");
133    
134                    push @html_results, $html;
135    
136            }
137    
138            return \@html_results;
139  }  }
140    
141    

Legend:
Removed from v.94  
changed lines
  Added in v.101

  ViewVC Help
Powered by ViewVC 1.1.26