/[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 17 by dpavlin, Fri May 7 11:25:01 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;          # store total number of hits
52            $self->{'total_hits'} = $results->Hits;
53    
54            my @res_ids;
55    
56          while ( my $result = $results->NextResult ) {          my $count = 0;
                 my $id = $result->Property( "swishdocpath" );  
                 push @r, $id;  
57    
58            while ( my $r = $results->NextResult ) {
59    
60                    sub p($$) {
61                            my ($r,$prop) = @_;
62                            $prop = $r->Property($prop);
63                            $prop =~ s/##lf##/\n/gs;
64                            return $utf2iso->convert($prop);
65                    }
66    
67                    my $id = p($r,"swishdocpath");
68                    push @res_ids, $id;
69    
70                  foreach my $p (qw(from to cc bcc)) {                  foreach my $p (qw(from to cc bcc)) {
71                          @{$self->{cache}->{$id}->{$p}} = split(/##/, $result->Property($p.'_phrase'));                          @{$self->{cache}->{$id}->{$p}} = split(/##/, p($r,$p.'_phrase'));
72                  }                  }
73    
74                  foreach my $p (qw(subject body date)) {                  foreach my $p (qw(subject body date)) {
75                          $self->{cache}->{$id}->{$p} = $result->Property($p);                          $self->{cache}->{$id}->{$p} = p($r,$p);
76                  }                  }
77    
                 $self->{cache}->{$id}->{'body'} =~ s/##lf##/\n/gs;  
   
78                  # this is redundant, but needed for templates later...                  # this is redundant, but needed for templates later...
79                  $self->{cache}->{$id}->{'id'} = $id;                  $self->{cache}->{$id}->{'id'} = $id;
80    
81                    last if ($count++ > $self->{max_results});
82          }          }
83    
84          return @r;          return @res_ids;
85  }  }
86    
87  sub add_index {  sub add_index {
88          my $self = shift;          my $self = shift;
89            
90          croak("add_index is not implemented for swish!");          my $mbox_id = shift || croak "add_index needs mbox_id";
91            my $document = shift || croak "add_index needs document";
92    
93            my ($mbox,$id) = split(/\s/,$mbox_id,2);
94    
95            my $xml = qq{<message>};
96            foreach my $tag (keys %$document) {
97                    my $data = $document->{$tag};
98                    next if (! $data || $data eq '');
99                    # save [cr/]lf before conversion to XML
100                    $data =~ s/\n\r/##lf##/gs;
101                    $data =~ s/\n/##lf##/gs;
102                    $xml .= "<$tag><![CDATA[".$data."]]></$tag>\n";
103            }
104            $xml .= qq{</message>};
105    
106            $xml = $iso2utf->convert($xml);
107            use bytes;      # as opposed to chars
108            print "Path-Name: $mbox $id\n";
109            print "Content-Length: ".(length($xml)+1)."\n";
110            print "Document-Type: XML\n\n$xml\n";
111    
112  }  }
113    
114  sub close_index {  sub close_index {

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

  ViewVC Help
Powered by ViewVC 1.1.26