/[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

Contents of /trunk/MWS_swish.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 13 - (show annotations)
Thu May 6 16:53:40 2004 UTC (20 years ago) by dpavlin
File size: 1453 byte(s)
partial implementation for dates, more verbose debugging, index should now
return all fields writen in it (this will break Plucene code, so it's
non-function from now on)

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 #
6 # simple implementation to use SWISH-e with queryies like
7 # Lucene (subject:something)
8 #
9
10 use SWISH::API;
11
12 sub open_index {
13 my $self = shift;
14
15 my $swish = $self->{index};
16
17 if (! $swish) {
18
19 my $index_file = $self->{index_file} || croak "open_index needs index filename";
20 $index_file .= "/swish-e";
21 print STDERR "opening index '$index_file'\n";
22 $swish = SWISH::API->new($index_file);
23 $swish->AbortLastError if $swish->Error;
24
25 $self->{index} = $swish;
26 }
27
28 return $swish;
29 }
30
31 sub search_index {
32 my $self = shift;
33
34 my $s = shift || croak "search_index needs query";
35
36 my $index = $self->open_index;
37
38 if ($s =~ /:/) {
39 my ($fld,$val) = split(/:/,$s,2);
40 $s = "$fld=($val)";
41 }
42
43 print STDERR "swish search: $s\n";
44 my $results = $index->Query($s);
45
46 my @r;
47
48 while ( my $result = $results->NextResult ) {
49 my $id = $result->Property( "swishdocpath" );
50 push @r, $id;
51
52
53 foreach my $p (qw(from to cc bcc)) {
54 @{$self->{cache}->{$id}->{$p}} = split(/##/, $result->Property($p.'_phrase'));
55 }
56
57 foreach my $p (qw(subject body date)) {
58 $self->{cache}->{$id}->{$p} = $result->Property($p);
59 }
60
61 $self->{cache}->{$id}->{'body'} =~ s/##lf##/\n/gs;
62
63 # this is redundant, but needed for templates later...
64 $self->{cache}->{$id}->{'id'} = $id;
65 }
66
67 return @r;
68 }
69
70 sub add_index {
71 my $self = shift;
72
73 croak("add_index is not implemented for swish!");
74 }
75
76 sub close_index {
77 my $self = shift;
78
79 }
80
81 1;

  ViewVC Help
Powered by ViewVC 1.1.26