/[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 73 by dpavlin, Sat Jun 25 20:23:23 2005 UTC revision 74 by dpavlin, Sun Nov 20 20:13:39 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    =head1 FUNCTIONS
30    
31  Perhaps a little code snippet.  =head2 new
32    
33      use WebPAC::Output::Estraier;  Connect to Hyper Estraier index using HTTP
34    
35      my $foo = WebPAC::Output::Estraier->new();   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  =head1 EXPORT  Options are:
44    
45  A list of functions that can be exported.  You can delete this section  =over 4
 if you don't export anything, such as for a purely object-oriented module.  
46    
47  =head1 FUNCTIONS  =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  =head2 function1  =item encoding
64    
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
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            my $iconv = new Text::Iconv('iso-8859-2', 'utf-8');
95    
96            $self ? return $self : return undef;
97  }  }
98    
99  =head2 function2  =head2 add
100    
101    Adds one entry to database.
102    
103      $est->add(
104            id => 42,
105            ds => $ds,
106            type => 'display',
107            url_prefix => 'database name',
108            text => 'optional text from which snippet is created',
109      );
110    
111    This function will create  entries in index using following URI format:
112    
113      C<file:///database%20name/000>
114    
115    Each tag in C<data_structure> with specified C<type> will create one
116    attribute and corresponding hidden text (used for search).
117    
118  =cut  =cut
119    
120  sub function2 {  sub add {
121  }          my $self = shift;
122    
123  =head1 AUTHOR          my $args = {@_};
124    
125  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>          my $log = $self->_get_logger;
126    
127            my $database = $self->{'database'} || $log->logconfess('no database in $self');
128            $log->logconfess('need db in object') unless ($self->{'db'});
129    
130            foreach my $p (qw/id ds type/) {
131                    $log->logdie("need $p") unless ($args->{$p});
132            }
133    
134            my $type = $args->{'type'};
135            my $mfn = $args->{'id'};
136    
137            my $uri = "file:///$type/$database/$mfn";
138            $log->debug("creating $uri");
139    
140            my $doc = HyperEstraier::Document->new;
141            $doc->add_attr('@uri', $uri);
142    
143            $log->debug("ds = ", sub { Dumper($args->{'ds'}) } );
144    
145  =head1 BUGS          # filter all tags which have type defined
146            my @tags = grep {
147                    defined( $args->{'ds'}->{$_}->{$type} )
148            } keys %{ $args->{'ds'} };
149    
150  Please report any bugs or feature requests to          $log->debug("tags = ", join(",", @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.  
151    
152  =head1 ACKNOWLEDGEMENTS          return unless (@tags);
153    
154            foreach my $tag (@tags) {
155    
156                    my $vals = join(" ", @{ $args->{'ds'}->{$tag}->{$type} });
157    
158                    $log->logconfess("no values for $tag/$type") unless ($vals);
159    
160                    $doc->add_attr($tag, $vals);
161                    $doc->add_hidden_text($vals);
162            }
163    
164            my $text = $args->{'text'};
165            $doc->add_text( $text ) if ( $text );
166    
167            $log->debug("adding ", sub { $doc->dump_draft } );
168            $self->{'db'}->put_doc($doc) || $log->die("can't add document $uri to index");
169    
170            return 1;
171    }
172    
173    =head1 AUTHOR
174    
175    Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
176    
177  =head1 COPYRIGHT & LICENSE  =head1 COPYRIGHT & LICENSE
178    

Legend:
Removed from v.73  
changed lines
  Added in v.74

  ViewVC Help
Powered by ViewVC 1.1.26