begin split of full-text into own module
[BackupPC.git] / lib / BackupPC / Search / Estraier.pm
1 package BackupPC::Search::Estraier;
2 use warnings;
3 use strict;
4
5 use Search::Estraier;
6
7 my $debug = $ENV{DEBUG} || 0;
8
9 sub new {
10         my ( $class, $index_node_url ) = @_;
11
12         warn "# using $index_node_url";
13
14         my $self = bless {
15                 node => Search::Estraier::Node->new(
16                         url => $index_node_url,
17                         user => 'admin',
18                         passwd => 'admin',
19                         croak_on_error => 1,
20                 ),
21         }, $class;
22         return $self;
23 }
24
25 sub node { $_[0]->{node} };
26
27 sub exists {
28         my ( $self, $row ) = @_;
29
30         my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
31         my $id = $self->node->uri_to_id($uri);
32         return $id && $id != -1;
33 }
34
35 sub add_doc {
36         my ( $self, $row ) = @_;
37
38         # create a document object 
39         my $doc = Search::Estraier::Document->new;
40
41         my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
42         # add attributes to the document object 
43         $doc->add_attr('@uri', $uri);
44
45         foreach my $c (keys %$row) {
46                 print STDERR "attr $c = $row->{$c}\n" if ($debug > 2);
47                 $doc->add_attr($c, $row->{$c}) if defined($row->{$c});
48         }
49
50         #$doc->add_attr('@cdate', fmt_date($row->{'date'}));
51
52         # add the body text to the document object 
53         my $path = $row->{'filepath'};
54         $doc->add_text($path);
55         $path =~ s/(.)/$1 /g;
56         $doc->add_hidden_text($path);
57
58         print STDERR $doc->dump_draft,"\n" if ($debug > 1);
59
60         # register the document object to the database
61         $self->node->put_doc($doc);
62
63 }
64
65 sub commit {
66         my $self = shift;
67         warn "# commit not needed";
68 }
69
70 1;