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);
97 $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)");
98 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)";
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_where1");
101 warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1";
103 $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.
175 for(my $i=0; $i<=@$value;$i++) {
179 if (@$operator[$i] eq "start") {
180 $sql_tables .= "auth_subfield_table as m$nb_table,";
181 $sql_where1 .= "(m1.subfieldvalue like ".$dbh->quote("@$value[$i]%");
183 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
186 } elsif (@$operator[$i] eq "contains") {
187 $sql_tables .= "auth_word as m$nb_table,";
188 $sql_where1 .= "(m1.word like ".$dbh->quote("@$value[$i]%");
190 $sql_where1 .=" and m1.tagsubfield in (@$tags[$i])";
194 $sql_tables .= "auth_subfield_table as m$nb_table,";
195 $sql_where1 .= "(m1.subfieldvalue @$operator[$i] ".$dbh->quote("@$value[$i]");
197 $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])";
202 if (@$operator[$i] eq "start") {
204 $sql_tables .= "auth_subfield_table as m$nb_table,";
205 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue like ".$dbh->quote("@$value[$i]%");
207 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
210 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
211 } elsif (@$operator[$i] eq "contains") {
212 if (@$and_or[$i] eq 'and') {
214 $sql_tables .= "auth_word as m$nb_table,";
215 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
217 $sql_where1 .=" and m$nb_table.tagsubfield in(@$tags[$i])";
220 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
222 $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%");
224 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldid in (@$tags[$i])";
227 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
231 $sql_tables .= "auth_subfield_table as m$nb_table,";
232 $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue @$operator[$i] ".$dbh->quote(@$value[$i]);
234 $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])";
236 $sql_where2 .= "m1.authid=m$nb_table.authid and ";
243 if($sql_where2 ne "(") # some datas added to sql_where2, processing
245 $sql_where2 = substr($sql_where2, 0, (length($sql_where2)-5)); # deletes the trailing ' and '
248 else # no sql_where2 statement, deleting '('
252 chop $sql_tables; # deletes the trailing ','
253 return ($sql_tables, $sql_where1, $sql_where2);
257 sub AUTHcount_usage {
259 my $dbh = C4::Context->dbh;
260 # find MARC fields using this authtype
261 my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
262 my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
263 $sth->execute($authtypecode);
264 my $tags_using_authtype;
265 while (my ($tagfield) = $sth->fetchrow) {
266 # warn "TAG : $tagfield";
267 $tags_using_authtype.= "'".$tagfield."9',";
269 chop $tags_using_authtype;
270 $sth = $dbh->prepare("select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=?");
271 # warn "Q : select count(*) from marc_subfield_table where concat(tag,subfieldcode) in ($tags_using_authtype) and subfieldvalue=$authid";
272 $sth->execute($authid);
273 my ($result) = $sth->fetchrow;
274 # warn "Authority $authid TOTAL USED : $result";
278 # merging 2 authority entries. After a merge, the "from" can be deleted.
280 # my ($auth_merge_from,$auth_merge_to) = @_;
281 # my $dbh = C4::Context->dbh;
282 # # find MARC fields using this authtype
283 # my $authtypecode = AUTHfind_authtypecode($dbh,$authid);
285 # my $record_from = AUTHgetauthority($dbh,$auth_merge_from);
286 # my $record_to = AUTHgetauthority($dbh,$auth_merge_to);
287 # my $sth = $dbh->prepare("select distinct tagfield from marc_subfield_structure where authtypecode=?");
288 # $sth->execute($authtypecode);
289 # my $tags_using_authtype;
290 # while (my ($tagfield) = $sth->fetchrow) {
291 # warn "TAG : $tagfield";
292 # $tags_using_authtype.= "'".$tagfield."9',";
294 # chop $tags_using_authtype;
295 # # now, find every biblio using this authority
296 # $sth = $dbh->prepare("select bibid,tag,tag_indicator,tagorder from marc_subfield_table where tag+subfieldid in ($tags_using_authtype) and subfieldvalue=?");
297 # $sth->execute($authid);
298 # # and delete entries before recreating them
299 # while (my ($bibid,$tag,$tag_indicator,$tagorder) = $sth->fetchrow) {
300 # &MARCdelsubfield($dbh,$bibid,$tag);
306 sub AUTHfind_authtypecode {
307 my ($dbh,$authid) = @_;
308 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
309 $sth->execute($authid);
310 my ($authtypecode) = $sth->fetchrow;
311 return $authtypecode;
316 my ($dbh,$forlibrarian,$authtypecode)= @_;
317 # warn "AUTH : $authtypecode";
318 $authtypecode="" unless $authtypecode;
319 # warn "AUTH : $authtypecode";
321 my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac';
322 # check that framework exists
323 $sth=$dbh->prepare("select count(*) from auth_tag_structure where authtypecode=?");
324 $sth->execute($authtypecode);
325 my ($total) = $sth->fetchrow;
326 $authtypecode="" unless ($total >0);
327 $sth=$dbh->prepare("select tagfield,$libfield as lib,mandatory,repeatable from auth_tag_structure where authtypecode=? order by tagfield");
328 $sth->execute($authtypecode);
329 my ($lib,$tag,$res,$tab,$mandatory,$repeatable);
330 while ( ($tag,$lib,$mandatory,$repeatable) = $sth->fetchrow) {
331 $res->{$tag}->{lib}=$lib;
332 $res->{$tab}->{tab}=""; # XXX
333 $res->{$tag}->{mandatory}=$mandatory;
334 $res->{$tag}->{repeatable}=$repeatable;
337 $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");
338 $sth->execute($authtypecode);
341 my $authorised_value;
342 my $thesaurus_category;
348 while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$value_builder,$seealso) = $sth->fetchrow) {
349 $res->{$tag}->{$subfield}->{lib}=$lib;
350 $res->{$tag}->{$subfield}->{tab}=$tab;
351 $res->{$tag}->{$subfield}->{mandatory}=$mandatory;
352 $res->{$tag}->{$subfield}->{repeatable}=$repeatable;
353 $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value;
354 $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category;
355 $res->{$tag}->{$subfield}->{value_builder}=$value_builder;
356 $res->{$tag}->{$subfield}->{seealso}=$seealso;
357 $res->{$tag}->{$subfield}->{hidden}=$hidden;
358 $res->{$tag}->{$subfield}->{isurl}=$isurl;
363 sub AUTHaddauthority {
364 # pass the MARC::Record to this function, and it will create the records in the marc tables
365 my ($dbh,$record,$authid,$authtypecode) = @_;
366 my @fields=$record->fields();
367 # warn "IN AUTHaddauthority $authid => ".$record->as_formatted;
368 # adding main table, and retrieving authid
369 # if authid is sent, then it's not a true add, it's only a re-add, after a delete (ie, a mod)
370 # if authid empty => true add, find a new authid number
372 $dbh->do("lock tables auth_header WRITE,auth_subfield_table WRITE, auth_word WRITE, stopwords READ");
373 my $sth=$dbh->prepare("insert into auth_header (datecreated,authtypecode) values (now(),?)");
374 $sth->execute($authtypecode);
375 $sth=$dbh->prepare("select max(authid) from auth_header");
377 ($authid)=$sth->fetchrow;
380 warn "auth : $authid";
382 # now, add subfields...
383 foreach my $field (@fields) {
385 if ($field->tag() <10) {
386 &AUTHaddsubfield($dbh,$authid,
395 my @subfields=$field->subfields();
396 foreach my $subfieldcount (0..$#subfields) {
397 &AUTHaddsubfield($dbh,$authid,
399 $field->indicator(1).$field->indicator(2),
401 $subfields[$subfieldcount][0],
403 $subfields[$subfieldcount][1]
408 $dbh->do("unlock tables");
413 sub AUTHaddsubfield {
414 # Add a new subfield to a tag into the DB.
415 my ($dbh,$authid,$tagid,$tag_indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalues) = @_;
416 # if not value, end of job, we do nothing
417 if (length($subfieldvalues) ==0) {
420 if (not($subfieldcode)) {
423 my @subfieldvalues = split /\|/,$subfieldvalues;
424 foreach my $subfieldvalue (@subfieldvalues) {
425 my $sth=$dbh->prepare("insert into auth_subfield_table (authid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue) values (?,?,?,?,?,?,?)");
426 $sth->execute($authid,(sprintf "%03s",$tagid),$tagorder,$tag_indicator,$subfieldcode,$subfieldorder,$subfieldvalue);
428 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";
430 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
434 sub AUTHgetauthority {
435 # Returns MARC::Record of the biblio passed in parameter.
436 my ($dbh,$authid)=@_;
437 my $record = MARC::Record->new();
438 #---- TODO : the leader is missing
439 $record->leader(' ');
440 my $sth=$dbh->prepare("select authid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue
441 from auth_subfield_table
442 where authid=? order by tag,tagorder,subfieldcode
444 $sth->execute($authid);
448 my $field; # for >=10 tags
449 my $prevvalue; # for <10 tags
450 while (my $row=$sth->fetchrow_hashref) {
451 if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag) {
454 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue) unless $prevtag eq "XXX"; # ignore the 1st loop
456 $record->add_fields($field) unless $prevtag eq "XXX";
459 $prevtagorder=$row->{tagorder};
460 $prevtag = $row->{tag};
461 $previndicator=$row->{tag_indicator};
462 if ($row->{tag}<10) {
463 $prevvalue = $row->{subfieldvalue};
465 $field = MARC::Field->new((sprintf "%03s",$prevtag), substr($row->{tag_indicator}.' ',0,1), substr($row->{tag_indicator}.' ',1,1), $row->{'subfieldcode'}, $row->{'subfieldvalue'} );
468 if ($row->{tag} <10) {
469 $record->add_fields((sprintf "%03s",$row->{tag}), $row->{'subfieldvalue'});
471 $field->add_subfields($row->{'subfieldcode'}, $row->{'subfieldvalue'} );
473 $prevtag= $row->{tag};
474 $previndicator=$row->{tag_indicator};
477 # the last has not been included inside the loop... do it now !
478 if ($prevtag ne "XXX") { # check that we have found something. Otherwise, prevtag is still XXX and we
479 # must return an empty record, not make MARC::Record fail because we try to
480 # create a record with XXX as field :-(
482 $record->add_fields($prevtag,$prevvalue);
484 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
485 $record->add_fields($field);
491 sub AUTHmodauthority {
492 my ($dbh,$authid,$record,$delete)=@_;
493 my $oldrecord=&AUTHgetauthority($dbh,$authid);
494 if ($oldrecord eq $record) {
497 # 1st delete the authority,
499 &AUTHdelauthority($dbh,$authid,1);
500 &AUTHaddauthority($dbh,$record,$authid);
501 # FIXME : modify the authority in biblio too.
504 sub AUTHdelauthority {
505 my ($dbh,$authid,$keep_biblio) = @_;
506 # if the keep_biblio is set to 1, then authority entries in biblio are preserved.
507 # This flag is set when the delauthority is called by modauthority
508 # due to a too complex structure of MARC (repeatable fields and subfields),
509 # the best solution for a modif is to delete / recreate the record.
511 my $record = AUTHgetauthority($dbh,$authid);
512 $dbh->do("delete from auth_header where authid=$authid");
513 $dbh->do("delete from auth_subfield_table where authid=$authid");
514 $dbh->do("delete from auth_word where authid=$authid");
515 # FIXME : delete or not in biblio tables (depending on $keep_biblio flag)
518 sub AUTHmodsubfield {
519 # Subroutine changes a subfield value given a subfieldid.
520 my ($dbh, $subfieldid, $subfieldvalue )=@_;
521 $dbh->do("lock tables auth_subfield_table WRITE");
522 my $sth=$dbh->prepare("update auth_subfield_table set subfieldvalue=? where subfieldid=?");
523 $sth->execute($subfieldvalue, $subfieldid);
524 $dbh->do("unlock tables");
526 $sth=$dbh->prepare("select authid,tag,tagorder,subfieldcode,subfieldid,subfieldorder from auth_subfield_table where subfieldid=?");
527 $sth->execute($subfieldid);
528 my ($authid,$tagid,$tagorder,$subfieldcode,$x,$subfieldorder) = $sth->fetchrow;
530 &AUTHdelword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder);
531 &AUTHaddword($dbh,$authid,$tagid,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
532 return($subfieldid, $subfieldvalue);
535 sub AUTHfindsubfield {
536 my ($dbh,$authid,$tag,$subfieldcode,$subfieldorder,$subfieldvalue) = @_;
540 my $query="select subfieldid from auth_subfield_table where authid=? and tag=? and subfieldcode=?";
541 my @bind_values = ($authid,$tag, $subfieldcode);
542 if ($subfieldvalue) {
543 $query .= " and subfieldvalue=?";
544 push(@bind_values,$subfieldvalue);
546 if ($subfieldorder<1) {
549 $query .= " and subfieldorder=?";
550 push(@bind_values,$subfieldorder);
552 my $sti=$dbh->prepare($query);
553 $sti->execute(@bind_values);
554 while (($subfieldid) = $sti->fetchrow) {
556 $lastsubfieldid=$subfieldid;
558 if ($resultcounter>1) {
559 # Error condition. Values given did not resolve into a unique record. Don't know what to edit
560 # should rarely occur (only if we use subfieldvalue with a value that exists twice, which is strange)
563 return $lastsubfieldid;
567 sub AUTHfindsubfieldid {
568 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
569 my $sth=$dbh->prepare("select subfieldid from auth_subfield_table
570 where authid=? and tag=? and tagorder=?
571 and subfieldcode=? and subfieldorder=?");
572 $sth->execute($authid,$tag,$tagorder,$subfield,$subfieldorder);
573 my ($res) = $sth->fetchrow;
575 $sth=$dbh->prepare("select subfieldid from auth_subfield_table
576 where authid=? and tag=? and tagorder=?
577 and subfieldcode=?");
578 $sth->execute($authid,$tag,$tagorder,$subfield);
579 ($res) = $sth->fetchrow;
584 sub AUTHfind_authtypecode {
585 my ($dbh,$authid) = @_;
586 my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?");
587 $sth->execute($authid);
588 my ($authtypecode) = $sth->fetchrow;
589 return $authtypecode;
592 sub AUTHdelsubfield {
593 # delete a subfield for $authid / tag / tagorder / subfield / subfieldorder
594 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
595 $dbh->do("delete from auth_subfield_table where authid='$authid' and
596 tag='$tag' and tagorder='$tagorder'
597 and subfieldcode='$subfield' and subfieldorder='$subfieldorder'
602 my ($dbh,$rtags,$rsubfields,$rvalues,%indicators) = @_;
604 my $record = MARC::Record->new();
605 # my %subfieldlist=();
606 my $prevvalue; # if tag <10
607 my $field; # if tag >=10
608 for (my $i=0; $i< @$rtags; $i++) {
609 # rebuild MARC::Record
610 if (@$rtags[$i] ne $prevtag) {
613 $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
617 $record->add_fields($field);
620 $indicators{@$rtags[$i]}.=' ';
621 if (@$rtags[$i] <10) {
622 $prevvalue= @$rvalues[$i];
624 $field = MARC::Field->new( (sprintf "%03s",@$rtags[$i]), substr($indicators{@$rtags[$i]},0,1),substr($indicators{@$rtags[$i]},1,1), @$rsubfields[$i] => @$rvalues[$i]);
626 $prevtag = @$rtags[$i];
628 if (@$rtags[$i] <10) {
629 $prevvalue=@$rvalues[$i];
632 $field->add_subfields(@$rsubfields[$i] => @$rvalues[$i]);
635 $prevtag= @$rtags[$i];
638 # the last has not been included inside the loop... do it now !
639 $record->add_fields($field);
640 # warn $record->as_formatted;
645 # split a subfield string and adds it into the word table.
647 my ($dbh,$authid,$tag,$tagorder,$subfieldid,$subfieldorder,$sentence) =@_;
648 $sentence =~ s/(\.|\?|\:|\!|\'|,|\-|\"|\(|\)|\[|\]|\{|\})/ /g;
649 my @words = split / /,$sentence;
650 my $stopwords= C4::Context->stopwords;
651 my $sth=$dbh->prepare("insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word)
652 values (?,concat(?,?),?,?,?,soundex(?))");
653 foreach my $word (@words) {
654 # we record only words longer than 2 car and not in stopwords hash
655 if (length($word)>2 and !($stopwords->{uc($word)})) {
656 $sth->execute($authid,$tag,$subfieldid,$tagorder,$subfieldorder,$word,$word);
658 warn "ERROR ==> insert into auth_word (authid, tagsubfield, tagorder, subfieldorder, word, sndx_word) values ($authid,concat($tag,$subfieldid),$tagorder,$subfieldorder,$word,soundex($word))\n";
665 # delete words. this sub deletes all the words from a sentence. a subfield modif is done by a delete then a add
666 my ($dbh,$authid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
667 my $sth=$dbh->prepare("delete from auth_word where authid=? and tagsubfield=concat(?,?) and tagorder=? and subfieldorder=?");
668 $sth->execute($authid,$tag,$subfield,$tagorder,$subfieldorder);
672 # converts ISO 5426 coded string to ISO 8859-1
673 # sloppy code : should be improved in next issue
674 my ($string,$encoding) = @_ ;
676 # $encoding = C4::Context->preference("marcflavour") unless $encoding;
677 if ($encoding eq "UNIMARC") {
739 # this handles non-sorting blocks (if implementation requires this)
740 $string = nsb_clean($_) ;
741 } elsif ($encoding eq "USMARC" || $encoding eq "MARC21") {
794 # this handles non-sorting blocks (if implementation requires this)
795 $string = nsb_clean($_) ;
802 my $NSB = '\x88' ; # NSB : begin Non Sorting Block
803 my $NSE = '\x89' ; # NSE : Non Sorting Block end
804 # handles non sorting blocks
808 s/[ ]{0,1}$NSE/) /gm ;
813 END { } # module clean-up code here (global destructor)
819 Koha Developement team <info@koha.org>
821 Paul POULAIN paul.poulain@free.fr
827 # Revision 1.4 2004/06/22 11:35:37 tipaul
828 # removing % at the beginning of a string to avoid loooonnnngggg searchs
830 # Revision 1.3 2004/06/17 08:02:13 tipaul
831 # merging tag & subfield in auth_word for better perfs
833 # Revision 1.2 2004/06/10 08:29:01 tipaul
834 # MARC authority management (continued)
836 # Revision 1.1 2004/06/07 07:35:01 tipaul
837 # MARC authority management package