/[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 95 by dpavlin, Tue Nov 22 12:57:25 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 41  sub new { Line 45  sub new {
45          $self->config($config);          $self->config($config);
46    
47          my $log = $c->log;          my $log = $c->log;
48            $self->{log} = $log;
49    
50  #       if (! $c->stash->{est}) {          my $est_cfg = $c->config->{hyperestraier};
51            $est_cfg->{'log'} = $log;
52    
53                  my $est_cfg = $c->config->{hyperestraier};          $log->debug("using config:" . Dumper($est_cfg) );
                 $est_cfg->{'log'} = $log;  
54    
55                  $log->debug("using config:" . Dumper($est_cfg) );          $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } );
56    
57  #               $c->stash->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } );          my $db_path = $c->config->{webpac}->{db_path};
58  #       }          my $template_path = $c->config->{webpac}->{template_path};
59    
60  #       $log->debug("param: " . Dumper($c->req->params));          $log->debug("using db path '$db_path', template path '$template_path'");
61    
62  #       $c->stash->{est}->search(          $self->{db} = new WebPAC::DB(
63  #               query => $c->req->params->{Title},                  path => $db_path,
64  #               max => 100,                  read_only => 1,
65  #       );          );
66    
67            $self->{out} = new WebPAC::Output::TT(
68                    include_path => $template_path,
69                    filters => { foo => sub { shift } },
70            );
71    
72            $self->{template} ||= $c->config->{webpac}->{template};
73    
74          return $self;          return $self;
75    
76  }  }
77    
78    sub search {
79            my ( $self, $query ) = @_;
80    
81            my $log = $self->{log};
82    
83            $log->debug("search got query: $query<--");
84    
85            my $template_filename = $self->{template};
86    
87            my @results = $self->{est}->search(
88                    query => $query,
89                    attr => [ '@uri' ],
90                    max => 100,
91            );
92    
93            for my $i ( 0 .. $#results ) {
94    
95                    my $mfn = $1 if ( $results[$i]->{'@uri'} =~ m#/(\d+)$#);
96    
97                    $log->debug("load_ds( $mfn )");
98    
99                    my $ds = $self->{db}->load_ds( $mfn ) || next;
100                    $results[$i]->{ html } = $self->{out}->apply(
101                            template => $template_filename,
102                            data => $ds,
103                    );
104            }
105    
106            return \@results;
107    }
108    
109    
110            
111    
112  =head1 AUTHOR  =head1 AUTHOR
113    
114  Dobrica Pavlinusic  Dobrica Pavlinusic

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

  ViewVC Help
Powered by ViewVC 1.1.26