1 package WebPAC::Output::Estraier;
6 use base qw/WebPAC::Common/;
8 use Search::Estraier 0.06;
9 use Encode qw/from_to/;
10 use Data::Dump qw/dump/;
13 use List::Util qw/first/;
17 WebPAC::Output::Estraier - Create Hyper Estraier full text index
25 our $VERSION = '0.12';
29 Create full text index using Hyper Estraier index from data with
36 Connect to Hyper Estraier index using HTTP
38 my $est = new WebPAC::Output::Estraier(
39 masterurl => 'http://localhost:1978/',
43 label => 'node label',
44 encoding => 'iso-8859-2',
54 URI to C<estmaster> node
58 C<estmaster> user with sufficient rights
66 name of database from which data comes
70 label for node (optional)
74 character encoding of C<data_structure> if it's differenet than C<ISO-8859-2>
75 (and it probably is). This encoding will be converted to C<UTF-8> for
80 Name of database will be used to form URI of documents in index.
89 my $log = $self->_get_logger;
91 #$log->debug("self: ", sub { dump($self) });
93 foreach my $p (qw/masterurl user passwd database/) {
94 $log->logdie("need $p") unless ($self->{$p});
97 $self->{encoding} ||= 'ISO-8859-2';
99 my $url = $self->{masterurl} . '/node/' . $self->{database};
102 $self->{label} ||= "WebPAC $self->{database}";
104 $self->{db} = Search::Estraier::Node->new(
106 user => $self->{user},
107 passwd => $self->{passwd},
108 debug => $self->{debug},
110 label => $self->convert( $self->{label} ),
113 $log->info("using ", $self->{clean} ? "new " : "", "index $self->{url} '$self->{label}' with encoding $self->{encoding}");
115 if ($self->{clean}) {
116 $log->debug("clean $self->{database}");
117 $self->master( action => 'nodeclr', name => $self->{database} );
119 $log->debug("opening index $self->{url}");
122 $self ? return $self : return undef;
128 Adds one entry to database.
134 text => 'optional text from which snippet is created',
137 This function will create entries in index using following URI format:
139 C<file:///type/database%20name/000>
141 Each tag in C<data_structure> with specified C<type> will create one
142 attribute and corresponding hidden text (used for search).
151 my $log = $self->_get_logger;
153 my $database = $self->{'database'} || $log->logconfess('no database in $self');
154 $log->logconfess('need db in object') unless ($self->{'db'});
156 foreach my $p (qw/id ds type/) {
157 $log->logdie("need $p") unless ($args->{$p});
160 my $type = $args->{'type'};
161 my $id = $args->{'id'};
163 my $uri = "file:///$type/$database/$id";
164 $log->debug("creating $uri");
166 my $doc = Search::Estraier::Document->new;
167 $doc->add_attr('@uri', $self->convert($uri) );
169 $log->debug("ds = ", sub { dump($args->{'ds'}) } );
171 # filter all tags which have type defined
173 ref($args->{'ds'}->{$_}) eq 'HASH' && defined( $args->{'ds'}->{$_}->{$type} )
174 } keys %{ $args->{'ds'} };
176 $log->debug("tags = ", join(",", @tags));
178 return unless (@tags);
180 foreach my $tag (@tags) {
182 my $vals = join(" ", @{ $args->{'ds'}->{$tag}->{$type} });
186 $vals = $self->convert( $vals ) or
187 $log->logdie("can't convert '$vals' to UTF-8");
189 $doc->add_attr( $tag, $vals );
190 $doc->add_hidden_text( $vals );
193 my $text = $args->{'text'};
195 $text = $self->convert( $text ) or
196 $log->logdie("can't convert '$text' to UTF-8");
197 $doc->add_text( $text );
200 $log->debug("adding ", sub { $doc->dump_draft } );
201 $self->{'db'}->put_doc($doc) || $log->warn("can't add document $uri with draft " . $doc->dump_draft . " to node " . $self->{url} . " status: " . $self->{db}->status());
220 my $log = $self->_get_logger;
222 foreach my $p (qw/from to credit/) {
223 $log->logdie("need $p") unless ($args->{$p});
226 my $node = first { $_->{name} eq $args->{to} } $self->master( action => 'nodelist' );
229 $log->warn("can't find node $args->{to}, skipping link creaton");
233 my $label = $node->{label};
236 $log->warn("can't find label for $args->{to}, skipping link creaton");
240 $log->debug("using label $label for $args->{to}");
242 return $self->{db}->set_link(
243 $self->{masterurl} . '/node/' . $args->{to},
252 Issue administrative commands to C<estmaster> process. See documentation for
253 C<master> in L<Search::Estraier>::Node.
264 $self->{db}->master( @_ );
270 my $utf8_string = $self->convert('string in codepage');
277 my $text = shift || return;
278 from_to($text, $self->{encoding}, 'UTF-8');
284 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
286 =head1 COPYRIGHT & LICENSE
288 Copyright 2005 Dobrica Pavlinusic, All Rights Reserved.
290 This program is free software; you can redistribute it and/or modify it
291 under the same terms as Perl itself.
295 1; # End of WebPAC::Output::Estraier