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 |
|
# store total number of hits |
55 |
|
$self->{'total_hits'} = $results->Hits; |
56 |
|
|
57 |
my @res_ids; |
my @res_ids; |
58 |
|
|
59 |
|
my $count = 1; |
60 |
|
|
61 |
while ( my $r = $results->NextResult ) { |
while ( my $r = $results->NextResult ) { |
62 |
|
|
63 |
sub p($$) { |
sub p($$) { |
71 |
push @res_ids, $id; |
push @res_ids, $id; |
72 |
|
|
73 |
foreach my $p (qw(from to cc bcc)) { |
foreach my $p (qw(from to cc bcc)) { |
74 |
@{$self->{cache}->{$id}->{$p}} = split(/##/, p($r,$p.'_phrase')); |
@{$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 |
foreach my $p (qw(subject body date)) { |
foreach my $p (qw(subject body date)) { |
84 |
|
|
85 |
# this is redundant, but needed for templates later... |
# this is redundant, but needed for templates later... |
86 |
$self->{cache}->{$id}->{'id'} = $id; |
$self->{cache}->{$id}->{'id'} = $id; |
87 |
|
|
88 |
|
last if (++$count > $self->{max_results}); |
89 |
} |
} |
90 |
|
|
91 |
return @res_ids; |
return @res_ids; |
102 |
my $xml = qq{<message>}; |
my $xml = qq{<message>}; |
103 |
foreach my $tag (keys %$document) { |
foreach my $tag (keys %$document) { |
104 |
my $data = $document->{$tag}; |
my $data = $document->{$tag}; |
105 |
|
next if (! $data || $data eq ''); |
106 |
# save [cr/]lf before conversion to XML |
# save [cr/]lf before conversion to XML |
107 |
$data =~ s/\n\r/##lf##/gs; |
$data =~ s/\n\r/##lf##/gs; |
108 |
$data =~ s/\n/##lf##/gs; |
$data =~ s/\n/##lf##/gs; |
109 |
$xml .= "<$tag><![CDATA[".$data."]]></$tag>\n" if ($data && $data ne ''); |
$xml .= "<$tag><![CDATA[".$data."]]></$tag>\n"; |
110 |
} |
} |
111 |
$xml .= qq{</message>}; |
$xml .= qq{</message>}; |
112 |
|
|