/[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 20 by dpavlin, Fri May 7 23:35:39 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    
73          # convert to UTF-8          # convert to UTF-8
74          $s = $iso2utf->convert($s) || $s;          $sw = $iso2utf->convert($sw) || $sw;
75          my $results = $index->Query($s);  
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          # store total number of hits
81          $self->{'total_hits'} = $results->Hits;          $self->{'total_hits'} = $results->Hits;
# Line 78  sub search_index { Line 104  sub search_index {
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    

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

  ViewVC Help
Powered by ViewVC 1.1.26