[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/perl 2 3 use strict; 4 use Search::OpenFTS; 5 use locale; 6 use DBI(); 7 use DBD::Pg(); 8 use Getopt::Std; 9 use Time::HiRes qw( usleep ualarm gettimeofday tv_interval ); 10 11 my %opt; 12 getopts('b:l:p:vqedz', \%opt); 13 14 if ( $#ARGV<0 || ! $opt{p} ) { 15 print "Usage\n"; 16 print "$0 -p DATABASE [-b count] [ -v ] [ -l ] [ -q | -d ] [ -e ] WORD1 [ WORD2 [...] ]\n"; 17 print "\t-b count\tbenchmark\n"; 18 print "\t-v\t\tverbose\n"; 19 print "\t-q\t\tquiet\n"; 20 print "\t-d\t\tdetailed view\n"; 21 print "\t-l\t\tlimit frequency\n"; 22 print "\t-e\t\texplain\n"; 23 exit; 24 } 25 26 my $dbi=DBI->connect('DBI:Pg:dbname='.$opt{p}.';host=sp',"sp"); 27 $dbi||die; 28 29 my %ofts; 30 if ( defined $opt{l} ) { 31 $ofts{limit_freq}=$opt{l}; 32 } 33 34 my $fts=Search::OpenFTS->new( $dbi, %ofts ); 35 die $@ if ! $fts; 36 37 if ( $opt{v} ) { 38 print $fts->_sql( \@ARGV ),"\n"; 39 } 40 if ( $opt{e} ) { 41 my $sql = $fts->_sql( \@ARGV ); 42 if ( length $sql ) { 43 $dbi->do("explain $sql" ); 44 } else { 45 print "No SQL\n"; 46 } 47 } 48 49 if ( $opt{d} ) { 50 my ($out, $tables, $condition, $order) = $fts->get_sql( \@ARGV ); 51 print "$out ,\n $tables ,\n $condition ,\n $order \n"; 52 my $sql=" 53 select 54 txt.tid, 55 txt.txt, 56 $out 57 from 58 txt$tables 59 where 60 $condition 61 order by $order;"; 62 foreach ( exec_sql( $dbi, $sql ) ) { 63 print "---------------------------------------------------\n"; 64 print "TID: $_->{tid}\tpos: $_->{pos}\n$_->{txt}"; 65 } 66 } 67 #elsif ( ! $opt{q} ) { 68 # my $a=$fts->search( \@ARGV ); 69 # print join(";", @$a),"\n" if ref $a; 70 #} 71 72 73 if ( $opt{z} ) { 74 my ($out, $tables, $condition, $order) = $fts->get_sql( \@ARGV ); 75 print "$out ||| $tables ||| $condition ||| $order \n"; 76 } 77 78 #ÐÏÔÅÓÔÉÒÕÅÍ ÎÁ ÓËÏÒÏÓÔØ 79 if ( $opt{b} ) { 80 print "Speed gun in use :)...\n" if ! $opt{q}; 81 my $t0 = [gettimeofday]; 82 my $count=0; 83 foreach ( 1..$opt{b} ) { 84 my $a=$fts->search( \@ARGV ); 85 $count=$#{$a}; 86 } 87 my $elapsed = tv_interval ( $t0, [gettimeofday]); 88 print "Done\n"; 89 print sprintf("total: %.02f sec; number: %d; for one: %.03f sec; found %d docs\n", $elapsed, $opt{b}, $elapsed/$opt{b}, $count+1 ); 90 } 91 $dbi -> disconnect; 92 93 sub exec_sql { 94 my ($dbi, $sql, @keys) = @_; 95 my $sth=$dbi->prepare($sql) || die; 96 $sth->execute( @keys ) || die; 97 my $r; 98 my @row; 99 while ( defined ( $r=$sth->fetchrow_hashref ) ) { 100 push @row, $r; 101 } 102 $sth->finish; 103 return @row; 104 } 105
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |