/[mws]/trunk/MWS_swish.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/MWS_swish.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 13 by dpavlin, Thu May 6 16:53:40 2004 UTC revision 14 by dpavlin, Thu May 6 19:46:58 2004 UTC
# Line 8  use strict; Line 8  use strict;
8  #  #
9    
10  use SWISH::API;  use SWISH::API;
11    use Text::Iconv;
12    use Data::Dumper;
13    
14    my $iso2utf = Text::Iconv->new('ISO-8859-2','UTF-8');
15    my $utf2iso = Text::Iconv->new('UTF-8','ISO-8859-2');
16    
17  sub open_index {  sub open_index {
18          my $self = shift;          my $self = shift;
# Line 43  sub search_index { Line 48  sub search_index {
48          print STDERR "swish search: $s\n";          print STDERR "swish search: $s\n";
49          my $results = $index->Query($s);          my $results = $index->Query($s);
50    
51          my @r;          my @res_ids;
52    
53            while ( my $r = $results->NextResult ) {
54    
55          while ( my $result = $results->NextResult ) {                  sub p($$) {
56                  my $id = $result->Property( "swishdocpath" );                          my ($r,$prop) = @_;
57                  push @r, $id;                          $prop = $r->Property($prop);
58                            $prop =~ s/##lf##/\n/gs;
59                            return $utf2iso->convert($prop);
60                    }
61    
62                    my $id = p($r,"swishdocpath");
63                    push @res_ids, $id;
64    
65                  foreach my $p (qw(from to cc bcc)) {                  foreach my $p (qw(from to cc bcc)) {
66                          @{$self->{cache}->{$id}->{$p}} = split(/##/, $result->Property($p.'_phrase'));                          @{$self->{cache}->{$id}->{$p}} = split(/##/, p($r,$p.'_phrase'));
67                  }                  }
68    
69                  foreach my $p (qw(subject body date)) {                  foreach my $p (qw(subject body date)) {
70                          $self->{cache}->{$id}->{$p} = $result->Property($p);                          $self->{cache}->{$id}->{$p} = p($r,$p);
71                  }                  }
72    
                 $self->{cache}->{$id}->{'body'} =~ s/##lf##/\n/gs;  
   
73                  # this is redundant, but needed for templates later...                  # this is redundant, but needed for templates later...
74                  $self->{cache}->{$id}->{'id'} = $id;                  $self->{cache}->{$id}->{'id'} = $id;
75          }          }
76    
77          return @r;          return @res_ids;
78  }  }
79    
80  sub add_index {  sub add_index {
81          my $self = shift;          my $self = shift;
82            
83          croak("add_index is not implemented for swish!");          my $mbox_id = shift || croak "add_index needs mbox_id";
84            my $document = shift || croak "add_index needs document";
85    
86            my ($mbox,$id) = split(/\s/,$mbox_id,2);
87    
88            my $xml = qq{<message>};
89            foreach my $tag (keys %$document) {
90                    my $data = $document->{$tag};
91                    # save [cr/]lf before conversion to XML
92                    $data =~ s/\n\r/##lf##/gs;
93                    $data =~ s/\n/##lf##/gs;
94                    $xml .= "<$tag><![CDATA[".$data."]]></$tag>\n" if ($data && $data ne '');
95            }
96            $xml .= qq{</message>};
97    
98            $xml = $iso2utf->convert($xml);
99            use bytes;      # as opposed to chars
100            print "Path-Name: $mbox $id\n";
101            print "Content-Length: ".(length($xml)+1)."\n";
102            print "Document-Type: XML\n\n$xml\n";
103    
104  }  }
105    
106  sub close_index {  sub close_index {

Legend:
Removed from v.13  
changed lines
  Added in v.14

  ViewVC Help
Powered by ViewVC 1.1.26