1 package C4::AuthoritiesMarc;
2 # Copyright 2000-2002 Katipo Communications
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17 # Suite 330, Boston, MA 02111-1307 USA
27 use vars qw($VERSION @ISA @EXPORT);
29 # set the version for version checking
36 &AUTHfind_authtypecode
52 &MARCaddword &MARCdelword
57 my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode) = @_;
58 # build the sql request. She will look like :
60 # from auth_subfield_table as m1, auth_subfield_table as m2
61 # where m1.authid=m2.authid and
62 # (m1.subfieldvalue like "Des%" and m2.subfieldvalue like "27%")
66 my @normal_and_or = ();
67 my @normal_operator = ();
68 my @normal_value = ();
69 # Extracts the NOT statements from the list of statements
70 for(my $i = 0 ; $i <= $#{$value} ; $i++)
72 if(@$operator[$i] eq "contains") # if operator is contains, splits the words in separate requests
74 foreach my $word (split(/ /, @$value[$i]))
76 unless (C4::Context->stopwords->{uc($word)}) { #it's NOT a stopword => use it. Otherwise, ignore
77 my $tag = substr(@$tags[$i],0,3);
78 my $subf = substr(@$tags[$i],3,1);
79 push @normal_tags, @$tags[$i];
80 push @normal_and_or, "and"; # assumes "foo" and "bar" if "foo bar" is entered
81 push @normal_operator, @$operator[$i];
82 push @normal_value, $word;
88 push @normal_tags, @$tags[$i];
89 push @normal_and_or, @$and_or[$i];
90 push @normal_operator, @$operator[$i];
91 push @normal_value, @$value[$i];
95 # Finds the basic results without the NOT requests
96 my ($sql_tables, $sql_where1, $sql_where2) = create_request($dbh,\@normal_tags, \@normal_and_or, \@normal_operator, \@normal_value);
101 $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)");
102 warn "Q2 : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)";
104 $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1");
105 warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1";
107 $sth->execute($authtypecode);
109 while (my ($authid) = $sth->fetchrow) {
110 push @result,$authid;
113 # we have authid list. Now, loads summary from [offset] to [offset]+[length]
114 my $counter = $offset;
115 my @finalresult = ();
117 while (($counter <= $#result) && ($counter <= ($offset + $length))) {
118 # warn " HERE : $counter, $#result, $offset, $length";
119 # get MARC::Record of the authority
120 my $record = AUTHgetauthority($dbh,$result[$counter]);
121 # then build the summary
122 my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]);
123 my $authref = getauthtype($authtypecode);
124 my $summary = $authref->{summary};
125 my @fields = $record->fields();
126 foreach my $field (@fields) {
127 my $tag = $field->tag();
130 my @subf = $field->subfields;
131 for my $i (0..$#subf) {
132 my $subfieldcode = $subf[$i][0];
133 my $subfieldvalue = $subf[$i][1];
134 my $tagsubf = $tag.$subfieldcode;
135 $summary =~ s/\[(.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g;
139 $summary =~ s/\[(.*?)]//g;
140 $summary =~ s/\n/<br>/g;
142 # find biblio MARC field using this authtypecode (to jump to biblio)
143 my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]);
144 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
145 $sth->execute($authtypecode);
146 my $tags_using_authtype;
147 while (my ($tagfield) = $sth->fetchrow) {
148 # warn "TAG : $tagfield";
149 $tags_using_authtype.= $tagfield."9,";
151 chop $tags_using_authtype;
153 # then add a line for the template loop
155 $newline{summary} = $summary;
156 $newline{authid} = $result[$counter];
157 $newline{used} = &AUTHcount_usage($result[$counter]);
158 $newline{biblio_fields} = $tags_using_authtype;
160 push @finalresult, \%newline;
162 my $nbresults = $#result + 1;
163 return (\@finalresult, $nbresults);
166 # Creates the SQL Request
169 my ($dbh,$tags, $and_or, $operator, $value) = @_;
171 my $sql_tables; # will contain marc_subfield_table as m1,...
172 my $sql_where1; # will contain the "true" where
173 my $sql_where2 = "("; # will contain m1.authid=m2.authid
174 my $nb_active=0; # will contain the number of "active" entries. and entry is active is a value is provided.
175 my $nb_table=1; # will contain the number of table. ++ on each entry EXCEPT when an OR is provided.
178 for(my $i=0; $i<=@$value;$i++) {
182 if (@$operator[$i] eq "start") {
183 $sql_tables .= "auth_subfield_table as m$nb_table,";
184 $sql_where1 .= "(m1.subfieldvalue like ".$dbh->quote("@$value[$i]%");
186 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
189 } elsif (@$operator[$i] eq "contains") {
190 $sql_tables .= "auth_word as m$nb_table,";
191 $sql_where1 .= "(m1.word like ".$dbh->quote("@$value[$i]%");
193 $sql_where1 .=" and m1.tagsubfield in (@$tags[$i])";
198 $sql_tables .= "auth_subfield_table as m$nb_table,";
199 $sql_where1 .= "(m1.subfieldvalue @$operator[$i] ".$dbh->quote("@$value[$i]");
201 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
206 if (@$operator[$i] eq "start") {
208 $sql_tables .= "auth_subfield_table as m$nb_table,";
209 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue like ".$dbh->quote("@$value[$i]%");
211 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
214 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
215 } elsif (@$operator[$i] eq "contains") {
216 if (@$and_or[$i] eq 'and') {
218 $sql_tables .= "auth_word as m$nb_table,";
219 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
221 $sql_where1 .=" and m$nb_table.tagsubfield in(@$tags[$i])";
224 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
226 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
228 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldid in (@$tags[$i])";
231 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
235 $sql_tables .= "auth_subfield_table as m$nb_table,";
236 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue @$operator[$i] ".$dbh->quote(@$value[$i]);
238 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
240 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
247 if($sql_where2 ne "(") # some datas added to sql_where2, processing
249 $sql_where2 = substr($sql_where2, 0, (length($sql_where2)-5)); # deletes the trailing ' and '
252 else # no sql_where2 statement, deleting '('
256 chop $sql_tables; # deletes the trailing ','
258 return ($sql_tables, $sql_where1, $sql_where2);
262 sub AUTHcount_usage {
264 my $dbh = C4::Context->dbh;
265 # find MARC fields using this authtype
266 my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
267 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
268 $sth->execute($authtypecode);
269 my $tags_using_authtype;
270 while (my ($tagfield) = $sth->fetchrow) {
271 # warn "TAG : $tagfield";
272 $tags_using_authtype.= "'".$tagfield."9',";
274 chop $tags_using_authtype;
275 if ($tags_using_authtype) {
276 $sth = $dbh->prepare("select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=?");
278 $sth = $dbh->prepare("select count(*) from marc_subfield_table where subfieldvalue=?");
280 # warn "Q : select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=$authid";
281 $sth->execute($authid);
282 my ($result) = $sth->fetchrow;
283 # warn "Authority $authid TOTAL USED : $result";
287 # merging 2 authority entries. After a merge, the "from" can be deleted.
289 # my ($auth_merge_from,$auth_merge_to) = @_;
290 # my $dbh = C4::Context->dbh;
291 # # find MARC fields using this authtype
292 # my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
294 # my $record_from = AUTHgetauthority($dbh,$auth_merge_from);
295 # my $record_to = AUTHgetauthority($dbh,$auth_merge_to);
296 # my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
297 # $sth->execute($authtypecode);
298 # my $tags_using_authtype;
299 # while (my ($tagfield) = $sth->fetchrow) {
300 # warn "TAG : $tagfield";
301 # $tags_using_authtype.= "'".$tagfield."9',";
303 # chop $tags_using_authtype;
304 # # now, find every biblio using this authority
305 # $sth = $dbh->prepare("select bibid,tag,tag_indicator,tagorder from marc_subfield_table where tag+subfieldid in ($tags_using_authtype) and subfieldvalue=?");
306 # $sth->execute($authid);
307 # # and delete entries before recreating them
308 # while (my ($bibid,$tag,$tag_indicator,$tagorder) = $sth->fetchrow) {
309 # &MARCdelsubfield($dbh,$bibid,$tag);
315 sub AUTHfind_authtypecode {
316 my ($dbh,$authid) = @_;
317 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
318 $sth->execute($authid);
319 my ($authtypecode) = $sth->fetchrow;
320 return $authtypecode;
325 my ($dbh,$forlibrarian,$authtypecode)= @_;
326 $authtypecode="" unless $authtypecode;
328 my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
329 # check that framework exists
330 $sth=$dbh->prepare("select count(*) from auth_tag_structure where authtypecode=?");
331 $sth->execute($authtypecode);
332 my ($total) = $sth->fetchrow;
333 $authtypecode="" unless ($total >0);
334 $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory,repeatable from auth_tag_structure where authtypecode=? order by tagfield");
335 $sth->execute($authtypecode);
336 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
337 while ( ($tag,$lib,$mandatory,$repeatable) = $sth->fetchrow) {
338 $res->{$tag}->{lib}=$lib;
339 $res->{$tab}->{tab}=""; # XXX
340 $res->{$tag}->{mandatory}=$mandatory;
341 $res->{$tag}->{repeatable}=$repeatable;
344 $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,value_builder,seealso from auth_subfield_structure where authtypecode=? order by tagfield,tagsubfield");
345 $sth->execute($authtypecode);
348 my $authorised_value;
349 my $thesaurus_category;
355 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$value_builder,$seealso) = $sth->fetchrow) {
356 $res->{$tag}->{$subfield}->{lib}=$lib;
357 $res->{$tag}->{$subfield}->{tab}=$tab;
358 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
359 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
360 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
361 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
362 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
363 $res->{$tag}->{$subfield}->{seealso}=$seealso;
364 $res->{$tag}->{$subfield}->{hidden}=$hidden;
365 $res->{$tag}->{$subfield}->{isurl}=$isurl;
370 sub AUTHaddauthority {
371 # pass the MARC::Record to this function, and it will create the records in the marc tables
372 my ($dbh,$record,$authid,$authtypecode) = @_;
373 my @fields=$record->fields();
374 # warn "IN AUTHaddauthority $authid => ".$record->as_formatted;
375 # adding main table, and retrieving authid
376 # if authid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
377 # if authid empty => true add, find a new authid number
379 $dbh->do("lock tables auth_header WRITE,auth_subfield_table WRITE, auth_word WRITE, stopwords READ");
380 my $sth=$dbh->prepare("insert into auth_header (datecreated,authtypecode) values (now(),?)");
381 $sth->execute($authtypecode);
382 $sth=$dbh->prepare("select max(authid) from auth_header");
384 ($authid)=$sth->fetchrow;
388 # now, add subfields...
389 foreach my $field (@fields) {
391 if ($field->tag() <10) {
392 &AUTHaddsubfield($dbh,$authid,
401 my @subfields=$field->subfields();
402 foreach my $subfieldcount (0..$#subfields) {
403 &AUTHaddsubfield($dbh,$authid,
405 $field->indicator(1).$field->indicator(2),
407 $subfields[$subfieldcount][0],
409 $subfields[$subfieldcount][1]
414 $dbh->do("unlock tables");
419 sub AUTHaddsubfield {
420 # Add a new subfield to a tag into the DB.
421 my ($dbh,$authid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalues) = @_;
422 # if not value, end of job, we do nothing
423 if (length($subfieldvalues) ==0) {
426 if (not($subfieldcode)) {
429 my @subfieldvalues = split /\|/,$subfieldvalues;
430 foreach my $subfieldvalue (@subfieldvalues) {
431 my $sth=$dbh->prepare("insert into auth_subfield_table (authid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
432 $sth->execute($authid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
434 warn "ERROR ==> insert into auth_subfield_table (authid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values ($authid,$tagid,$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue)\n";
436 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
440 sub AUTHgetauthority {
441 # Returns MARC::Record of the biblio passed in parameter.
442 my ($dbh,$authid)=@_;
443 my $record = MARC::Record->new();
444 #---- TODO : the leader is missing
445 $record->leader(' ');
446 my $sth=$dbh->prepare("select authid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue
447 from auth_subfield_table
448 where authid=? order by tag,tagorder,subfieldcode
450 $sth->execute($authid);
454 my $field; # for >=10 tags
455 my $prevvalue; # for <10 tags
456 while (my $row=$sth->fetchrow_hashref) {
457 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
460 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue) unless $prevtag eq "XXX"; # ignore the 1st loop
462 $record->add_fields($field) unless $prevtag eq "XXX";
465 $prevtagorder=$row->{tagorder};
466 $prevtag = $row->{tag};
467 $previndicator=$row->{tag_indicator};
468 if ($row->{tag}<10) {
469 $prevvalue = $row->{subfieldvalue};
471 $field = MARC::Field->new((sprintf "%03s",$prevtag), substr($row->{tag_indicator}.' ',0,1), substr($row->{tag_indicator}.' ',1,1), $row->{'subfieldcode'}, $row->{'subfieldvalue'} );
474 if ($row->{tag} <10) {
475 $record->add_fields((sprintf "%03s",$row->{tag}), $row->{'subfieldvalue'});
477 $field->add_subfields($row->{'subfieldcode'}, $row->{'subfieldvalue'} );
479 $prevtag= $row->{tag};
480 $previndicator=$row->{tag_indicator};
483 # the last has not been included inside the loop... do it now !
484 if ($prevtag ne "XXX") { # check that we have found something. Otherwise, prevtag is still XXX and we
485 # must return an empty record, not make MARC::Record fail because we try to
486 # create a record with XXX as field :-(
488 $record->add_fields($prevtag,$prevvalue);
490 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
491 $record->add_fields($field);
497 sub AUTHgetauth_type {
498 my ($authtypecode) = @_;
499 my $dbh=C4::Context->dbh;
500 my $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
501 $sth->execute($authtypecode);
502 return $sth->fetchrow_hashref;
504 sub AUTHmodauthority {
505 my ($dbh,$authid,$record,$delete)=@_;
506 my $oldrecord=&AUTHgetauthority($dbh,$authid);
507 if ($oldrecord eq $record) {
510 # 1st delete the authority,
512 &AUTHdelauthority($dbh,$authid,1);
513 &AUTHaddauthority($dbh,$record,$authid,AUTHfind_authtypecode($dbh,$authid));
514 # FIXME : modify the authority in biblio too.
517 sub AUTHdelauthority {
518 my ($dbh,$authid,$keep_biblio) = @_;
519 # if the keep_biblio is set to 1, then authority entries in biblio are preserved.
520 # This flag is set when the delauthority is called by modauthority
521 # due to a too complex structure of MARC (repeatable fields and subfields),
522 # the best solution for a modif is to delete / recreate the record.
524 my $record = AUTHgetauthority($dbh,$authid);
525 $dbh->do("delete from auth_header where authid=$authid") unless $keep_biblio;
526 $dbh->do("delete from auth_subfield_table where authid=$authid");
527 $dbh->do("delete from auth_word where authid=$authid");
528 # FIXME : delete or not in biblio tables (depending on $keep_biblio flag)
531 sub AUTHmodsubfield {
532 # Subroutine changes a subfield value given a subfieldid.
533 my ($dbh, $subfieldid, $subfieldvalue )=@_;
534 $dbh->do("lock tables auth_subfield_table WRITE");
535 my $sth=$dbh->prepare("update auth_subfield_table set subfieldvalue=? where subfieldid=?");
536 $sth->execute($subfieldvalue, $subfieldid);
537 $dbh->do("unlock tables");
539 $sth=$dbh->prepare("select authid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from auth_subfield_table where subfieldid=?");
540 $sth->execute($subfieldid);
541 my ($authid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
543 &AUTHdelword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
544 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
545 return($subfieldid, $subfieldvalue);
548 sub AUTHfindsubfield {
549 my ($dbh,$authid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
553 my $query="select subfieldid from auth_subfield_table where authid=? and tag=? and subfieldcode=?";
554 my @bind_values = ($authid,$tag, $subfieldcode);
555 if ($subfieldvalue) {
556 $query .= " and subfieldvalue=?";
557 push(@bind_values,$subfieldvalue);
559 if ($subfieldorder<1) {
562 $query .= " and subfieldorder=?";
563 push(@bind_values,$subfieldorder);
565 my $sti=$dbh->prepare($query);
566 $sti->execute(@bind_values);
567 while (($subfieldid) = $sti->fetchrow) {
569 $lastsubfieldid=$subfieldid;
571 if ($resultcounter>1) {
572 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
573 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
576 return $lastsubfieldid;
580 sub AUTHfindsubfieldid {
581 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
582 my $sth=$dbh->prepare("select subfieldid from auth_subfield_table
583 where authid=? and tag=? and tagorder=?
584 and subfieldcode=? and subfieldorder=?");
585 $sth->execute($authid,$tag,$tagorder,$subfield,$subfieldorder);
586 my ($res) = $sth->fetchrow;
588 $sth=$dbh->prepare("select subfieldid from auth_subfield_table
589 where authid=? and tag=? and tagorder=?
590 and subfieldcode=?");
591 $sth->execute($authid,$tag,$tagorder,$subfield);
592 ($res) = $sth->fetchrow;
597 sub AUTHfind_authtypecode {
598 my ($dbh,$authid) = @_;
599 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
600 $sth->execute($authid);
601 my ($authtypecode) = $sth->fetchrow;
602 return $authtypecode;
605 sub AUTHdelsubfield {
606 # delete a subfield for $authid / tag / tagorder / subfield / subfieldorder
607 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
608 $dbh->do("delete from auth_subfield_table where authid='$authid' and
609 tag='$tag' and tagorder='$tagorder'
610 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
615 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
617 my $record = MARC::Record->new();
618 # my %subfieldlist=();
619 my $prevvalue; # if tag <10
620 my $field; # if tag >=10
621 for (my $i=0; $i< @$rtags; $i++) {
622 # rebuild MARC::Record
623 if (@$rtags[$i] ne $prevtag) {
626 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
630 $record->add_fields($field);
633 $indicators{@$rtags[$i]}.=' ';
634 if (@$rtags[$i] <10) {
635 $prevvalue= @$rvalues[$i];
637 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
639 $prevtag = @$rtags[$i];
641 if (@$rtags[$i] <10) {
642 $prevvalue=@$rvalues[$i];
645 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
648 $prevtag= @$rtags[$i];
651 # the last has not been included inside the loop... do it now !
652 $record->add_fields($field);
653 # warn $record->as_formatted;
658 # split a subfield string and adds it into the word table.
660 my ($dbh,$authid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
661 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
662 my @words = split / /,$sentence;
663 my $stopwords= C4::Context->stopwords;
664 my $sth=$dbh->prepare("insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
665 values (?,concat(?,?),?,?,?,soundex(?))");
666 foreach my $word (@words) {
667 # we record only words longer than 2 car and not in stopwords hash
668 if (length($word)>2 and !($stopwords->{uc($word)})) {
669 $sth->execute($authid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
671 warn "ERROR ==> insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($authid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
678 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
679 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
680 my $sth=$dbh->prepare("delete from auth_word where authid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?");
681 $sth->execute($authid,$tag,$subfield,$tagorder,$subfieldorder);
685 # converts ISO 5426 coded string to ISO 8859-1
686 # sloppy code : should be improved in next issue
687 my ($string,$encoding) = @_ ;
689 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
690 if ($encoding eq "UNIMARC") {
752 # this handles non-sorting blocks (if implementation requires this)
753 $string = nsb_clean($_) ;
754 } elsif ($encoding eq "USMARC" || $encoding eq "MARC21") {
807 # this handles non-sorting blocks (if implementation requires this)
808 $string = nsb_clean($_) ;
815 my $NSB = '\x88' ; # NSB : begin Non Sorting Block
816 my $NSE = '\x89' ; # NSE : Non Sorting Block end
817 # handles non sorting blocks
821 s/[ ]{0,1}$NSE/) /gm ;
826 END { } # module clean-up code here (global destructor)
832 Koha Developement team <info@koha.org>
834 Paul POULAIN paul.poulain@free.fr
840 # Revision 1.9 2004/12/23 09:48:11 tipaul
841 # Minor changes in summary "exploding" (the 3 digits AFTER the subfield were not on the right place).
843 # Revision 1.8 2004/11/05 10:11:39 tipaul
844 # export auth_count_usage (bugfix)
846 # Revision 1.7 2004/09/23 16:13:00 tipaul
847 # Bugfix in modification
849 # Revision 1.6 2004/08/18 16:00:24 tipaul
850 # fixes for authorities management
852 # Revision 1.5 2004/07/05 13:37:22 doxulting
853 # First step for working authorities
855 # Revision 1.4 2004/06/22 11:35:37 tipaul
856 # removing % at the beginning of a string to avoid loooonnnngggg searchs
858 # Revision 1.3 2004/06/17 08:02:13 tipaul
859 # merging tag & subfield in auth_word for better perfs
861 # Revision 1.2 2004/06/10 08:29:01 tipaul
862 # MARC authority management (continued)
864 # Revision 1.1 2004/06/07 07:35:01 tipaul
865 # MARC authority management package