4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
22 # This script generates and fill the thesaurus table
23 # with the data in bibliothesaurus
29 my $dbh = C4::Context->dbh;
32 my ($dbh,$sql_cmd)=@_;
33 my $sti=$dbh->prepare($sql_cmd);
36 print "error : ".$sti->errstr." \n tried to execute : $sql_cmd\n";
41 my $sth=$dbh->prepare("show tables");
44 while (my ($table) = $sth->fetchrow) {
46 # print "table $table\n";
49 #print "creating thesaurus...\n";
50 #dosql($dbh,"CREATE TABLE bibliothesaurus (code BIGINT not null AUTO_INCREMENT, freelib CHAR (255) not null , stdlib CHAR (255) not null , type CHAR (80) not null , PRIMARY KEY (code), INDEX (freelib),index(stdlib),index(type))");
51 $dbh->do("delete from bibliothesaurus");
52 my $sti=$dbh->prepare("select count(*) from bibliosubject");
54 my ($total) = $sti->fetchrow_array;
55 $sti=$dbh->prepare("select subject from bibliosubject");
58 my $search_sth = $dbh->prepare("select id,level,hierarchy from bibliothesaurus where stdlib=?");
59 my $insert_sth = $dbh->prepare("insert into bibliothesaurus (freelib,stdlib,category,level,hierarchy) values (?,?,?,?,?)");
60 while (my $line =$sti->fetchrow_hashref) {
63 print "$i / $total\n";
65 my @hierarchy = split / - /,$line->{'subject'};
67 my $top_hierarchy = "";
68 #---- if not a main authority field, search where to link
69 for (my $hier=0; $hier<$#hierarchy+1 ; $hier++) {
70 $rebuild .=$hierarchy[$hier];
71 $search_sth->execute($rebuild);
72 my ($id,$level,$hierarchy) = $search_sth->fetchrow_array;
73 # warn "/($line->{'subject'}) : $rebuild/";
74 # if father not found, create father and son
76 $insert_sth->execute($rebuild,$rebuild,"",$hier,"$top_hierarchy");
77 # search again, to find $id and buiild $top_hierarchy
78 $search_sth->execute($rebuild);
79 my ($id,$level,$hierarchy) = $search_sth->fetchrow_array;
80 $top_hierarchy .="|" if ($top_hierarchy);
81 $top_hierarchy .= "$id";
82 # else create only son
84 $top_hierarchy .="|" if ($top_hierarchy);
85 $top_hierarchy .= "$id";
86 # $insert_sth->execute($rebuild,$rebuild,"",$hier,"$top_hierarchy");
90 # my $sti2=$dbh->prepare("select count(*) as t from bibliothesaurus where freelib=".$dbh->quote($line->{'subject'}));
93 # print "error : ".$sti2->errstr."\n";
96 # my $line2=$sti2->fetchrow_hashref;
97 # if ($line2->{'t'} ==0) {
98 # dosql($dbh,"insert into bibliothesaurus (freelib,stdlib,category) values (".$dbh->quote($line->{'subject'}).",".$dbh->quote($line->{'subject'}).")");