--- db/prgsrc/db.cgi 2004/11/08 02:23:18 1.137 +++ db/prgsrc/db.cgi 2008/02/09 10:40:59 1.146 @@ -13,6 +13,8 @@ use Getopt::Std; #my ($dbuser,$dbname,$dbpass,$dbhost); eval {require "dbdefs.pl";} ; my $url=url||''; +my @used_stop=(); +my $showNearQuestions=0; $dbuser||="piataev"; $dbname||="chgk"; $dbpass||=""; @@ -43,7 +45,7 @@ if ($^O =~ /win/i) { $realHTMLDIR="/html/znatoki/baza/"; } else { - $realHTMLDIR="/home/piataev/public_html/dimrub/db/files/"; + $realHTMLDIR="/home/znatoki/chgk-db/public_html/dimrub/db/files/"; } @@ -66,7 +68,7 @@ $outputkvo=100 if $outputkvo>100; if (param('debug')) {$debug=1; $printqueries=1} *STDERR=*STDOUT if $debug; -if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/ && $url !~ /zaba/) { +if ($url !~ /db\.chgk\.info/ && $url !~ /localhost/ && $url !~ /bilbo/ && $url !~ /zaba/ && $url !~ /question\.chgk\.info/ ) { my $u="http://db.chgk.info/cgi-bin/db.cgi?$qs"; Redirect ($u); exit; @@ -129,8 +131,8 @@ my $all=param('all'); $all=0 if lc $all eq 'no'; my ($PWD) = `pwd` if $^O!~/win/i; chomp $PWD if $PWD; -my ($SRCPATH) = "/home/piataev/public_html/dimrub/src"; -my ($ZIP) = "/usr/local/bin/zip"; +my ($SRCPATH) = "/home/db-chgk/public_html/dimrub/src"; +my ($ZIP) = "/usr/bin/zip"; my $DUMPFILE = "/tmp/chgkdump"; my ($SENDMAIL) = "/usr/sbin/sendmail"; my ($TMPDIR) = "/var/tmp"; @@ -278,15 +280,17 @@ sub tourhref { my $res; if ($usehtml) { $res=$t; + $res=~s/\-q$//; + $res=~s/\-a$//; $res.=$a?"-a":"-q" unless $gr; $res.=".html"; $res=~s/(\#\d+)(.*)$/$2$1/; my $t=$res; $t=~s/\#.*$//; - $res=~s/\.1// unless -e "$realHTMLDIR$t"; +# $res=~s/\.1// unless $gr ||$res=~/\.\d+$/;#-e "$realHTMLDIR$t"; $t=$res; $t=~s/\#.*$//; - $res=~s/\.html/-q\.html/ unless -e "$realHTMLDIR$t"; +# $res=~s/\.html/-q\.html/ unless -e "$realHTMLDIR$t"; $res="$HTMLDIR$res" unless $opt_z; return $res; } else { @@ -432,9 +436,9 @@ action="/znatoki/cgi-bin/db.cgi"> -

