2 package Debbugs::Estraier;
6 Debbugs::Estraier -- Routines for interfacing bugs to HyperEstraier
10 use Debbugs::Estraier;
24 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
25 use base qw(Exporter);
27 #use Params::Validate;
30 use Debbugs::Common qw(getbuglocation getbugcomponent readbug);
34 ($VERSION) = q$Revision: 1.3 $ =~ /^Revision:\s+([^\s+])/;
35 $DEBUG = 0 unless defined $DEBUG;
38 %EXPORT_TAGS = (add => [qw(add_bug_log add_bug_message)],
41 Exporter::export_ok_tags(qw(add));
42 $EXPORT_TAGS{all} = [@EXPORT_OK];
47 my ($est,$bug_num) = @_;
49 # We want to read the entire bug log, pulling out individual
50 # messages, and shooting them through hyper estraier
52 my $location = getbuglocation($bug_num,'log');
53 my $bug_log = getbugcomponent($bug_num,'log',$location);
54 my $log_fh = new IO::File $bug_log, 'r' or
55 die "Unable to open bug log $bug_log for reading: $!";
57 my $log = Debbugs::Log->new($log_fh) or
58 die "Debbugs::Log was unable to be initialized";
63 if (my $location = getbuglocation($bug_num,'summary')) {
64 $status = readbug($bug_num,$location);
66 while (my $record = $log->read_record()) {
68 next unless $record->{type} eq 'incoming-recv';
69 my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
70 next if defined $msg_id and exists $seen_msg_ids{$msg_id};
71 $seen_msg_ids{$msg_id} = 1 if defined $msg_id;
72 next if $msg_id =~ /handler\..+\.ack(?:info)?\@/;
73 add_bug_message($est,$record->{text},$bug_num,$msg_num,$status)
78 my ($est,$bug_message,$bug_num,
79 $msg_num,$status) = @_;
82 my $uri = "$bug_num/$msg_num";
83 $doc = $est->get_doc_by_uri($uri);
84 $doc = new Search::Estraier::Document if not defined $doc;
85 $doc->add_text($bug_message);
87 # * @id : the ID number determined automatically when the document is registered.
88 # * @uri : the location of a document which any document should have.
89 # * @digest : the message digest calculated automatically when the document is registered.
90 # * @cdate : the creation date.
91 # * @mdate : the last modification date.
92 # * @adate : the last access date.
93 # * @title : the title used as a headline in the search result.
94 # * @author : the author.
95 # * @type : the media type.
96 # * @lang : the language.
97 # * @genre : the genre.
99 # * @weight : the scoring weight.
100 # * @misc : miscellaneous information.
101 my @attr = qw(status subject date submitter package tags severity);
103 my ($date) = $bug_message =~ /^Date:\s+(.+?)\s*$/mi;
104 $doc->add_attr('@cdate' => $date);
106 my ($subject) = $bug_message =~ /^Subject:\s+(.+?)\s*$/mi;
107 $doc->add_attr('@title' => $subject);
109 my ($author) = $bug_message =~ /^From:\s+(.+?)\s*$/mi;
110 $doc->add_attr('@author' => $author);
112 $doc->add_attr('@uri' => $uri);
113 foreach my $attr (@attr) {
114 $doc->add_attr($attr => $status->{$attr});
116 print STDERR "adding $uri\n" if $DEBUG;
117 # Try a bit harder if estraier is returning timeouts
119 while ($attempt > 0) {
120 $est->put_doc($doc) and last;
121 my $status = $est->status;
123 print STDERR "Failed to add $uri\n".$status."\n";
124 last unless $status =~ /^5/;