1 package BackupPC::Search::Estraier;
5 use Search::Estraier 0.04;
6 use Data::Dump qw(dump);
8 my $debug = $ENV{DEBUG} || 0;
14 my $index_node_url = $Conf{HyperEstraierIndex} || die "no HyperEstraierIndex in config ",dump(%Conf);
16 warn "# using $index_node_url";
19 node => Search::Estraier::Node->new(
20 url => $index_node_url,
29 sub node { $_[0]->{node} };
32 my ( $self, $row ) = @_;
34 my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
35 my $id = $self->node->uri_to_id($uri);
36 return $id && $id != -1;
40 my ( $self, $row ) = @_;
42 # create a document object
43 my $doc = Search::Estraier::Document->new;
45 my $uri = $row->{hname} . ':' . $row->{sname} . '#' . $row->{backupnum} . ' ' . $row->{filepath};
46 # add attributes to the document object
47 $doc->add_attr('@uri', $uri);
49 foreach my $c (keys %$row) {
50 print STDERR "attr $c = $row->{$c}\n" if ($debug > 2);
51 $doc->add_attr($c, $row->{$c}) if defined($row->{$c});
54 #$doc->add_attr('@cdate', fmt_date($row->{'date'}));
56 # add the body text to the document object
57 my $path = $row->{'filepath'};
58 $doc->add_text($path);
60 $doc->add_hidden_text($path);
62 print STDERR $doc->dump_draft,"\n" if ($debug > 1);
64 # register the document object to the database
65 $self->node->put_doc($doc);
71 warn "# commit not needed";
75 share_d => 'sname STRD',
76 share_a => 'sname STRA',
77 path_d => 'filepath STRD',
78 path_a => 'filepath STRA',
79 num_d => 'backupnum NUMD',
80 num_a => 'backupnum NUMA',
81 size_d => 'size NUMD',
82 size_a => 'size NUMA',
83 date_d => 'date NUMD',
84 date_a => 'date NUMA',
88 my ( $self, $offset, $on_page, $sort, $q, $shareid, $backup_from, $backup_to, $files_from, $files_to ) = @_;
90 warn "# search $offset/$on_page [$q] shareid: $shareid backup: $backup_from - $backup_to files: $files_from - $files_to";
92 # create a search condition object
93 my $cond = Search::Estraier::Condition->new();
97 $cond->add_attr("filepath ISTRINC $q");
100 # set the search phrase to the search condition object
101 $cond->set_phrase($q);
104 $cond->add_attr("backup_date NUMGE $backup_from") if ($backup_from);
105 $cond->add_attr("backup_date NUMLE $backup_to") if ($backup_to);
107 $cond->add_attr("date NUMGE $files_from") if ($files_from);
108 $cond->add_attr("date NUMLE $files_to") if ($files_to);
110 $cond->add_attr("shareid NUMEQ $shareid") if ($shareid);
112 $cond->set_max( $offset + $on_page );
113 $cond->set_options( 'SURE' );
114 $cond->set_order( $sort_mapping->{$sort} );
116 # get the result of search
120 $result = $self->node->search($cond, 0);
122 $hits = $result->hits;
127 # for each document in result
128 for my $i ($offset .. ($offset + $on_page - 1)) {
129 last if ($i >= $result->doc_num);
131 my $doc = $result->get_doc($i);
134 foreach my $c (qw/fid hname sname backupnum filepath date type size/) {
135 $row->{$c} = $doc->attr($c);
142 return ($hits, \@res);