/[mws]/trunk/lib/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/lib/MWS/SWISH.pm

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

revision 16 by dpavlin, Thu May 6 23:06:08 2004 UTC revision 24 by dpavlin, Sat May 8 14:27:54 2004 UTC
# Line 36  sub open_index { Line 36  sub open_index {
36  sub search_index {  sub search_index {
37          my $self = shift;          my $self = shift;
38    
39          my $s = shift || croak "search_index needs query";          croak "search_index needs query" if (! @_);
40    
41          my $index = $self->open_index;          my $index = $self->open_index;
42    
43          if ($s =~ /:/) {          my $sw;
44                  my ($fld,$val) = split(/:/,$s,2);  
45                  $s = "$fld=($val)";          my $sort_map = {
46                    'date' => 'date_utime',
47                    'from' => 'from_phrase',
48                    'to' => 'to_phrase',
49                    'rank' => 'swishrank',
50            };
51    
52            my $sort_by;
53    
54            foreach my $s (@_) {
55    
56                    if ($s =~ /^\s*(\w+):(.+)\s*$/) {
57                            my ($f,$v) = ($1,$2);
58                            if (lc($f) eq "sort") {
59                                    my ($sf,$sv) = split(/ /,$v,2);
60                                    $sort_by = $sort_map->{$sf} || croak "unsupported sort by field $v - fix sort_map";
61                                    $sort_by .= " $sv";
62                            } else {
63                                    $sw .= "$f=($v)";
64                            }
65                    } else {
66                            # and/or/not operators
67                            $sw .= " $s ";
68                    }
69          }          }
70    
71          print STDERR "swish search: $s\n";          print STDERR "swish search: $sw\n";
72          my $results = $index->Query($s);  
73            # convert to UTF-8
74            $sw = $iso2utf->convert($sw) || $sw;
75    
76            my $search = $index->New_Search_Object;
77            $search->SetSort( $sort_by );
78            my $results = $search->Execute($sw);
79    
80            # store total number of hits
81            $self->{'total_hits'} = $results->Hits;
82    
83          my @res_ids;          my @res_ids;
84    
85            my $count = 1;
86    
87          while ( my $r = $results->NextResult ) {          while ( my $r = $results->NextResult ) {
88    
89                  sub p($$) {                  sub p($$) {
# Line 63  sub search_index { Line 97  sub search_index {
97                  push @res_ids, $id;                  push @res_ids, $id;
98    
99                  foreach my $p (qw(from to cc bcc)) {                  foreach my $p (qw(from to cc bcc)) {
100                          @{$self->{cache}->{$id}->{$p}} = split(/##/, p($r,$p.'_phrase'));                          @{$self->{cache}->{$id}->{$p}} = ();
101                            foreach my $v (split(/##/, p($r,$p.'_phrase'))) {
102                                    push @{$self->{cache}->{$id}->{$p}}, $v;
103                                    $self->add_counter($p,$v);
104                            }
105                  }                  }
106    
107                  foreach my $p (qw(subject body date)) {                  foreach my $p (qw(subject body date date_utime)) {
108                          $self->{cache}->{$id}->{$p} = p($r,$p);                          $self->{cache}->{$id}->{$p} = p($r,$p);
109                  }                  }
110    
111                    $self->add_counter_calendar(p($r,'date_utime'));
112    
113                  # this is redundant, but needed for templates later...                  # this is redundant, but needed for templates later...
114                  $self->{cache}->{$id}->{'id'} = $id;                  $self->{cache}->{$id}->{'id'} = $id;
115    
116                    last if (++$count > $self->{max_results});
117          }          }
118    
119          return @res_ids;          return @res_ids;

Legend:
Removed from v.16  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26