/[webpac2]/trunk/lib/WebPAC/Output/Estraier.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 /trunk/lib/WebPAC/Output/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Sat Jun 25 20:23:23 2005 UTC revision 113 by dpavlin, Wed Nov 23 00:14:05 2005 UTC
# Line 3  package WebPAC::Output::Estraier; Line 3  package WebPAC::Output::Estraier;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6    use base qw/WebPAC::Common/;
7    
8    use HyperEstraier;
9    use Text::Iconv;
10    use Data::Dumper;
11    
12  =head1 NAME  =head1 NAME
13    
14  WebPAC::Output::Estraier - The great new WebPAC::Output::Estraier!  WebPAC::Output::Estraier - Create Hyper Estraier full text index
15    
16  =head1 VERSION  =head1 VERSION
17    
# Line 17  our $VERSION = '0.01'; Line 23  our $VERSION = '0.01';
23    
24  =head1 SYNOPSIS  =head1 SYNOPSIS
25    
26  Quick summary of what the module does.  Create full text index using Hyper Estraier index from data with
27    type C<search>.
28    
29  Perhaps a little code snippet.  =head1 FUNCTIONS
30    
31      use WebPAC::Output::Estraier;  =head2 new
32    
33      my $foo = WebPAC::Output::Estraier->new();  Connect to Hyper Estraier index using HTTP
     ...  
34    
35  =head1 EXPORT   my $est = new WebPAC::Output::Estraier(
36            url => 'http://localhost:1978/node/webpac2',
37            user => 'admin',
38            passwd => 'admin',
39            database => 'demo',
40            encoding => 'iso-8859-2',
41     );
42    
43  A list of functions that can be exported.  You can delete this section  Options are:
 if you don't export anything, such as for a purely object-oriented module.  
44    
45  =head1 FUNCTIONS  =over 4
46    
47    =item url
48    
49    URI to C<estmaster> node
50    
51    =item user
52    
53    C<estmaster> user with sufficient rights
54    
55    =item passwd
56    
57    password for user
58    
59    =item database
60    
61    name of database from which data comes
62    
63    =item encoding
64    
65  =head2 function1  character encoding of C<data_structure> if it's differenet than C<ISO-8859-2>
66    (and it probably is). This encoding will be converted to C<UTF-8> for
67    Hyper Estraier.
68    
69    =back
70    
71    Name of database will be used to form URI of documents in index.
72    
73  =cut  =cut
74    
75  sub function1 {  sub new {
76            my $class = shift;
77            my $self = {@_};
78            bless($self, $class);
79    
80            my $log = $self->_get_logger;
81    
82            foreach my $p (qw/url user passwd/) {
83                    $log->logdie("need $p") unless ($self->{$p});
84            }
85    
86            $log->info("opening Hyper Estraier index $self->{'url'}");
87    
88            $self->{'db'} = HyperEstraier::Node->new($self->{'url'});
89            $self->{'db'}->set_auth($self->{'user'}, $self->{'passwd'});
90    
91            my $encoding = $self->{'encoding'} || 'ISO-8859-2';
92            $log->info("using encoding $encoding");
93    
94            $self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or
95                    $log->logdie("can't create conversion from $encoding to UTF-8");
96    
97            $self ? return $self : return undef;
98  }  }
99    
100  =head2 function2  
101    =head2 add
102    
103    Adds one entry to database.
104    
105      $est->add(
106            id => 42,
107            ds => $ds,
108            type => 'display',
109            url_prefix => 'database name',
110            text => 'optional text from which snippet is created',
111      );
112    
113    This function will create  entries in index using following URI format:
114    
115      C<file:///database%20name/000>
116    
117    Each tag in C<data_structure> with specified C<type> will create one
118    attribute and corresponding hidden text (used for search).
119    
120  =cut  =cut
121    
122  sub function2 {  sub add {
123  }          my $self = shift;
124    
125  =head1 AUTHOR          my $args = {@_};
126    
127  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>          my $log = $self->_get_logger;
128    
129            my $database = $self->{'database'} || $log->logconfess('no database in $self');
130            $log->logconfess('need db in object') unless ($self->{'db'});
131    
132            foreach my $p (qw/id ds type/) {
133                    $log->logdie("need $p") unless ($args->{$p});
134            }
135    
136            my $type = $args->{'type'};
137            my $mfn = $args->{'id'};
138    
139            my $uri = "file:///$type/$database/$mfn";
140            $log->debug("creating $uri");
141    
142            my $doc = HyperEstraier::Document->new;
143            $doc->add_attr('@uri', $self->{'iconv'}->convert($uri) );
144    
145            $log->debug("ds = ", sub { Dumper($args->{'ds'}) } );
146    
147            # filter all tags which have type defined
148            my @tags = grep {
149                    ref($args->{'ds'}->{$_}) eq 'HASH' && defined( $args->{'ds'}->{$_}->{$type} )
150            } keys %{ $args->{'ds'} };
151    
152  =head1 BUGS          $log->debug("tags = ", join(",", @tags));
153    
154  Please report any bugs or feature requests to          return unless (@tags);
 C<bug-webpac-output-estraier@rt.cpan.org>, or through the web interface at  
 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebPAC>.  
 I will be notified, and then you'll automatically be notified of progress on  
 your bug as I make changes.  
155    
156  =head1 ACKNOWLEDGEMENTS          foreach my $tag (@tags) {
157    
158                    my $vals = join(" ", @{ $args->{'ds'}->{$tag}->{$type} });
159    
160                    $log->logconfess("no values for $tag/$type") unless ($vals);
161    
162                    $vals = $self->{'iconv'}->convert( $vals ) or
163                            $log->logdie("can't convert '$vals' to UTF-8");
164    
165                    $doc->add_attr( $tag, $vals );
166                    $doc->add_hidden_text( $vals );
167            }
168    
169            my $text = $args->{'text'};
170            if ( $text ) {
171                    $text = $self->{'iconv'}->convert( $text ) or
172                            $log->logdie("can't convert '$text' to UTF-8");
173                    $doc->add_text( $text );
174            }
175    
176            $log->debug("adding ", sub { $doc->dump_draft } );
177            $self->{'db'}->put_doc($doc) || $log->logdie("can't add document $uri to index");
178    
179            return 1;
180    }
181    
182    =head1 AUTHOR
183    
184    Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
185    
186  =head1 COPYRIGHT & LICENSE  =head1 COPYRIGHT & LICENSE
187    

Legend:
Removed from v.1  
changed lines
  Added in v.113

  ViewVC Help
Powered by ViewVC 1.1.26