1 package WebPAC::Output::Estraier;
6 use base qw/WebPAC::Common/;
14 WebPAC::Output::Estraier - Create Hyper Estraier full text index
22 our $VERSION = '0.01';
26 Create full text index using Hyper Estraier index from data with
33 Connect to Hyper Estraier index using HTTP
35 my $est = new WebPAC::Output::Estraier(
36 url => 'http://localhost:1978/node/webpac2',
40 encoding => 'iso-8859-2',
49 URI to C<estmaster> node
53 C<estmaster> user with sufficient rights
61 name of database from which data comes
65 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
71 Name of database will be used to form URI of documents in index.
80 my $log = $self->_get_logger;
82 foreach my $p (qw/url user passwd/) {
83 $log->logdie("need $p") unless ($self->{$p});
86 $log->info("opening Hyper Estraier index $self->{'url'}");
88 $self->{'db'} = HyperEstraier::Node->new($self->{'url'});
89 $self->{'db'}->set_auth($self->{'user'}, $self->{'passwd'});
91 my $encoding = $self->{'encoding'} || 'ISO-8859-2';
92 $log->info("using encoding $encoding");
94 my $iconv = new Text::Iconv('iso-8859-2', 'utf-8');
96 $self ? return $self : return undef;
101 Adds one entry to database.
107 url_prefix => 'database name',
108 text => 'optional text from which snippet is created',
111 This function will create entries in index using following URI format:
113 C<file:///database%20name/000>
115 Each tag in C<data_structure> with specified C<type> will create one
116 attribute and corresponding hidden text (used for search).
125 my $log = $self->_get_logger;
127 my $database = $self->{'database'} || $log->logconfess('no database in $self');
128 $log->logconfess('need db in object') unless ($self->{'db'});
130 foreach my $p (qw/id ds type/) {
131 $log->logdie("need $p") unless ($args->{$p});
134 my $type = $args->{'type'};
135 my $mfn = $args->{'id'};
137 my $uri = "file:///$type/$database/$mfn";
138 $log->debug("creating $uri");
140 my $doc = HyperEstraier::Document->new;
141 $doc->add_attr('@uri', $uri);
143 $log->debug("ds = ", sub { Dumper($args->{'ds'}) } );
145 # filter all tags which have type defined
147 defined( $args->{'ds'}->{$_}->{$type} )
148 } keys %{ $args->{'ds'} };
150 $log->debug("tags = ", join(",", @tags));
152 return unless (@tags);
154 foreach my $tag (@tags) {
156 my $vals = join(" ", @{ $args->{'ds'}->{$tag}->{$type} });
158 $log->logconfess("no values for $tag/$type") unless ($vals);
160 $doc->add_attr($tag, $vals);
161 $doc->add_hidden_text($vals);
164 my $text = $args->{'text'};
165 $doc->add_text( $text ) if ( $text );
167 $log->debug("adding ", sub { $doc->dump_draft } );
168 $self->{'db'}->put_doc($doc) || $log->die("can't add document $uri to index");
175 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
177 =head1 COPYRIGHT & LICENSE
179 Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
181 This program is free software; you can redistribute it and/or modify it
182 under the same terms as Perl itself.
186 1; # End of WebPAC::Output::Estraier