/[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 92 by dpavlin, Tue Nov 22 12:57:09 2005 UTC revision 100 by dpavlin, Tue Nov 22 14:45:17 2005 UTC
# Line 3  package Webpacus::Model::WebPAC; Line 3  package Webpacus::Model::WebPAC;
3  use strict;  use strict;
4  use warnings;  use warnings;
5  use lib '/data/webpac2/lib';  use lib '/data/webpac2/lib';
6  use base qw/Catalyst::Model/;  use base qw/
7  use WebPAC::Search::Estraier;          Catalyst::Model
8            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 28  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 41  sub new { Line 54  sub new {
54          $self->config($config);          $self->config($config);
55    
56          my $log = $c->log;          my $log = $c->log;
57            $self->{log} = $log;
58    
59  #       if (! $c->stash->{est}) {          my $est_cfg = $c->config->{hyperestraier};
60            $est_cfg->{'log'} = $log;
61    
62                  my $est_cfg = $c->config->{hyperestraier};          $log->debug("using config:" . Dumper($est_cfg) );
                 $est_cfg->{'log'} = $log;  
63    
64                  $log->debug("using config:" . Dumper($est_cfg) );          $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } );
65    
66  #               $c->stash->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } );          my $db_path = $c->config->{webpac}->{db_path};
67  #       }          my $template_path = $c->config->{webpac}->{template_path};
68    
69  #       $log->debug("param: " . Dumper($c->req->params));          $log->debug("using db path '$db_path', template path '$template_path'");
70    
71  #       $c->stash->{est}->search(          $self->{db} = new WebPAC::DB(
72  #               query => $c->req->params->{Title},                  path => $db_path,
73  #               max => 100,                  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            $self->{template} ||= $c->config->{webpac}->{template};
82    
83            $self->{iconv} = new Text::Iconv(
84                    $c->config->{webpac}->{webpac_encoding},
85                    $c->config->{webpac}->{out_encoding}
86            );
87    
88            $log->debug("converting encoding from webpac_encoding '" .
89                    $c->config->{webpac}->{webpac_encoding} .
90                    "' to '" .
91                    $c->config->{webpac}->{out_encoding} .
92                    "'"
93            );
94    
95          return $self;          return $self;
96    
97  }  }
98    
99    sub search {
100            my ( $self, $query ) = @_;
101    
102            my $log = $self->{log};
103    
104            $log->debug("search model query: -->$query<--");
105    
106            my $template_filename = $self->{template};
107    
108            my @results = $self->{est}->search(
109                    query => $query,
110                    attr => [ '@uri' ],
111                    max => 100,
112            );
113    
114            $log->debug("loading " . ($#results + 1) . " results");
115    
116            my @html_results;
117    
118            for my $i ( 0 .. $#results ) {
119    
120                    my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#);
121    
122                    # $log->debug("load_ds( $mfn )");
123    
124                    my $ds = $self->{db}->load_ds( $mfn ) || next;
125            
126                    my $html = $self->{out}->apply(
127                            template => $template_filename,
128                            data => $ds,
129                    );
130    
131                    $html = $self->{iconv}->convert( $html ) || $log->error("can't convert: $html");
132    
133                    push @html_results, $html;
134    
135            }
136    
137            return \@html_results;
138    }
139    
140    
141            
142    
143  =head1 AUTHOR  =head1 AUTHOR
144    
145  Dobrica Pavlinusic  Dobrica Pavlinusic

Legend:
Removed from v.92  
changed lines
  Added in v.100

  ViewVC Help
Powered by ViewVC 1.1.26