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
51 &MARCaddword &MARCdelword
56 my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode) = @_;
57 # build the sql request. She will look like :
59 # from auth_subfield_table as m1, auth_subfield_table as m2
60 # where m1.authid=m2.authid and
61 # (m1.subfieldvalue like "Des%" and m2.subfieldvalue like "27%")
65 my @normal_and_or = ();
66 my @normal_operator = ();
67 my @normal_value = ();
68 # Extracts the NOT statements from the list of statements
69 for(my $i = 0 ; $i <= $#{$value} ; $i++)
71 if(@$operator[$i] eq "contains") # if operator is contains, splits the words in separate requests
73 foreach my $word (split(/ /, @$value[$i]))
75 unless (C4::Context->stopwords->{uc($word)}) { #it's NOT a stopword => use it. Otherwise, ignore
76 my $tag = substr(@$tags[$i],0,3);
77 my $subf = substr(@$tags[$i],3,1);
78 push @normal_tags, @$tags[$i];
79 push @normal_and_or, "and"; # assumes "foo" and "bar" if "foo bar" is entered
80 push @normal_operator, @$operator[$i];
81 push @normal_value, $word;
87 push @normal_tags, @$tags[$i];
88 push @normal_and_or, @$and_or[$i];
89 push @normal_operator, @$operator[$i];
90 push @normal_value, @$value[$i];
94 # Finds the basic results without the NOT requests
95 my ($sql_tables, $sql_where1, $sql_where2) = create_request($dbh,\@normal_tags, \@normal_and_or, \@normal_operator, \@normal_value);
100 $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)");
101 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)";
103 $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");
104 warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1";
106 $sth->execute($authtypecode);
108 while (my ($authid) = $sth->fetchrow) {
109 push @result,$authid;
112 # we have authid list. Now, loads summary from [offset] to [offset]+[length]
113 my $counter = $offset;
114 my @finalresult = ();
116 while (($counter <= $#result) && ($counter <= ($offset + $length))) {
117 # warn " HERE : $counter, $#result, $offset, $length";
118 # get MARC::Record of the authority
119 my $record = AUTHgetauthority($dbh,$result[$counter]);
120 # then build the summary
121 my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]);
122 my $authref = getauthtype($authtypecode);
123 my $summary = $authref->{summary};
124 my @fields = $record->fields();
125 foreach my $field (@fields) {
126 my $tag = $field->tag();
129 my @subf = $field->subfields;
130 for my $i (0..$#subf) {
131 my $subfieldcode = $subf[$i][0];
132 my $subfieldvalue = $subf[$i][1];
133 my $tagsubf = $tag.$subfieldcode;
134 $summary =~ s/\[(.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue\[$1$tagsubf$2]$2$3/g;
138 $summary =~ s/\[(.*?)]//g;
139 $summary =~ s/\n/<br>/g;
141 # find biblio MARC field using this authtypecode (to jump to biblio)
142 my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]);
143 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
144 $sth->execute($authtypecode);
145 my $tags_using_authtype;
146 while (my ($tagfield) = $sth->fetchrow) {
147 # warn "TAG : $tagfield";
148 $tags_using_authtype.= $tagfield."9,";
150 chop $tags_using_authtype;
152 # then add a line for the template loop
154 $newline{summary} = $summary;
155 $newline{authid} = $result[$counter];
156 $newline{used} = &AUTHcount_usage($result[$counter]);
157 $newline{biblio_fields} = $tags_using_authtype;
159 push @finalresult, \%newline;
161 my $nbresults = $#result + 1;
162 return (\@finalresult, $nbresults);
165 # Creates the SQL Request
168 my ($dbh,$tags, $and_or, $operator, $value) = @_;
170 my $sql_tables; # will contain marc_subfield_table as m1,...
171 my $sql_where1; # will contain the "true" where
172 my $sql_where2 = "("; # will contain m1.authid=m2.authid
173 my $nb_active=0; # will contain the number of "active" entries. and entry is active is a value is provided.
174 my $nb_table=1; # will contain the number of table. ++ on each entry EXCEPT when an OR is provided.
177 for(my $i=0; $i<=@$value;$i++) {
181 if (@$operator[$i] eq "start") {
182 $sql_tables .= "auth_subfield_table as m$nb_table,";
183 $sql_where1 .= "(m1.subfieldvalue like ".$dbh->quote("@$value[$i]%");
185 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
188 } elsif (@$operator[$i] eq "contains") {
189 $sql_tables .= "auth_word as m$nb_table,";
190 $sql_where1 .= "(m1.word like ".$dbh->quote("@$value[$i]%");
192 $sql_where1 .=" and m1.tagsubfield in (@$tags[$i])";
197 $sql_tables .= "auth_subfield_table as m$nb_table,";
198 $sql_where1 .= "(m1.subfieldvalue @$operator[$i] ".$dbh->quote("@$value[$i]");
200 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
205 if (@$operator[$i] eq "start") {
207 $sql_tables .= "auth_subfield_table as m$nb_table,";
208 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue like ".$dbh->quote("@$value[$i]%");
210 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
213 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
214 } elsif (@$operator[$i] eq "contains") {
215 if (@$and_or[$i] eq 'and') {
217 $sql_tables .= "auth_word as m$nb_table,";
218 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
220 $sql_where1 .=" and m$nb_table.tagsubfield in(@$tags[$i])";
223 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
225 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
227 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldid in (@$tags[$i])";
230 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
234 $sql_tables .= "auth_subfield_table as m$nb_table,";
235 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue @$operator[$i] ".$dbh->quote(@$value[$i]);
237 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
239 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
246 if($sql_where2 ne "(") # some datas added to sql_where2, processing
248 $sql_where2 = substr($sql_where2, 0, (length($sql_where2)-5)); # deletes the trailing ' and '
251 else # no sql_where2 statement, deleting '('
255 chop $sql_tables; # deletes the trailing ','
257 return ($sql_tables, $sql_where1, $sql_where2);
261 sub AUTHcount_usage {
263 my $dbh = C4::Context->dbh;
264 # find MARC fields using this authtype
265 my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
266 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
267 $sth->execute($authtypecode);
268 my $tags_using_authtype;
269 while (my ($tagfield) = $sth->fetchrow) {
270 # warn "TAG : $tagfield";
271 $tags_using_authtype.= "'".$tagfield."9',";
273 chop $tags_using_authtype;
274 if ($tags_using_authtype) {
275 $sth = $dbh->prepare("select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=?");
277 $sth = $dbh->prepare("select count(*) from marc_subfield_table where subfieldvalue=?");
279 # warn "Q : select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=$authid";
280 $sth->execute($authid);
281 my ($result) = $sth->fetchrow;
282 # warn "Authority $authid TOTAL USED : $result";
286 # merging 2 authority entries. After a merge, the "from" can be deleted.
288 # my ($auth_merge_from,$auth_merge_to) = @_;
289 # my $dbh = C4::Context->dbh;
290 # # find MARC fields using this authtype
291 # my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
293 # my $record_from = AUTHgetauthority($dbh,$auth_merge_from);
294 # my $record_to = AUTHgetauthority($dbh,$auth_merge_to);
295 # my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
296 # $sth->execute($authtypecode);
297 # my $tags_using_authtype;
298 # while (my ($tagfield) = $sth->fetchrow) {
299 # warn "TAG : $tagfield";
300 # $tags_using_authtype.= "'".$tagfield."9',";
302 # chop $tags_using_authtype;
303 # # now, find every biblio using this authority
304 # $sth = $dbh->prepare("select bibid,tag,tag_indicator,tagorder from marc_subfield_table where tag+subfieldid in ($tags_using_authtype) and subfieldvalue=?");
305 # $sth->execute($authid);
306 # # and delete entries before recreating them
307 # while (my ($bibid,$tag,$tag_indicator,$tagorder) = $sth->fetchrow) {
308 # &MARCdelsubfield($dbh,$bibid,$tag);
314 sub AUTHfind_authtypecode {
315 my ($dbh,$authid) = @_;
316 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
317 $sth->execute($authid);
318 my ($authtypecode) = $sth->fetchrow;
319 return $authtypecode;
324 my ($dbh,$forlibrarian,$authtypecode)= @_;
325 $authtypecode="" unless $authtypecode;
327 my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
328 # check that framework exists
329 $sth=$dbh->prepare("select count(*) from auth_tag_structure where authtypecode=?");
330 $sth->execute($authtypecode);
331 my ($total) = $sth->fetchrow;
332 $authtypecode="" unless ($total >0);
333 $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory,repeatable from auth_tag_structure where authtypecode=? order by tagfield");
334 $sth->execute($authtypecode);
335 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
336 while ( ($tag,$lib,$mandatory,$repeatable) = $sth->fetchrow) {
337 $res->{$tag}->{lib}=$lib;
338 $res->{$tab}->{tab}=""; # XXX
339 $res->{$tag}->{mandatory}=$mandatory;
340 $res->{$tag}->{repeatable}=$repeatable;
343 $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");
344 $sth->execute($authtypecode);
347 my $authorised_value;
348 my $thesaurus_category;
354 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$value_builder,$seealso) = $sth->fetchrow) {
355 $res->{$tag}->{$subfield}->{lib}=$lib;
356 $res->{$tag}->{$subfield}->{tab}=$tab;
357 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
358 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
359 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
360 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
361 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
362 $res->{$tag}->{$subfield}->{seealso}=$seealso;
363 $res->{$tag}->{$subfield}->{hidden}=$hidden;
364 $res->{$tag}->{$subfield}->{isurl}=$isurl;
369 sub AUTHaddauthority {
370 # pass the MARC::Record to this function, and it will create the records in the marc tables
371 my ($dbh,$record,$authid,$authtypecode) = @_;
372 my @fields=$record->fields();
373 # warn "IN AUTHaddauthority $authid => ".$record->as_formatted;
374 # adding main table, and retrieving authid
375 # if authid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
376 # if authid empty => true add, find a new authid number
378 $dbh->do("lock tables auth_header WRITE,auth_subfield_table WRITE, auth_word WRITE, stopwords READ");
379 my $sth=$dbh->prepare("insert into auth_header (datecreated,authtypecode) values (now(),?)");
380 $sth->execute($authtypecode);
381 $sth=$dbh->prepare("select max(authid) from auth_header");
383 ($authid)=$sth->fetchrow;
387 # now, add subfields...
388 foreach my $field (@fields) {
390 if ($field->tag() <10) {
391 &AUTHaddsubfield($dbh,$authid,
400 my @subfields=$field->subfields();
401 foreach my $subfieldcount (0..$#subfields) {
402 &AUTHaddsubfield($dbh,$authid,
404 $field->indicator(1).$field->indicator(2),
406 $subfields[$subfieldcount][0],
408 $subfields[$subfieldcount][1]
413 $dbh->do("unlock tables");
418 sub AUTHaddsubfield {
419 # Add a new subfield to a tag into the DB.
420 my ($dbh,$authid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalues) = @_;
421 # if not value, end of job, we do nothing
422 if (length($subfieldvalues) ==0) {
425 if (not($subfieldcode)) {
428 my @subfieldvalues = split /\|/,$subfieldvalues;
429 foreach my $subfieldvalue (@subfieldvalues) {
430 my $sth=$dbh->prepare("insert into auth_subfield_table (authid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
431 $sth->execute($authid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
433 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";
435 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
439 sub AUTHgetauthority {
440 # Returns MARC::Record of the biblio passed in parameter.
441 my ($dbh,$authid)=@_;
442 my $record = MARC::Record->new();
443 #---- TODO : the leader is missing
444 $record->leader(' ');
445 my $sth=$dbh->prepare("select authid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue
446 from auth_subfield_table
447 where authid=? order by tag,tagorder,subfieldcode
449 $sth->execute($authid);
453 my $field; # for >=10 tags
454 my $prevvalue; # for <10 tags
455 while (my $row=$sth->fetchrow_hashref) {
456 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
459 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue) unless $prevtag eq "XXX"; # ignore the 1st loop
461 $record->add_fields($field) unless $prevtag eq "XXX";
464 $prevtagorder=$row->{tagorder};
465 $prevtag = $row->{tag};
466 $previndicator=$row->{tag_indicator};
467 if ($row->{tag}<10) {
468 $prevvalue = $row->{subfieldvalue};
470 $field = MARC::Field->new((sprintf "%03s",$prevtag), substr($row->{tag_indicator}.' ',0,1), substr($row->{tag_indicator}.' ',1,1), $row->{'subfieldcode'}, $row->{'subfieldvalue'} );
473 if ($row->{tag} <10) {
474 $record->add_fields((sprintf "%03s",$row->{tag}), $row->{'subfieldvalue'});
476 $field->add_subfields($row->{'subfieldcode'}, $row->{'subfieldvalue'} );
478 $prevtag= $row->{tag};
479 $previndicator=$row->{tag_indicator};
482 # the last has not been included inside the loop... do it now !
483 if ($prevtag ne "XXX") { # check that we have found something. Otherwise, prevtag is still XXX and we
484 # must return an empty record, not make MARC::Record fail because we try to
485 # create a record with XXX as field :-(
487 $record->add_fields($prevtag,$prevvalue);
489 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
490 $record->add_fields($field);
496 sub AUTHgetauth_type {
497 my ($authtypecode) = @_;
498 my $dbh=C4::Context->dbh;
499 my $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
500 $sth->execute($authtypecode);
501 return $sth->fetchrow_hashref;
503 sub AUTHmodauthority {
504 my ($dbh,$authid,$record,$delete)=@_;
505 my $oldrecord=&AUTHgetauthority($dbh,$authid);
506 if ($oldrecord eq $record) {
509 # 1st delete the authority,
511 &AUTHdelauthority($dbh,$authid,1);
512 &AUTHaddauthority($dbh,$record,$authid,AUTHfind_authtypecode($dbh,$authid));
513 # FIXME : modify the authority in biblio too.
516 sub AUTHdelauthority {
517 my ($dbh,$authid,$keep_biblio) = @_;
518 # if the keep_biblio is set to 1, then authority entries in biblio are preserved.
519 # This flag is set when the delauthority is called by modauthority
520 # due to a too complex structure of MARC (repeatable fields and subfields),
521 # the best solution for a modif is to delete / recreate the record.
523 my $record = AUTHgetauthority($dbh,$authid);
524 $dbh->do("delete from auth_header where authid=$authid") unless $keep_biblio;
525 $dbh->do("delete from auth_subfield_table where authid=$authid");
526 $dbh->do("delete from auth_word where authid=$authid");
527 # FIXME : delete or not in biblio tables (depending on $keep_biblio flag)
530 sub AUTHmodsubfield {
531 # Subroutine changes a subfield value given a subfieldid.
532 my ($dbh, $subfieldid, $subfieldvalue )=@_;
533 $dbh->do("lock tables auth_subfield_table WRITE");
534 my $sth=$dbh->prepare("update auth_subfield_table set subfieldvalue=? where subfieldid=?");
535 $sth->execute($subfieldvalue, $subfieldid);
536 $dbh->do("unlock tables");
538 $sth=$dbh->prepare("select authid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from auth_subfield_table where subfieldid=?");
539 $sth->execute($subfieldid);
540 my ($authid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
542 &AUTHdelword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
543 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
544 return($subfieldid, $subfieldvalue);
547 sub AUTHfindsubfield {
548 my ($dbh,$authid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
552 my $query="select subfieldid from auth_subfield_table where authid=? and tag=? and subfieldcode=?";
553 my @bind_values = ($authid,$tag, $subfieldcode);
554 if ($subfieldvalue) {
555 $query .= " and subfieldvalue=?";
556 push(@bind_values,$subfieldvalue);
558 if ($subfieldorder<1) {
561 $query .= " and subfieldorder=?";
562 push(@bind_values,$subfieldorder);
564 my $sti=$dbh->prepare($query);
565 $sti->execute(@bind_values);
566 while (($subfieldid) = $sti->fetchrow) {
568 $lastsubfieldid=$subfieldid;
570 if ($resultcounter>1) {
571 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
572 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
575 return $lastsubfieldid;
579 sub AUTHfindsubfieldid {
580 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
581 my $sth=$dbh->prepare("select subfieldid from auth_subfield_table
582 where authid=? and tag=? and tagorder=?
583 and subfieldcode=? and subfieldorder=?");
584 $sth->execute($authid,$tag,$tagorder,$subfield,$subfieldorder);
585 my ($res) = $sth->fetchrow;
587 $sth=$dbh->prepare("select subfieldid from auth_subfield_table
588 where authid=? and tag=? and tagorder=?
589 and subfieldcode=?");
590 $sth->execute($authid,$tag,$tagorder,$subfield);
591 ($res) = $sth->fetchrow;
596 sub AUTHfind_authtypecode {
597 my ($dbh,$authid) = @_;
598 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
599 $sth->execute($authid);
600 my ($authtypecode) = $sth->fetchrow;
601 return $authtypecode;
604 sub AUTHdelsubfield {
605 # delete a subfield for $authid / tag / tagorder / subfield / subfieldorder
606 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
607 $dbh->do("delete from auth_subfield_table where authid='$authid' and
608 tag='$tag' and tagorder='$tagorder'
609 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
614 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
616 my $record = MARC::Record->new();
617 # my %subfieldlist=();
618 my $prevvalue; # if tag <10
619 my $field; # if tag >=10
620 for (my $i=0; $i< @$rtags; $i++) {
621 # rebuild MARC::Record
622 if (@$rtags[$i] ne $prevtag) {
625 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
629 $record->add_fields($field);
632 $indicators{@$rtags[$i]}.=' ';
633 if (@$rtags[$i] <10) {
634 $prevvalue= @$rvalues[$i];
636 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
638 $prevtag = @$rtags[$i];
640 if (@$rtags[$i] <10) {
641 $prevvalue=@$rvalues[$i];
644 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
647 $prevtag= @$rtags[$i];
650 # the last has not been included inside the loop... do it now !
651 $record->add_fields($field);
652 # warn $record->as_formatted;
657 # split a subfield string and adds it into the word table.
659 my ($dbh,$authid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
660 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
661 my @words = split / /,$sentence;
662 my $stopwords= C4::Context->stopwords;
663 my $sth=$dbh->prepare("insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
664 values (?,concat(?,?),?,?,?,soundex(?))");
665 foreach my $word (@words) {
666 # we record only words longer than 2 car and not in stopwords hash
667 if (length($word)>2 and !($stopwords->{uc($word)})) {
668 $sth->execute($authid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
670 warn "ERROR ==> insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($authid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
677 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
678 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
679 my $sth=$dbh->prepare("delete from auth_word where authid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?");
680 $sth->execute($authid,$tag,$subfield,$tagorder,$subfieldorder);
684 # converts ISO 5426 coded string to ISO 8859-1
685 # sloppy code : should be improved in next issue
686 my ($string,$encoding) = @_ ;
688 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
689 if ($encoding eq "UNIMARC") {
751 # this handles non-sorting blocks (if implementation requires this)
752 $string = nsb_clean($_) ;
753 } elsif ($encoding eq "USMARC" || $encoding eq "MARC21") {
806 # this handles non-sorting blocks (if implementation requires this)
807 $string = nsb_clean($_) ;
814 my $NSB = '\x88' ; # NSB : begin Non Sorting Block
815 my $NSE = '\x89' ; # NSE : Non Sorting Block end
816 # handles non sorting blocks
820 s/[ ]{0,1}$NSE/) /gm ;
825 END { } # module clean-up code here (global destructor)
831 Koha Developement team <info@koha.org>
833 Paul POULAIN paul.poulain@free.fr
839 # Revision 1.7 2004/09/23 16:13:00 tipaul
840 # Bugfix in modification
842 # Revision 1.6 2004/08/18 16:00:24 tipaul
843 # fixes for authorities management
845 # Revision 1.5 2004/07/05 13:37:22 doxulting
846 # First step for working authorities
848 # Revision 1.4 2004/06/22 11:35:37 tipaul
849 # removing % at the beginning of a string to avoid loooonnnngggg searchs
851 # Revision 1.3 2004/06/17 08:02:13 tipaul
852 # merging tag & subfield in auth_word for better perfs
854 # Revision 1.2 2004/06/10 08:29:01 tipaul
855 # MARC authority management (continued)
857 # Revision 1.1 2004/06/07 07:35:01 tipaul
858 # MARC authority management package