Если при попытке поиска выдаётся сообщение об ошибке, + EOT @@ -500,19 +504,31 @@ sub russearch { my %relevance; my @blob; my %count; + my %stop_word; POSIX::setlocale( &POSIX::LC_ALL, $thislocale ); $sstr=~tr/йцукенгшщзхъфывапролджэячсмитьбю/ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ/; # @qw=@w =split (' ', uc $sstr); my $ts=uc $sstr; @qw=@w= $ts=~m/(?:(?:${RLrl})+)|(?:[A-Za-z0-9]+)/gom; - + $query="select nf.word from nf where number>=50000"; + $sth=$dbh->prepare($query); + $sth->execute(); + %stop_word=(); + while (@arr = $sth->fetchrow) + { + $stop_word{$arr[0]}=1; + } + $sth->finish; + #----------- foreach $i (0..$#w) # заполняем массив @nf начальных форм # $nf[$i] -- ссылка на массив возможных # начальных форм словоформы $i { + (push @used_stop, uc $w[$i]),next if $stop_word{uc $w[$i]}; $qw= $dbh->quote (uc $w[$i]); + $query=" select distinct w2 from nests where w1=$qw"; $sth=$dbh -> prepare($query); @@ -557,7 +573,7 @@ $sstr=~tr/йцукенгшщзхъфывапролджэячсмить $_= " word2question.word=$_" foreach @arr; $_= " nf.id=".$_. ' ' foreach @arr1; # @arr=(0) unless @arr; - $query="select questions from word2question where (". (join ' OR ', @arr).") AND length(questions)<80000"; + $query="select questions from word2question where (". (join ' OR ', @arr).") "; $sth=$dbh -> prepare($query); $sth->execute; @@ -891,7 +907,7 @@ sub PrintList { for (my $i = $first; $i <= $last; $i++) { my $q=$q{$$Questions[$i-1]}; my $output; - $output = &PrintQuestion($dbh, $q, 1, 0, 1,0,1 ); + $output = &PrintQuestion($dbh, $q, 1, 0, 1,$text,1 ); # if (param('metod') && (param('metod') eq 'rus' || param('metod') eq 'proxy')) { $output=~s/\b($shablon)\b/\$1\<\/strong\>/gi; @@ -945,6 +961,8 @@ sub PrintSearch { $Output.= p. "Время поиска: " . (time-$t) ." сек.".p; + $_="\"$_\"" foreach @used_stop; + $Output.= p. (join ', ',@used_stop) ." ignored".p if @used_stop; my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1); my $shablon; @@ -1176,7 +1194,6 @@ sub PrintTournament { p("Дополнительная информация об этом турнире - по адресу " . a({-'href'=>$URL}, $URL)); } - if ($Copyright) { $output .= p("Копирайт: " . $Copyright); } @@ -1186,6 +1203,10 @@ sub PrintTournament { if ($Info) { $output .= p($Info); } + + $output.=p("XML"); + + return $output; } @@ -1263,7 +1284,7 @@ sub PrintTour { my $sth=SelectQuestions($dbh,\@Questions,0); for ($q = 0; $q <= $#Questions; $q++) { fetchquestion($sth,\%q,0); - $output .= &PrintQuestion($dbh, \%q, $answer, 0,0,0,1); + $output .= &PrintQuestion($dbh, \%q, $answer, 0,0,$text,1); } $sth->finish; $output .= hr({-'align'=>'center', -'width'=>'80%'}); @@ -1281,6 +1302,7 @@ sub PrintTour { if ($Tournament{'Info'}) { $output .= p($Tournament{'Info'}); } + $output.=p("XML"); my $n=$Tour{'Number'}; if ($answer == 0) { @@ -1484,14 +1506,17 @@ $output.="" } $output=~s/\(pic: ([^\)]*)\)/

/g unless $text; + $output=~s/⌡/\ï/g; + $output=~s/⌠/\Ï/g; + $paramtour||=param("tour"); $fname=$fname.".$Question{'TourNumber'}" if $fname && $Question{'TourNumber'}; $fname||=param('tour'); my $qid=$fname ? ($fname.".$Question{'Number'}" ): ''; - $output.=br.a({href=> $url."?metod=proxy& + $output.=br.a({href=> "/search/"."?metod=proxy& qid=$qid"}, 'Близкие вопросы').p - if $answer>0 && !$text && $qid; + if $answer>0 && !$text && $qid && $showNearQuestions; return $output; } @@ -1964,7 +1989,7 @@ MAIN: my $texttour=$tour; my ($sth,$dbh); my($dsn) = "DBI:mysql:database=$dbname;host=$dbhost"; - $dbh = DBI->connect($dsn, $dbuser, $dbpass) + $dbh = DBI->connect($dsn, $dbuser, $dbpass) # $dbh = DBI->connect("DBI:mysql:$dbname", $username, $dbpass) or do { print header.h1("Временные проблемы") . "База вопросов временно не @@ -1976,14 +2001,14 @@ MAIN: if (param('qid') && (param('qid')=~/^\d+$/) || $tour && $tour=~/^\d+$/) { - my $destination='http://chgk.zaba.ru/search.html'; +# my $destination='http://chgk.zaba.ru/search.html'; # print header (-'Content-Type' => 'text/html', # -'Location:'=> 'http:\\db.chgk.info'); Redirect($destination); exit } - if ($tour && !param('qnumber') && (!param('answers')||(param('answers')<=1))) + if (0 && $tour && !param('qnumber') && (!param('answers')||(param('answers')<=1))) { my $n=param('tour'); $n=~s/.txt$//; @@ -2214,7 +2239,7 @@ EOT $QuestionNumber=($sth->fetchrow)[0]||0; } if ($QuestionNumber) { - $globaloutput.= &PrintQuestion($dbh, $QuestionNumber, $withanswers||0, $qnum, 1,0,0); + $globaloutput.= &PrintQuestion($dbh, $QuestionNumber, $withanswers||0, $qnum, 1,$text,0); # $dbh, $Id, $answer, $qnum, $title, $text } else { $globaloutput.=&PrintTournament($dbh, $tour, $withanswers);