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

Legend:
Removed from v.12  
changed lines
  Added in v.19

  ViewVC Help
Powered by ViewVC 1.1.26