$pg = $in{pg} || 0;

# キーワード検索準備(Shift-JIS定義)
$ascii = '[\x00-\x7F]';
$hankana = '[\xA1-\xDF]';
$twobytes = '[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]';

$in{word} =~ s/ / /g;
@wd = split(/\s+/, $in{word});

$i = 0;
@log;
open(DB,"$cf{datadir}/db.cgi") or error('open err: db.cgi');
while(<DB>) {
($no,$ttl,$com,$cat1,$cat2,$cat3,$ex,$w,$h) = split(/<>/);

# カテゴリ検索
next if ($in{cat1} != $cat1 && $in{cat1} ne '');
next if ($in{cat2} != $cat2 && $in{cat2} ne '');
next if ($in{cat3} != $cat3 && $in{cat3} ne '');

# ワード検索
if ($in{word} ne '') {
$flg;
foreach my $wd (@wd) {
if ($com =~ /^(?:$ascii|$hankana|$twobytes)*?\Q$wd\E/i) {
$flg++;
} else {
$flg = 0;
last;
} }
next if (!$flg);