/[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 95 - (hide annotations)
Tue Nov 22 12:57:25 2005 UTC (18 years, 5 months ago) by dpavlin
File size: 2226 byte(s)
 r9023@llin:  dpavlin | 2005-11-22 10:17:01 +0100
 first try at implementing full results

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     url: 'http://localhost:1978/node/webpac2'
36     user: 'admin'
37     passwd: 'admin'
38    
39     =cut
40    
41     sub new {
42     my ( $self, $c, $config ) = @_;
43    
44     $self = $self->NEXT::new($c, $config);
45     $self->config($config);
46    
47     my $log = $c->log;
48 dpavlin 94 $self->{log} = $log;
49 dpavlin 92
50 dpavlin 93 my $est_cfg = $c->config->{hyperestraier};
51     $est_cfg->{'log'} = $log;
52 dpavlin 92
53 dpavlin 93 $log->debug("using config:" . Dumper($est_cfg) );
54 dpavlin 92
55 dpavlin 93 $self->{est} = new WebPAC::Search::Estraier( %{ $est_cfg } );
56 dpavlin 92
57 dpavlin 95 my $db_path = $c->config->{webpac}->{db_path};
58     my $template_path = $c->config->{webpac}->{template_path};
59    
60     $log->debug("using db path '$db_path', template path '$template_path'");
61    
62     $self->{db} = new WebPAC::DB(
63     path => $db_path,
64     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 dpavlin 92 return $self;
75    
76     }
77    
78 dpavlin 93 sub search {
79     my ( $self, $query ) = @_;
80    
81 dpavlin 95 my $log = $self->{log};
82 dpavlin 94
83 dpavlin 95 $log->debug("search got query: $query<--");
84    
85     my $template_filename = $self->{template};
86    
87 dpavlin 93 my @results = $self->{est}->search(
88     query => $query,
89     attr => [ '@uri' ],
90     max => 100,
91     );
92    
93 dpavlin 95 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 dpavlin 93 }
108    
109    
110    
111    
112 dpavlin 92 =head1 AUTHOR
113    
114     Dobrica Pavlinusic
115    
116     =head1 LICENSE
117    
118     This library is free software, you can redistribute it and/or modify
119     it under the same terms as Perl itself.
120    
121     =cut
122    
123     1;

  ViewVC Help
Powered by ViewVC 1.1.26