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

Diff of /trunk/MWS_swish.pm

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

revision 27 by dpavlin, Sat May 8 20:34:26 2004 UTC revision 30 by dpavlin, Sun May 9 00:09:32 2004 UTC
# Line 11  use SWISH::API; Line 11  use SWISH::API;
11  use Text::Iconv;  use Text::Iconv;
12  use Data::Dumper;  use Data::Dumper;
13  use File::Temp qw/ :mktemp /;  use File::Temp qw/ :mktemp /;
14    use Text::Soundex;
15    
16  my $iso2utf = Text::Iconv->new('ISO-8859-2','UTF-8');  my $iso2utf = Text::Iconv->new('ISO-8859-2','UTF-8');
17  my $utf2iso = Text::Iconv->new('UTF-8','ISO-8859-2');  my $utf2iso = Text::Iconv->new('UTF-8','ISO-8859-2');
# Line 212  sub close_index { Line 213  sub close_index {
213    
214  }  }
215    
216    # this is optional function which return words which sound like
217    sub apropos_index {
218            my $self = shift;
219    
220            my $fld = shift || croak "apropos_index need field";
221            my $words = shift || return;
222    
223            my @a;
224    
225            foreach my $word (split(/\s+/,$words)) {
226    
227                    my $hash = soundex($word);
228                    my $c = substr($word,0,1);
229    
230                    my $index = $self->open_index;
231                    my $index_file = $self->{index_dir}."/".$self->{config_name};
232    
233                    open(SWISH,"swish-e -f $index_file -k $c |") || die "can't start swish-e";
234                    my @k_arr;
235                    while(<SWISH>) {
236                            next if (/^#/);
237                            s/^.+?:\s+//;
238                            @k_arr = split(/\s+/);
239                    }
240    
241                    foreach my $k (@k_arr) {
242                            push @a, $k if (soundex($k) eq $hash);
243                    }
244            }
245    
246    #       print STDERR "apropos_index($fld,$word) [$hash]: ",join(" ",@a),"\n";
247            return @a;
248    
249    }
250    
251  1;  1;

Legend:
Removed from v.27  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26