--- trunk/MWS_swish.pm 2004/05/06 23:06:08 16 +++ trunk/MWS_swish.pm 2004/05/08 00:54:16 21 @@ -36,20 +36,35 @@ sub search_index { my $self = shift; - my $s = shift || croak "search_index needs query"; + croak "search_index needs query" if (! @_); my $index = $self->open_index; - if ($s =~ /:/) { - my ($fld,$val) = split(/:/,$s,2); - $s = "$fld=($val)"; + my $sw; + + foreach my $s (@_) { + + if ($s =~ /^\s*(\w+):(.+)\s*$/) { + $sw .= "$1=($2)"; + } else { + # and/or/not operators + $sw .= " $s "; + } } - print STDERR "swish search: $s\n"; - my $results = $index->Query($s); + print STDERR "swish search: $sw\n"; + + # convert to UTF-8 + $sw = $iso2utf->convert($sw) || $sw; + my $results = $index->Query($sw); + + # store total number of hits + $self->{'total_hits'} = $results->Hits; my @res_ids; + my $count = 1; + while ( my $r = $results->NextResult ) { sub p($$) { @@ -63,15 +78,23 @@ push @res_ids, $id; foreach my $p (qw(from to cc bcc)) { - @{$self->{cache}->{$id}->{$p}} = split(/##/, p($r,$p.'_phrase')); + @{$self->{cache}->{$id}->{$p}} = (); + foreach my $v (split(/##/, p($r,$p.'_phrase'))) { + push @{$self->{cache}->{$id}->{$p}}, $v; + $self->add_counter($p,$v); + } } foreach my $p (qw(subject body date)) { $self->{cache}->{$id}->{$p} = p($r,$p); } + $self->add_counter_calendar(p($r,'date_utime')); + # this is redundant, but needed for templates later... $self->{cache}->{$id}->{'id'} = $id; + + last if (++$count > $self->{max_results}); } return @res_ids;