/[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

Annotation of /Webpacus/lib/Webpacus/Model/WebPAC.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 96 - (hide annotations)
Tue Nov 22 12:57:30 2005 UTC (18 years, 5 months ago) by dpavlin
File size: 2624 byte(s)
 r9026@llin:  dpavlin | 2005-11-22 11:08:17 +0100
 fix encoding comming from WebPAC::Output

1 dpavlin 92 package Webpacus::Model::WebPAC;
2    
3     use strict;
4     use warnings;
5     use lib '/data/webpac2/lib';
6 dpavlin 93 use base qw/
7     Catalyst::Model
8     WebPAC::Search::Estraier
9     /;
10 dpavlin 92 use Data::Dumper;
11 dpavlin 95 use WebPAC::DB;
12     use WebPAC::Output::TT;
13 dpavlin 92
14     =head1 NAME
15    
16     Webpacus::Model::WebPAC - Catalyst Model
17    
18     =head1 SYNOPSIS
19    
20     See L<Webpacus> and L<WebPAC>.
21    
22     =head1 DESCRIPTION
23    
24     Catalyst Model for access to WebPAC data.
25    
26     =head2 new
27    
28     Configuration for hyperestraier in C<config.yaml> like this:
29    
30     --- #YAML:1.0
31     # DO NOT USE TABS FOR INDENTATION OR label/value SEPARATION!!!
32    
33     # configuration for hyper estraier full text search engine
34     hyperestraier:
35 dpavlin 96 url: 'http://localhost:1978/node/webpac2'
36     user: 'admin'
37     passwd: 'admin'
38 dpavlin 92
39 dpavlin 96 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 dpavlin 92 =cut
49    
50     sub new {
51     my ( $self, $c, $config ) = @_;
52    
53     $self = $self->NEXT::new($c, $config);
54     $self->config($config);
55    
56     my $log = $c->log;
57 dpavlin 94 $self->{log} = $log;
58 dpavlin 92
59 dpavlin 93 my $est_cfg = $c->config->{hyperestraier};
60     $est_cfg->{'log'} = $log;
61 dpavlin 92
62 dpavlin 93 $log->debug("using config:" . Dumper($est_cfg) );
63 dpavlin 92
64 dpavlin 93 $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } );
65 dpavlin 92
66 dpavlin 95 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     $self->{template} ||= $c->config->{webpac}->{template};
82    
83 dpavlin 96 $self->{iconv} = new Text::Iconv(
84     $c->config->{webpac}->{webpac_encoding},
85     $c->config->{webpac}->{out_encoding}
86     );
87    
88    
89 dpavlin 92 return $self;
90    
91     }
92    
93 dpavlin 93 sub search {
94     my ( $self, $query ) = @_;
95    
96 dpavlin 95 my $log = $self->{log};
97 dpavlin 94
98 dpavlin 95 $log->debug("search got query: $query<--");
99    
100     my $template_filename = $self->{template};
101    
102 dpavlin 93 my @results = $self->{est}->search(
103     query => $query,
104     attr => [ '@uri' ],
105     max => 100,
106     );
107    
108 dpavlin 95 for my $i ( 0 .. $#results ) {
109    
110     my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#);
111    
112     $log->debug("load_ds( $mfn )");
113    
114     my $ds = $self->{db}->load_ds( $mfn ) || next;
115 dpavlin 96 $results[$i]->{ html } = $self->{iconv}->convert(
116     $self->{out}->apply(
117 dpavlin 95 template => $template_filename,
118     data => $ds,
119 dpavlin 96 ) );
120 dpavlin 95 }
121    
122     return \@results;
123 dpavlin 93 }
124    
125    
126    
127    
128 dpavlin 92 =head1 AUTHOR
129    
130     Dobrica Pavlinusic
131    
132     =head1 LICENSE
133    
134     This library is free software, you can redistribute it and/or modify
135     it under the same terms as Perl itself.
136    
137     =cut
138    
139     1;

  ViewVC Help
Powered by ViewVC 1.1.26