r8988@llin: dpavlin | 2005-11-20 20:46:12 +0100
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Nov 2005 20:13:39 +0000 (20:13 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 20 Nov 2005 20:13:39 +0000 (20:13 +0000)
 added real implementation for WebPAC::Output::Estraier along with run.pl
 script which run test indexing (which will in one point move to
 WebPAC::Simple or something like that)

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@74 07558da8-63fa-0310-ba24-9fe276d99e06

Makefile.PL
conf/log.conf
conf/output/tt/html_ffzg.tt
lib/WebPAC/Normalize.pm
lib/WebPAC/Output/Estraier.pm
run.pl [new file with mode: 0755]

index 3a69c09..2bfe6bf 100644 (file)
@@ -48,6 +48,9 @@ tags:
 sf:
        svn2cvs.pl file:///home/dpavlin/private/svn/webpac2/trunk/ :ext:dpavlin@cvs.sourceforge.net:/cvsroot/webpac webpac2
 
+run:
+       rm -f ./db/*
+       ./run.pl
 
 MAKE_MORE
 }
index 10ac436..bf2f453 100644 (file)
@@ -28,6 +28,7 @@ log4perl.logger.WebPAC.DB.save_ds=DEBUG
 #log4perl.logger.WebPAC.Normalize.parse_to_arr=DEBUG
 
 #log4perl.logger.WebPAC.Output.TT=DEBUG
+log4perl.logger.WebPAC.Output.Estraier=DEBUG
 
 #log4perl.logger.WebPAC.Common=DEBUG
 
index a2b9c30..a74a861 100644 (file)
@@ -16,7 +16,7 @@
   </td>
 </tr>
 [% END %]
-
+xx
 [% IF d('CorporateName') || d('CorporateName2') %]
 <tr class="line">
   <td class="label">Ustanova</td>
index 1e21425..89df722 100644 (file)
@@ -210,7 +210,7 @@ sub data_structure {
                        }
 
                        # default types 
-                       my @types = qw(display swish);
+                       my @types = qw(display search);
                        # override by type attribute
                        @types = ( $tag->{'type'} ) if ($tag->{'type'});
 
index de27dd2..0fc5359 100644 (file)
@@ -3,9 +3,15 @@ package WebPAC::Output::Estraier;
 use warnings;
 use strict;
 
+use base qw/WebPAC::Common/;
+
+use HyperEstraier;
+use Text::Iconv;
+use Data::Dumper;
+
 =head1 NAME
 
-WebPAC::Output::Estraier - The great new WebPAC::Output::Estraier!
+WebPAC::Output::Estraier - Create Hyper Estraier full text index
 
 =head1 VERSION
 
@@ -17,49 +23,156 @@ our $VERSION = '0.01';
 
 =head1 SYNOPSIS
 
-Quick summary of what the module does.
+Create full text index using Hyper Estraier index from data with
+type C<search>.
+
+=head1 FUNCTIONS
 
-Perhaps a little code snippet.
+=head2 new
 
-    use WebPAC::Output::Estraier;
+Connect to Hyper Estraier index using HTTP
 
-    my $foo = WebPAC::Output::Estraier->new();
-    ...
+ my $est = new WebPAC::Output::Estraier(
+       url => 'http://localhost:1978/node/webpac2',
+       user => 'admin',
+       passwd => 'admin',
+       database => 'demo',
+       encoding => 'iso-8859-2',
+ );
 
-=head1 EXPORT
+Options are:
 
-A list of functions that can be exported.  You can delete this section
-if you don't export anything, such as for a purely object-oriented module.
+=over 4
 
-=head1 FUNCTIONS
+=item url
+
+URI to C<estmaster> node
+
+=item user
+
+C<estmaster> user with sufficient rights
+
+=item passwd
+
+password for user
+
+=item database
+
+name of database from which data comes
 
-=head2 function1
+=item encoding
+
+character encoding of C<data_structure> if it's differenet than C<ISO-8859-2>
+(and it probably is). This encoding will be converted to C<UTF-8> for
+Hyper Estraier.
+
+=back
+
+Name of database will be used to form URI of documents in index.
 
 =cut
 
-sub function1 {
+sub new {
+       my $class = shift;
+        my $self = {@_};
+        bless($self, $class);
+
+       my $log = $self->_get_logger;
+
+       foreach my $p (qw/url user passwd/) {
+               $log->logdie("need $p") unless ($self->{$p});
+       }
+
+       $log->info("opening Hyper Estraier index $self->{'url'}");
+
+       $self->{'db'} = HyperEstraier::Node->new($self->{'url'});
+       $self->{'db'}->set_auth($self->{'user'}, $self->{'passwd'});
+
+       my $encoding = $self->{'encoding'} || 'ISO-8859-2';
+       $log->info("using encoding $encoding");
+
+       my $iconv = new Text::Iconv('iso-8859-2', 'utf-8');
+
+       $self ? return $self : return undef;
 }
 
-=head2 function2
+=head2 add
+
+Adds one entry to database.
+
+  $est->add(
+       id => 42,
+       ds => $ds,
+       type => 'display',
+       url_prefix => 'database name',
+       text => 'optional text from which snippet is created',
+  );
+
+This function will create  entries in index using following URI format:
+
+  C<file:///database%20name/000>
+
+Each tag in C<data_structure> with specified C<type> will create one
+attribute and corresponding hidden text (used for search).
 
 =cut
 
-sub function2 {
-}
+sub add {
+       my $self = shift;
 
-=head1 AUTHOR
+        my $args = {@_};
 
-Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
+       my $log = $self->_get_logger;
+
+       my $database = $self->{'database'} || $log->logconfess('no database in $self');
+       $log->logconfess('need db in object') unless ($self->{'db'});
+
+       foreach my $p (qw/id ds type/) {
+               $log->logdie("need $p") unless ($args->{$p});
+       }
+
+       my $type = $args->{'type'};
+       my $mfn = $args->{'id'};
+
+       my $uri = "file:///$type/$database/$mfn";
+       $log->debug("creating $uri");
+
+       my $doc = HyperEstraier::Document->new;
+       $doc->add_attr('@uri', $uri);
+
+       $log->debug("ds = ", sub { Dumper($args->{'ds'}) } );
 
-=head1 BUGS
+       # filter all tags which have type defined
+       my @tags = grep {
+               defined( $args->{'ds'}->{$_}->{$type} )
+       } keys %{ $args->{'ds'} };
 
-Please report any bugs or feature requests to
-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.
+       $log->debug("tags = ", join(",", @tags));
 
-=head1 ACKNOWLEDGEMENTS
+       return unless (@tags);
+
+       foreach my $tag (@tags) {
+
+               my $vals = join(" ", @{ $args->{'ds'}->{$tag}->{$type} });
+
+               $log->logconfess("no values for $tag/$type") unless ($vals);
+
+               $doc->add_attr($tag, $vals);
+               $doc->add_hidden_text($vals);
+       }
+
+       my $text = $args->{'text'};
+       $doc->add_text( $text ) if ( $text );
+
+       $log->debug("adding ", sub { $doc->dump_draft } );
+       $self->{'db'}->put_doc($doc) || $log->die("can't add document $uri to index");
+
+       return 1;
+}
+
+=head1 AUTHOR
+
+Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
 
 =head1 COPYRIGHT & LICENSE
 
diff --git a/run.pl b/run.pl
new file mode 100755 (executable)
index 0000000..be7b5f6
--- /dev/null
+++ b/run.pl
@@ -0,0 +1,96 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Cwd qw/abs_path/;
+use File::Temp qw/tempdir/;
+use Data::Dumper;
+use lib './lib';
+
+use WebPAC::Lookup;
+use WebPAC::Input::ISIS;
+use WebPAC::DB;
+use WebPAC::Normalize::XML;
+use WebPAC::Output::TT;
+use WebPAC::Output::Estraier;
+
+my $abs_path = abs_path($0);
+$abs_path =~ s#/[^/]*$#/#;
+
+my $isis_file = '/data/isis_data/ps/LIBRI/LIBRI';
+
+my $lookup = new WebPAC::Lookup(
+       lookup_file => "$abs_path/conf/lookup/isis.pm",
+);
+
+my $isis = new WebPAC::Input::ISIS(
+       code_page => 'ISO-8859-2',      # application encoding
+       limit_mfn => 50,
+);
+
+my $maxmfn = $isis->open(
+       filename => $isis_file,
+       code_page => '852',             # database encoding
+);
+
+my $path = './db/';
+
+my $db = new WebPAC::DB(
+       path => $path,
+);
+
+my $n = new WebPAC::Normalize::XML(
+#      filter => { 'foo' => sub { shift } },
+       db => $db,
+       lookup_regex => $lookup->regex,
+       lookup => $lookup,
+);
+
+$n->open(
+       tag => 'isis',
+       xml_file => "$abs_path/conf/normalize/isis_ffzg.xml",
+);
+
+my $out = new WebPAC::Output::TT(
+       include_path => "$abs_path/conf/output/tt",
+       filters => { foo => sub { shift } },
+);
+
+my $est = new WebPAC::Output::Estraier(
+       url => 'http://localhost:1978/node/webpac2',
+       user => 'admin',
+       passwd => 'admin',
+       database => 'ps',
+);
+
+while (my $row = $isis->fetch) {
+
+       my $mfn = $row->{'000'}->[0] || die "can't find MFN";
+
+       my $ds = $n->data_structure($row);
+
+#      print STDERR Dumper($row, $ds);
+
+       my $html = $out->apply(
+               template => 'html_ffzg.tt',
+               data => $ds,
+       );
+
+       # create test output
+
+       my $file = sprintf('out/%02d.html', $mfn );
+       open(my $fh, '>', $file) or die "can't open $file: $!";
+       print $fh $html;
+       close($fh);
+
+       $html =~ s#\s*[\n\r]+\s*##gs;
+
+#      print STDERR $html;
+
+       $est->add(
+               id => $mfn,
+               ds => $ds,
+               type => 'search',
+       );
+
+};