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
49 &MARCaddword &MARCdelword
54 my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode) = @_;
55 # build the sql request. She will look like :
57 # from auth_subfield_table as m1, auth_subfield_table as m2
58 # where m1.authid=m2.authid and
59 # (m1.subfieldvalue like "Des%" and m2.subfieldvalue like "27%")
63 my @normal_and_or = ();
64 my @normal_operator = ();
65 my @normal_value = ();
66 # Extracts the NOT statements from the list of statements
67 for(my $i = 0 ; $i <= $#{$value} ; $i++)
69 if(@$operator[$i] eq "contains") # if operator is contains, splits the words in separate requests
71 foreach my $word (split(/ /, @$value[$i]))
73 unless (C4::Context->stopwords->{uc($word)}) { #it's NOT a stopword => use it. Otherwise, ignore
74 my $tag = substr(@$tags[$i],0,3);
75 my $subf = substr(@$tags[$i],3,1);
76 push @normal_tags, @$tags[$i];
77 push @normal_and_or, "and"; # assumes "foo" and "bar" if "foo bar" is entered
78 push @normal_operator, @$operator[$i];
79 push @normal_value, $word;
85 push @normal_tags, @$tags[$i];
86 push @normal_and_or, @$and_or[$i];
87 push @normal_operator, @$operator[$i];
88 push @normal_value, @$value[$i];
92 # Finds the basic results without the NOT requests
93 my ($sql_tables, $sql_where1, $sql_where2) = create_request($dbh,\@normal_tags, \@normal_and_or, \@normal_operator, \@normal_value);
98 $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)");
99 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)";
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_where1");
102 warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1";
104 $sth->execute($authtypecode);
106 while (my ($authid) = $sth->fetchrow) {
107 warn "AUTH: $authid";
108 push @result,$authid;
111 # we have authid list. Now, loads summary from [offset] to [offset]+[length]
112 my $counter = $offset;
113 my @finalresult = ();
115 while (($counter <= $#result) && ($counter <= ($offset + $length))) {
116 # warn " HERE : $counter, $#result, $offset, $length";
117 # get MARC::Record of the authority
118 my $record = AUTHgetauthority($dbh,$result[$counter]);
119 # then build the summary
120 my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]);
121 my $authref = getauthtype($authtypecode);
122 my $summary = $authref->{summary};
123 my @fields = $record->fields();
124 foreach my $field (@fields) {
125 my $tag = $field->tag();
128 my @subf = $field->subfields;
129 for my $i (0..$#subf) {
130 my $subfieldcode = $subf[$i][0];
131 my $subfieldvalue = $subf[$i][1];
132 my $tagsubf = $tag.$subfieldcode;
133 $summary =~ s/\[(.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue\[$1$tagsubf$2]$2$3/g;
137 $summary =~ s/\[(.*?)]//g;
138 $summary =~ s/\n/<br>/g;
140 # find biblio MARC field using this authtypecode (to jump to biblio)
141 my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]);
142 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
143 $sth->execute($authtypecode);
144 my $tags_using_authtype;
145 while (my ($tagfield) = $sth->fetchrow) {
146 # warn "TAG : $tagfield";
147 $tags_using_authtype.= $tagfield."9,";
149 chop $tags_using_authtype;
151 # then add a line for the template loop
153 $newline{summary} = $summary;
154 $newline{authid} = $result[$counter];
155 $newline{used} = &AUTHcount_usage($result[$counter]);
156 $newline{biblio_fields} = $tags_using_authtype;
158 push @finalresult, \%newline;
160 my $nbresults = $#result + 1;
161 return (\@finalresult, $nbresults);
164 # Creates the SQL Request
167 my ($dbh,$tags, $and_or, $operator, $value) = @_;
169 my $sql_tables; # will contain marc_subfield_table as m1,...
170 my $sql_where1; # will contain the "true" where
171 my $sql_where2 = "("; # will contain m1.authid=m2.authid
172 my $nb_active=0; # will contain the number of "active" entries. and entry is active is a value is provided.
173 my $nb_table=1; # will contain the number of table. ++ on each entry EXCEPT when an OR is provided.
176 for(my $i=0; $i<=@$value;$i++) {
180 if (@$operator[$i] eq "start") {
181 $sql_tables .= "auth_subfield_table as m$nb_table,";
182 $sql_where1 .= "(m1.subfieldvalue like ".$dbh->quote("@$value[$i]%");
184 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
187 } elsif (@$operator[$i] eq "contains") {
188 $sql_tables .= "auth_word as m$nb_table,";
189 $sql_where1 .= "(m1.word like ".$dbh->quote("@$value[$i]%");
191 $sql_where1 .=" and m1.tagsubfield in (@$tags[$i])";
196 $sql_tables .= "auth_subfield_table as m$nb_table,";
197 $sql_where1 .= "(m1.subfieldvalue @$operator[$i] ".$dbh->quote("@$value[$i]");
199 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
204 if (@$operator[$i] eq "start") {
206 $sql_tables .= "auth_subfield_table as m$nb_table,";
207 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue like ".$dbh->quote("@$value[$i]%");
209 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
212 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
213 } elsif (@$operator[$i] eq "contains") {
214 if (@$and_or[$i] eq 'and') {
216 $sql_tables .= "auth_word as m$nb_table,";
217 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
219 $sql_where1 .=" and m$nb_table.tagsubfield in(@$tags[$i])";
222 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
224 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
226 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldid in (@$tags[$i])";
229 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
233 $sql_tables .= "auth_subfield_table as m$nb_table,";
234 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue @$operator[$i] ".$dbh->quote(@$value[$i]);
236 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
238 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
245 if($sql_where2 ne "(") # some datas added to sql_where2, processing
247 $sql_where2 = substr($sql_where2, 0, (length($sql_where2)-5)); # deletes the trailing ' and '
250 else # no sql_where2 statement, deleting '('
254 chop $sql_tables; # deletes the trailing ','
256 return ($sql_tables, $sql_where1, $sql_where2);
260 sub AUTHcount_usage {
262 my $dbh = C4::Context->dbh;
263 # find MARC fields using this authtype
264 my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
265 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
266 $sth->execute($authtypecode);
267 my $tags_using_authtype;
268 while (my ($tagfield) = $sth->fetchrow) {
269 # warn "TAG : $tagfield";
270 $tags_using_authtype.= "'".$tagfield."9',";
272 chop $tags_using_authtype;
273 $sth = $dbh->prepare("select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=?");
274 # warn "Q : select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=$authid";
275 $sth->execute($authid);
276 my ($result) = $sth->fetchrow;
277 # warn "Authority $authid TOTAL USED : $result";
281 # merging 2 authority entries. After a merge, the "from" can be deleted.
283 # my ($auth_merge_from,$auth_merge_to) = @_;
284 # my $dbh = C4::Context->dbh;
285 # # find MARC fields using this authtype
286 # my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
288 # my $record_from = AUTHgetauthority($dbh,$auth_merge_from);
289 # my $record_to = AUTHgetauthority($dbh,$auth_merge_to);
290 # my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
291 # $sth->execute($authtypecode);
292 # my $tags_using_authtype;
293 # while (my ($tagfield) = $sth->fetchrow) {
294 # warn "TAG : $tagfield";
295 # $tags_using_authtype.= "'".$tagfield."9',";
297 # chop $tags_using_authtype;
298 # # now, find every biblio using this authority
299 # $sth = $dbh->prepare("select bibid,tag,tag_indicator,tagorder from marc_subfield_table where tag+subfieldid in ($tags_using_authtype) and subfieldvalue=?");
300 # $sth->execute($authid);
301 # # and delete entries before recreating them
302 # while (my ($bibid,$tag,$tag_indicator,$tagorder) = $sth->fetchrow) {
303 # &MARCdelsubfield($dbh,$bibid,$tag);
309 sub AUTHfind_authtypecode {
310 my ($dbh,$authid) = @_;
311 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
312 $sth->execute($authid);
313 my ($authtypecode) = $sth->fetchrow;
314 return $authtypecode;
319 my ($dbh,$forlibrarian,$authtypecode)= @_;
320 # warn "AUTH : $authtypecode";
321 $authtypecode="" unless $authtypecode;
322 # warn "AUTH : $authtypecode";
324 my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
325 # check that framework exists
326 $sth=$dbh->prepare("select count(*) from auth_tag_structure where authtypecode=?");
327 $sth->execute($authtypecode);
328 my ($total) = $sth->fetchrow;
329 $authtypecode="" unless ($total >0);
330 $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory,repeatable from auth_tag_structure where authtypecode=? order by tagfield");
331 $sth->execute($authtypecode);
332 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
333 while ( ($tag,$lib,$mandatory,$repeatable) = $sth->fetchrow) {
334 $res->{$tag}->{lib}=$lib;
335 $res->{$tab}->{tab}=""; # XXX
336 $res->{$tag}->{mandatory}=$mandatory;
337 $res->{$tag}->{repeatable}=$repeatable;
340 $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");
341 $sth->execute($authtypecode);
344 my $authorised_value;
345 my $thesaurus_category;
351 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$value_builder,$seealso) = $sth->fetchrow) {
352 $res->{$tag}->{$subfield}->{lib}=$lib;
353 $res->{$tag}->{$subfield}->{tab}=$tab;
354 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
355 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
356 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
357 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
358 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
359 $res->{$tag}->{$subfield}->{seealso}=$seealso;
360 $res->{$tag}->{$subfield}->{hidden}=$hidden;
361 $res->{$tag}->{$subfield}->{isurl}=$isurl;
366 sub AUTHaddauthority {
367 # pass the MARC::Record to this function, and it will create the records in the marc tables
368 my ($dbh,$record,$authid,$authtypecode) = @_;
369 my @fields=$record->fields();
370 # warn "IN AUTHaddauthority $authid => ".$record->as_formatted;
371 # adding main table, and retrieving authid
372 # if authid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
373 # if authid empty => true add, find a new authid number
375 $dbh->do("lock tables auth_header WRITE,auth_subfield_table WRITE, auth_word WRITE, stopwords READ");
376 my $sth=$dbh->prepare("insert into auth_header (datecreated,authtypecode) values (now(),?)");
377 $sth->execute($authtypecode);
378 $sth=$dbh->prepare("select max(authid) from auth_header");
380 ($authid)=$sth->fetchrow;
383 warn "auth : $authid";
385 # now, add subfields...
386 foreach my $field (@fields) {
388 if ($field->tag() <10) {
389 &AUTHaddsubfield($dbh,$authid,
398 my @subfields=$field->subfields();
399 foreach my $subfieldcount (0..$#subfields) {
400 &AUTHaddsubfield($dbh,$authid,
402 $field->indicator(1).$field->indicator(2),
404 $subfields[$subfieldcount][0],
406 $subfields[$subfieldcount][1]
411 $dbh->do("unlock tables");
416 sub AUTHaddsubfield {
417 # Add a new subfield to a tag into the DB.
418 my ($dbh,$authid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalues) = @_;
419 # if not value, end of job, we do nothing
420 if (length($subfieldvalues) ==0) {
423 if (not($subfieldcode)) {
426 my @subfieldvalues = split /\|/,$subfieldvalues;
427 foreach my $subfieldvalue (@subfieldvalues) {
428 my $sth=$dbh->prepare("insert into auth_subfield_table (authid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
429 $sth->execute($authid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
431 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";
433 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
437 sub AUTHgetauthority {
438 # Returns MARC::Record of the biblio passed in parameter.
439 my ($dbh,$authid)=@_;
440 my $record = MARC::Record->new();
441 #---- TODO : the leader is missing
442 $record->leader(' ');
443 my $sth=$dbh->prepare("select authid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue
444 from auth_subfield_table
445 where authid=? order by tag,tagorder,subfieldcode
447 $sth->execute($authid);
451 my $field; # for >=10 tags
452 my $prevvalue; # for <10 tags
453 while (my $row=$sth->fetchrow_hashref) {
454 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
457 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue) unless $prevtag eq "XXX"; # ignore the 1st loop
459 $record->add_fields($field) unless $prevtag eq "XXX";
462 $prevtagorder=$row->{tagorder};
463 $prevtag = $row->{tag};
464 $previndicator=$row->{tag_indicator};
465 if ($row->{tag}<10) {
466 $prevvalue = $row->{subfieldvalue};
468 $field = MARC::Field->new((sprintf "%03s",$prevtag), substr($row->{tag_indicator}.' ',0,1), substr($row->{tag_indicator}.' ',1,1), $row->{'subfieldcode'}, $row->{'subfieldvalue'} );
471 if ($row->{tag} <10) {
472 $record->add_fields((sprintf "%03s",$row->{tag}), $row->{'subfieldvalue'});
474 $field->add_subfields($row->{'subfieldcode'}, $row->{'subfieldvalue'} );
476 $prevtag= $row->{tag};
477 $previndicator=$row->{tag_indicator};
480 # the last has not been included inside the loop... do it now !
481 if ($prevtag ne "XXX") { # check that we have found something. Otherwise, prevtag is still XXX and we
482 # must return an empty record, not make MARC::Record fail because we try to
483 # create a record with XXX as field :-(
485 $record->add_fields($prevtag,$prevvalue);
487 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
488 $record->add_fields($field);
494 sub AUTHmodauthority {
495 my ($dbh,$authid,$record,$delete)=@_;
496 my $oldrecord=&AUTHgetauthority($dbh,$authid);
497 if ($oldrecord eq $record) {
500 # 1st delete the authority,
502 &AUTHdelauthority($dbh,$authid,1);
503 &AUTHaddauthority($dbh,$record,$authid);
504 # FIXME : modify the authority in biblio too.
507 sub AUTHdelauthority {
508 my ($dbh,$authid,$keep_biblio) = @_;
509 # if the keep_biblio is set to 1, then authority entries in biblio are preserved.
510 # This flag is set when the delauthority is called by modauthority
511 # due to a too complex structure of MARC (repeatable fields and subfields),
512 # the best solution for a modif is to delete / recreate the record.
514 my $record = AUTHgetauthority($dbh,$authid);
515 $dbh->do("delete from auth_header where authid=$authid");
516 $dbh->do("delete from auth_subfield_table where authid=$authid");
517 $dbh->do("delete from auth_word where authid=$authid");
518 # FIXME : delete or not in biblio tables (depending on $keep_biblio flag)
521 sub AUTHmodsubfield {
522 # Subroutine changes a subfield value given a subfieldid.
523 my ($dbh, $subfieldid, $subfieldvalue )=@_;
524 $dbh->do("lock tables auth_subfield_table WRITE");
525 my $sth=$dbh->prepare("update auth_subfield_table set subfieldvalue=? where subfieldid=?");
526 $sth->execute($subfieldvalue, $subfieldid);
527 $dbh->do("unlock tables");
529 $sth=$dbh->prepare("select authid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from auth_subfield_table where subfieldid=?");
530 $sth->execute($subfieldid);
531 my ($authid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
533 &AUTHdelword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
534 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
535 return($subfieldid, $subfieldvalue);
538 sub AUTHfindsubfield {
539 my ($dbh,$authid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
543 my $query="select subfieldid from auth_subfield_table where authid=? and tag=? and subfieldcode=?";
544 my @bind_values = ($authid,$tag, $subfieldcode);
545 if ($subfieldvalue) {
546 $query .= " and subfieldvalue=?";
547 push(@bind_values,$subfieldvalue);
549 if ($subfieldorder<1) {
552 $query .= " and subfieldorder=?";
553 push(@bind_values,$subfieldorder);
555 my $sti=$dbh->prepare($query);
556 $sti->execute(@bind_values);
557 while (($subfieldid) = $sti->fetchrow) {
559 $lastsubfieldid=$subfieldid;
561 if ($resultcounter>1) {
562 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
563 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
566 return $lastsubfieldid;
570 sub AUTHfindsubfieldid {
571 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
572 my $sth=$dbh->prepare("select subfieldid from auth_subfield_table
573 where authid=? and tag=? and tagorder=?
574 and subfieldcode=? and subfieldorder=?");
575 $sth->execute($authid,$tag,$tagorder,$subfield,$subfieldorder);
576 my ($res) = $sth->fetchrow;
578 $sth=$dbh->prepare("select subfieldid from auth_subfield_table
579 where authid=? and tag=? and tagorder=?
580 and subfieldcode=?");
581 $sth->execute($authid,$tag,$tagorder,$subfield);
582 ($res) = $sth->fetchrow;
587 sub AUTHfind_authtypecode {
588 my ($dbh,$authid) = @_;
589 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
590 $sth->execute($authid);
591 my ($authtypecode) = $sth->fetchrow;
592 return $authtypecode;
595 sub AUTHdelsubfield {
596 # delete a subfield for $authid / tag / tagorder / subfield / subfieldorder
597 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
598 $dbh->do("delete from auth_subfield_table where authid='$authid' and
599 tag='$tag' and tagorder='$tagorder'
600 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
605 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
607 my $record = MARC::Record->new();
608 # my %subfieldlist=();
609 my $prevvalue; # if tag <10
610 my $field; # if tag >=10
611 for (my $i=0; $i< @$rtags; $i++) {
612 # rebuild MARC::Record
613 if (@$rtags[$i] ne $prevtag) {
616 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
620 $record->add_fields($field);
623 $indicators{@$rtags[$i]}.=' ';
624 if (@$rtags[$i] <10) {
625 $prevvalue= @$rvalues[$i];
627 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
629 $prevtag = @$rtags[$i];
631 if (@$rtags[$i] <10) {
632 $prevvalue=@$rvalues[$i];
635 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
638 $prevtag= @$rtags[$i];
641 # the last has not been included inside the loop... do it now !
642 $record->add_fields($field);
643 # warn $record->as_formatted;
648 # split a subfield string and adds it into the word table.
650 my ($dbh,$authid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
651 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
652 my @words = split / /,$sentence;
653 my $stopwords= C4::Context->stopwords;
654 my $sth=$dbh->prepare("insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
655 values (?,concat(?,?),?,?,?,soundex(?))");
656 foreach my $word (@words) {
657 # we record only words longer than 2 car and not in stopwords hash
658 if (length($word)>2 and !($stopwords->{uc($word)})) {
659 $sth->execute($authid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
661 warn "ERROR ==> insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($authid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
668 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
669 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
670 my $sth=$dbh->prepare("delete from auth_word where authid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?");
671 $sth->execute($authid,$tag,$subfield,$tagorder,$subfieldorder);
675 # converts ISO 5426 coded string to ISO 8859-1
676 # sloppy code : should be improved in next issue
677 my ($string,$encoding) = @_ ;
679 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
680 if ($encoding eq "UNIMARC") {
742 # this handles non-sorting blocks (if implementation requires this)
743 $string = nsb_clean($_) ;
744 } elsif ($encoding eq "USMARC" || $encoding eq "MARC21") {
797 # this handles non-sorting blocks (if implementation requires this)
798 $string = nsb_clean($_) ;
805 my $NSB = '\x88' ; # NSB : begin Non Sorting Block
806 my $NSE = '\x89' ; # NSE : Non Sorting Block end
807 # handles non sorting blocks
811 s/[ ]{0,1}$NSE/) /gm ;
816 END { } # module clean-up code here (global destructor)
822 Koha Developement team <info@koha.org>
824 Paul POULAIN paul.poulain@free.fr
830 # Revision 1.5 2004/07/05 13:37:22 doxulting
831 # First step for working authorities
833 # Revision 1.4 2004/06/22 11:35:37 tipaul
834 # removing % at the beginning of a string to avoid loooonnnngggg searchs
836 # Revision 1.3 2004/06/17 08:02:13 tipaul
837 # merging tag & subfield in auth_word for better perfs
839 # Revision 1.2 2004/06/10 08:29:01 tipaul
840 # MARC authority management (continued)
842 # Revision 1.1 2004/06/07 07:35:01 tipaul
843 # MARC authority management package