#!/usr/bin/perl use DBI; my $searcher = "owner.manager, owner.owner, owner.man"; my $dbh = DBI->connect('DBI:mysql:db;host=localhost', 'user', 'pass') or die "Database connection: $!"; open( FILE, "< $ARGV[0]" ); my %uword = (); my %seen = (); my $count = 0; my @data; my $key; my $i = 0; while ( ) { my $line = $_; chomp ($line); my @word = split / /, $line; $count = 0; while ( $word[ $count ] ) { $word[ $count ] =~ tr/^[\-a-zA-Z]//; $word[ $count ] =~ s/\'/\\\'/g; $count++; } foreach my $string ( @word ) { if ( $uwordi{ $string }[ 0 ] == 1 ) { push @{ $uword{ $string } }, $line; next; } $uword{ $string }[ 0 ] = 1; push @{ $uword{ $string } }, $line; } } $count = 0; while ( $key = keys %uword ) { my ( $imo, $owner, $manown, $manager ); my $sstring = $uword{ $key }; my $select = qq/SELECT $searcher /; my $from = qq/FROM owner, data /; my $where = qq/WHERE MATCH( $searcher ) AGAINST('+$sstring' IN BOOLEAN MODE) /; my $join = qq/AND owner.num = data.num/; my $query = $select . $from . $where . $join; print "SQL: $query\n"; my $sth = $dbh->prepare( $query ); $sth->execute; $sth->bind_columns( \$manager, \$owner, \$man ); while ( $sth->fetch ) { if ( defined( $owner ) ) { $data[$count] = $owner; $count++; } if ( defined( $man ) ) { $data[$count] = $manown; $count++; } if ( defined( $manager ) ) { $data[$count] = $manager; $count++ } } foreach my $string ( @data ) { next if !defined ($string); if ( $seen{ $string }[ 0 ] == 1 ) { for my $value (1 .. $#{ $uword{ $string } } ) { push @{ $seen{ $string } }, $uword{ $string }[ $value ]; } next; } $seen{ $string }[ 0 ] = 1; for my $value (1 .. $#{ $uword{ $string } } ) { push @{ $seen{ $string } }, $uword{ $string }[ $value ]; } } } $dbh->disconnect;