#============================================================ # MySearchApplication #============================================================ package MySearchApplication; use MyApplication; @ISA = qw(MyApplication); #公開したいサブルーチン #@EXPORT = qw(erfc tan); @EXPORT_OK = qw(); use strict; use SQLDB; #=============================================== # 大域変数 #=============================================== #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module, $app) = @_; my $this = {}; bless $this; # $this->SUPER::new(@_); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # 一般関数 #============================================================ sub MakeDirectoriesLink { my ($App, $pParams, $path, $LinkOption, $target, $EditLink, $RootDir) = @_; $RootDir = $path if(!defined $RootDir); my $RegExpRootDir = Utils::RegExpQuote($RootDir); my $link = ''; $path = Utils::URLDecode($path); my $code = Jcode::getcode($path); Jcode::convert(\$path, 'utf8', $code); $path =~ s/\\/\//g; my @dirs = Utils::Split('/', $path); my $dir = ''; my $dirnlabel = ''; for(my $i = 0 ; $i < @dirs ; $i++) { Jcode::convert(\$dirs[$i], $code, 'utf8'); $dir = Utils::MakePath($dir, $dirs[$i], '/', 0); next if($dir eq ''); $dirnlabel = Utils::MakePath($dirnlabel, $dirs[$i], '/', 0); if($RootDir eq '' or $dir =~ /^$RegExpRootDir/) { } else { next; } my $opt = $LinkOption; if(ref $opt eq 'ARRAY') { if(-d $dir) { $opt = $LinkOption->[0]; } else { $opt = $LinkOption->[1]; } } my $dire = $dir; $dire = Utils::URLEncode($dire); $opt =~ s/{Path}/$dire/mig; Jcode::convert(\$dirnlabel, $pParams->{WebCharCode}, $code); $link .= "/$dirnlabel"; if($EditLink ne '') { my $EditLink = $App->GetLinkString($EditLink, $pParams, "edit", "_blank", undef, undef, $dir); $link .="($EditLink)"; } if($RootDir eq '' or $dir =~ /^$RegExpRootDir/) { $dirnlabel = ''; } } $link =~ s/^\/+//; return $link; } sub BuildHitHash { my ($App, $pParams, $pRetHash0, $pKeywords, $pHash) = @_; my $pRetHash = $pRetHash0; # my $pRetHash = {}; # Utils::MergeHash($pRetHash, $pRetHash0); Utils::MergeHash($pRetHash, $pHash); my $DirPath = $pRetHash->{DirPath}; my $FilePath = $pRetHash->{FilePath}; Jcode::convert(\$DirPath, $pParams->{FileSystemCharCode}); Jcode::convert(\$FilePath, $pParams->{FileSystemCharCode}); $pRetHash->{FullPath} = Utils::MakePath($DirPath, $FilePath, '/', 0); Jcode::convert(\$pRetHash->{Authors}, $pParams->{WebCharCode}); Jcode::convert(\$pRetHash->{Title}, $pParams->{WebCharCode}); Jcode::convert(\$pRetHash->{Journal}, $pParams->{WebCharCode}); $pRetHash->{AuthorsStr} = $pRetHash->{Authors}; $pRetHash->{TitleStr} = $pRetHash->{Title}; $pRetHash->{JournalStr} = $pRetHash->{Journal}; for(my $i = 0 ; $i < @$pKeywords ; $i++) { my $keyword = $pKeywords->[$i]; $pRetHash->{AuthorsStr} =~ s/($keyword)/$1<\/b>/gi; $pRetHash->{TitleStr} =~ s/($keyword)/$1<\/b>/gi; $pRetHash->{JournalStr} =~ s/($keyword)/$1<\/b>/gi; } $pRetHash->{JournalStr} = "".$pRetHash->{Journal}.""; $pRetHash->{VolumeStr} = "".$pRetHash->{Volume}.""; # $pRetHash->{ConvAuthors} = $pRetHash->{AuthorsStr}; # $pRetHash->{ConvTitle} = $pRetHash->{TitleStr}; #$App->print("AF: $pParams->{AuthorsFormat}\n"); $pRetHash->{ConvAuthors} = $App->ConvertAuthors($pParams, $pRetHash->{AuthorsStr}, $pParams->{AuthorsFormat}, $pParams->{AuthorsFormatMaxAuthors}, $pParams->{AuthorsFormatLastSeparator}, $pParams->{AuthorsFormatFirstCharCapital}, $pParams->{AuthorsFormatFirstNameInitial}); $pRetHash->{ConvTitle} = $App->ConvertTitle($pParams, $pRetHash->{TitleStr}, $pParams->{TitleFormat}); $pRetHash->{SearchKey} = $App->BuildSearchKey($pParams, $pRetHash->{Year}, $pRetHash->{Volume}, $pRetHash->{Pages}, $pRetHash->{Authors}, $pRetHash->{Journal}, $pRetHash->{Title}, $pRetHash->{JournalType}); if($pRetHash->{LinkURL} ne '') { if($pRetHash->{LinkURL} =~ /^Papers:(.*)$/) { my $sn = $1; my ($Option, $target) = $App->GetCGIParameters( { Action => "SearchAllPapers::ViewData", PrevAction => $pParams->{Action}, UserSN => $sn, }, [qw(+Action UserSN IsChildFrame FrameMode)]); $pRetHash->{LinkURLStr} = "{ScriptPath}?$Option\" target=\"_blank\">Link to SearchPapers"; } } return $pRetHash; } #========================================== # DB関係 #========================================== sub SearchPapers { my ($App, $condition, $vars) = @_; my $pParams = $App->pParams(); my $ret = $App->DB()->Search($pParams->{DBPapersTableName}, $condition, $vars); return -1 if($ret <= 0); return $App->DB()->rows(); } sub UpdateReferences { my ($App, $condition, @a) = @_; my $pParams = $App->pParams(); # return $App->DB()->UpdateData($pParams->{DBReferencesTableName}, $condition, @a); return $App->DB()->UpdateDataByAutoJudge($pParams->{DBReferencesTableName}, $condition, @a); } sub SearchReferences { my ($App, $condition, $vars) = @_; my $pParams = $App->pParams(); my $ret = $App->DB()->Search($pParams->{DBReferencesTableName}, $condition, $vars); return $ret; } sub ConstructSQL { my ($App, $pParams, $key0, $target0, $pTargetHash) = @_; $pTargetHash = {} if(!defined $pTargetHash); $pTargetHash->{all} = [qw(Title Authors Journal Organization Laboratory Language JournalType Comment Keywords AtComment FilePath)] if(!defined $pTargetHash->{all}); $pTargetHash->{Keywords} = [qw(Comment Keywords AtComment)] if(!defined $pTargetHash->{Keywords}); my $sql0 = ''; if($key0 ne '') { my $fword0 = "\'%$key0%\'"; if($pTargetHash->{$target0}) { my $pTarget = $pTargetHash->{$target0}; my $s = ''; for(my $i = 0 ; $i < @$pTarget ; $i++) { $s .= ($s eq '')? "$pTarget->[$i] like $fword0" : " or $pTarget->[$i] like $fword0"; } $sql0 = "($s)"; } else { $sql0 .= "($target0 like $fword0)"; } } return $sql0; } sub ConstructSQLAll { my ($App, $pParams, $pHash, $OtherCondition, $pTargetHash, $pOrderArray) = (@_); $pOrderArray = [qw(DataUpdateTime WriteDate)] if(!defined $pOrderArray); my $yearcondition = "(Year is null or (Year >= $pHash->{year0} and Year <= $pHash->{year1}))"; my $sql = ""; my $sql1 = $App->ConstructSQL($pParams, $pHash->{keyword1}, $pHash->{target1}, $pTargetHash); if($pHash->{keyword2} ne '') { my $sql2 = $App->ConstructSQL($pParams, $pHash->{keyword2}, $pHash->{target2}, $pTargetHash); $sql .= "($sql1 $pHash->{operator} $sql2)"; } else { $sql .= $sql1; } if($pHash->{keyword1} ne '') { $sql .= " and "; } $sql .= $yearcondition; if($pHash->{UnregisteredOnly} ne '') { $sql .= " and LinkURL=''"; } if($pHash->{RegisteredOnly} ne '') { $sql .= " and LinkURL!=''"; } if($OtherCondition ne '') { $sql .= " and $OtherCondition"; } if($pHash->{orderdirection} eq 'ascend' and $pHash->{ordertarget} ne '') { $sql .= " order by $pHash->{ordertarget}"; for(my $i = 0 ; $i < @$pOrderArray ; $i++) { $sql .= ",$pOrderArray->[$i]"; } $sql .= ";\n"; } elsif($pHash->{ordertarget} ne '') { $sql .= " order by $pHash->{ordertarget} desc"; for(my $i = 0 ; $i < @$pOrderArray ; $i++) { $sql .= ",$pOrderArray->[$i] desc"; } } $sql =~ s/[\r\n\s]+/ /sg; return $sql; } 1;