--- trunk/MWS.pm 2004/05/07 12:41:16 18 +++ trunk/MWS.pm 2004/05/07 20:52:34 19 @@ -11,6 +11,7 @@ use POSIX qw(strftime); use Text::Autoformat; use Text::Iconv; +use Text::Unaccent; #use MWS_plucene; use MWS_swish; @@ -48,10 +49,55 @@ $self->{wrap_margin} = $self->{config}->val('global', 'wrap_margin'); $self->{max_results} = $self->{config}->val('global', 'max_results') || 100; + $self->reset_counters; return $self; } +sub normalize_string { + my $self = shift; + + my $v = shift || return; + + $v = unac_string('ISO-8859-2', $v); + $v = join('',sort split(/\s+/,$v)); + $v =~ s/\W+//g; + + return $v; +} + +# reset tables for search results +sub reset_counters { + my $self = shift; + + $self->{counter} = {}; + +# foreach my $c (qw(thread from to cc bcc lists links att)) { +# $self->{counter}->{$c} = {}; +# } + +} + +sub add_counter($$) { + my $self = shift; + + my ($c,$v) = @_; + my $k = $self->normalize_string($v); + + $self->{counter}->{$c}->{$k}->{name} = $v; + return $self->{counter}->{$c}->{$k}->{usage}++; +} + +sub counter { + my $self = shift; + + my $c = shift || return; + + return if (! $self->{counter}->{$c}); + + return $self->{counter}->{$c}; +} + sub mbox_name2path { my $self = shift; @@ -122,6 +168,8 @@ my $s = shift || carp "search called without argument!"; + $self->reset_counters; + print STDERR "search_index($s)\n" if ($debug == 2); my @index_ids = $self->search_index($s); @@ -191,6 +239,7 @@ push @arr, $self->fetch_result_by_id($id); } + return @arr; } @@ -253,9 +302,13 @@ my $message = $self->fetch_message($id) || return; $row->{'id'} = $id; - @{$row->{'from'}} = $self->unroll($message,'from','phrase'); - @{$row->{'to'}} = $self->unroll($message,'to','phrase'); - @{$row->{'cc'}} = $self->unroll($message,'cc','phrase'); + + foreach my $p (qw(from to cc bcc)) { + foreach my $v ($self->unroll($message,'from','phrase')) { + push @{$row->{$p}},$v; + $self->add_counter($p,$v); + } + } $row->{'subject'} = $self->decode_qp($message->subject); $row->{'body'} = $self->plain_text_body($message); $row->{'date'} = $message->date;