/[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 95 by dpavlin, Tue Nov 22 12:57:25 2005 UTC revision 119 by dpavlin, Wed Nov 23 21:52:35 2005 UTC
# Line 5  use warnings; Line 5  use warnings;
5  use lib '/data/webpac2/lib';  use lib '/data/webpac2/lib';
6  use base qw/  use base qw/
7          Catalyst::Model          Catalyst::Model
         WebPAC::Search::Estraier  
8  /;  /;
9  use Data::Dumper;  use Data::Dumper;
10  use WebPAC::DB;  use WebPAC::DB;
11  use WebPAC::Output::TT;  use WebPAC::Output::TT;
12    use WebPAC::Search::Estraier 0.02;
13    
14  =head1 NAME  =head1 NAME
15    
# Line 32  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 69  sub new { Line 78  sub new {
78                  filters => { foo => sub { shift } },                  filters => { foo => sub { shift } },
79          );          );
80    
81            # default template from config.yaml
82          $self->{template} ||= $c->config->{webpac}->{template};          $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, $add_attr ) = @_;
102    
103          my $log = $self->{log};          my $log = $self->{log};
104    
105          $log->debug("search got query: $query<--");          $log->debug("search model query: '$query', add_attr: '" . join("','", @{$add_attr}) . "'");
106    
107          my $template_filename = $self->{template};          my $template_filename = $template || $self->{template};
108    
109          my @results = $self->{est}->search(          my @results = $self->{est}->search(
110                  query => $query,                  phrase => $query,
111                  attr => [ '@uri' ],                  get_attr => [ '@uri' ],
112                  max => 100,                  max => 100,
113                    add_attr => $add_attr,
114          );          );
115    
116            $log->debug("loading " . ($#results + 1) . " results");
117    
118            my @html_results;
119    
120          for my $i ( 0 .. $#results ) {          for my $i ( 0 .. $#results ) {
121    
122                  my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#);                  my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#);
123    
124                  $log->debug("load_ds( $mfn )");                  #$log->debug("load_ds( $mfn )");
125    
126                  my $ds = $self->{db}->load_ds( $mfn ) || next;                  my $ds = $self->{db}->load_ds( $mfn ) || $log->error("can't load_ds( $mfn )") && next;
127                  $results[$i]->{ html } = $self->{out}->apply(          
128                    #$log->debug( "ds = " . Dumper( \@html_results ) );
129    
130                    my $html = $self->{out}->apply(
131                          template => $template_filename,                          template => $template_filename,
132                          data => $ds,                          data => $ds,
133                  );                  );
134    
135                    $html = $self->{iconv}->convert( $html ) || $log->error("can't convert: $html");
136    
137                    push @html_results, $html;
138    
139          }          }
140    
141          return \@results;          #$log->debug( '@html_results = ' . Dumper( \@html_results ) );
142    
143            return \@html_results;
144  }  }
145    
146    

Legend:
Removed from v.95  
changed lines
  Added in v.119

  ViewVC Help
Powered by ViewVC 1.1.26