-=head2 _DelBiblioNoZebra($biblionumber,$record,$server);
-
-function to delete a biblio in NoZebra indexes
-This function does NOT delete anything in database : it reads all the indexes entries
-that have to be deleted & delete them in the hash
-
-The SQL part is done either :
- - after the Add if we are modifying a biblio (delete + add again)
- - immediatly after this sub if we are doing a true deletion.
-
-$server can be 'biblioserver' or 'authorityserver' : it indexes biblios or authorities (in the same table, $server being part of the table itself
-
-=cut
-
-sub _DelBiblioNoZebra {
- my ( $biblionumber, $record, $server ) = @_;
-
- # Get the indexes
- my $dbh = C4::Context->dbh;
-
- # Get the indexes
- my %index;
- my $title;
- if ( $server eq 'biblioserver' ) {
- %index = GetNoZebraIndexes;
-
- # get title of the record (to store the 10 first letters with the index)
- my ( $titletag, $titlesubfield ) = GetMarcFromKohaField( 'biblio.title', '' ); # FIXME: should be GetFrameworkCode($biblionumber) ??
- $title = lc( $record->subfield( $titletag, $titlesubfield ) );
- } else {
-
- # for authorities, the "title" is the $a mainentry
- my ( $auth_type_tag, $auth_type_sf ) = C4::AuthoritiesMarc::get_auth_type_location();
- my $authref = C4::AuthoritiesMarc::GetAuthType( $record->subfield( $auth_type_tag, $auth_type_sf ) );
- warn "ERROR : authtype undefined for " . $record->as_formatted unless $authref;
- $title = $record->subfield( $authref->{auth_tag_to_report}, 'a' );
- $index{'mainmainentry'} = $authref->{'auth_tag_to_report'} . 'a';
- $index{'mainentry'} = $authref->{'auth_tag_to_report'} . '*';
- $index{'auth_type'} = "${auth_type_tag}${auth_type_sf}";
- }
-
- my %result;
-
- # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
- $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
-
- # limit to 10 char, should be enough, and limit the DB size
- $title = substr( $title, 0, 10 );
-
- #parse each field
- my $sth2 = $dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
- foreach my $field ( $record->fields() ) {
-
- #parse each subfield
- next if $field->tag < 10;
- foreach my $subfield ( $field->subfields() ) {
- my $tag = $field->tag();
- my $subfieldcode = $subfield->[0];
- my $indexed = 0;
-
- # check each index to see if the subfield is stored somewhere
- # otherwise, store it in __RAW__ index
- foreach my $key ( keys %index ) {
-
- # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
- if ( $index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/ ) {
- $indexed = 1;
- my $line = lc $subfield->[1];
-
- # remove meaningless value in the field...
- $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
-
- # ... and split in words
- foreach ( split / /, $line ) {
- next unless $_; # skip empty values (multiple spaces)
- # if the entry is already here, do nothing, the biblionumber has already be removed
- unless ( defined( $result{$key}->{$_} ) && ( $result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/ ) ) {
-
- # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
- $sth2->execute( $server, $key, $_ );
- my $existing_biblionumbers = $sth2->fetchrow;
-
- # it exists
- if ($existing_biblionumbers) {
-
- # warn " existing for $key $_: $existing_biblionumbers";
- $result{$key}->{$_} = $existing_biblionumbers;
- $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
- }
- }
- }
- }
- }
-
- # the subfield is not indexed, store it in __RAW__ index anyway
- unless ($indexed) {
- my $line = lc $subfield->[1];
- $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
-
- # ... and split in words
- foreach ( split / /, $line ) {
- next unless $_; # skip empty values (multiple spaces)
- # if the entry is already here, do nothing, the biblionumber has already be removed
- unless ( $result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/ ) {
-
- # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
- $sth2->execute( $server, '__RAW__', $_ );
- my $existing_biblionumbers = $sth2->fetchrow;
-
- # it exists
- if ($existing_biblionumbers) {
- $result{'__RAW__'}->{$_} = $existing_biblionumbers;
- $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
- }
- }
- }
- }
- }
- }
- return %result;
-}
-
-=head2 _AddBiblioNoZebra
-
- _AddBiblioNoZebra($biblionumber, $record, $server, %result);
-
-function to add a biblio in NoZebra indexes
-
-=cut
-
-sub _AddBiblioNoZebra {
- my ( $biblionumber, $record, $server, %result ) = @_;
- my $dbh = C4::Context->dbh;
-
- # Get the indexes
- my %index;
- my $title;
- if ( $server eq 'biblioserver' ) {
- %index = GetNoZebraIndexes;
-
- # get title of the record (to store the 10 first letters with the index)
- my ( $titletag, $titlesubfield ) = GetMarcFromKohaField( 'biblio.title', '' ); # FIXME: should be GetFrameworkCode($biblionumber) ??
- $title = lc( $record->subfield( $titletag, $titlesubfield ) );
- } else {
-
- # warn "server : $server";
- # for authorities, the "title" is the $a mainentry
- my ( $auth_type_tag, $auth_type_sf ) = C4::AuthoritiesMarc::get_auth_type_location();
- my $authref = C4::AuthoritiesMarc::GetAuthType( $record->subfield( $auth_type_tag, $auth_type_sf ) );
- warn "ERROR : authtype undefined for " . $record->as_formatted unless $authref;
- $title = $record->subfield( $authref->{auth_tag_to_report}, 'a' );
- $index{'mainmainentry'} = $authref->{auth_tag_to_report} . 'a';
- $index{'mainentry'} = $authref->{auth_tag_to_report} . '*';
- $index{'auth_type'} = "${auth_type_tag}${auth_type_sf}";
- }
-
- # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
- $title =~ s/ |\.|,|;|\[|\]|\(|\)|\*|-|'|:|=|\r|\n//g;
-
- # limit to 10 char, should be enough, and limit the DB size
- $title = substr( $title, 0, 10 );
-
- #parse each field
- my $sth2 = $dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
- foreach my $field ( $record->fields() ) {
-
- #parse each subfield
- ###FIXME: impossible to index a 001-009 value with NoZebra
- next if $field->tag < 10;
- foreach my $subfield ( $field->subfields() ) {
- my $tag = $field->tag();
- my $subfieldcode = $subfield->[0];
- my $indexed = 0;
-
- # warn "INDEXING :".$subfield->[1];
- # check each index to see if the subfield is stored somewhere
- # otherwise, store it in __RAW__ index
- foreach my $key ( keys %index ) {
-
- # warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
- if ( $index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/ ) {
- $indexed = 1;
- my $line = lc $subfield->[1];
-
- # remove meaningless value in the field...
- $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
-
- # ... and split in words
- foreach ( split / /, $line ) {
- next unless $_; # skip empty values (multiple spaces)
- # if the entry is already here, improve weight
-
- # warn "managing $_";
- if ( exists $result{$key}->{$_} && $result{$key}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/ ) {
- my $weight = $1 + 1;
- $result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
- $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
- } else {
-
- # get the value if it exist in the nozebra table, otherwise, create it
- $sth2->execute( $server, $key, $_ );
- my $existing_biblionumbers = $sth2->fetchrow;
-
- # it exists
- if ($existing_biblionumbers) {
- $result{$key}->{"$_"} = $existing_biblionumbers;
- my $weight = defined $1 ? $1 + 1 : 1;
- $result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
- $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
-
- # create a new ligne for this entry
- } else {
-
- # warn "INSERT : $server / $key / $_";
- $dbh->do( 'INSERT INTO nozebra SET server=' . $dbh->quote($server) . ', indexname=' . $dbh->quote($key) . ',value=' . $dbh->quote($_) );
- $result{$key}->{"$_"} .= "$biblionumber,$title-1;";
- }
- }
- }
- }
- }
-
- # the subfield is not indexed, store it in __RAW__ index anyway
- unless ($indexed) {
- my $line = lc $subfield->[1];
- $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
-
- # ... and split in words
- foreach ( split / /, $line ) {
- next unless $_; # skip empty values (multiple spaces)
- # if the entry is already here, improve weight
- my $tmpstr = $result{'__RAW__'}->{"$_"} || "";
- if ( $tmpstr =~ /$biblionumber,\Q$title\E\-(\d+);/ ) {
- my $weight = $1 + 1;
- $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
- $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
- } else {
-
- # get the value if it exist in the nozebra table, otherwise, create it
- $sth2->execute( $server, '__RAW__', $_ );
- my $existing_biblionumbers = $sth2->fetchrow;
-
- # it exists
- if ($existing_biblionumbers) {
- $result{'__RAW__'}->{"$_"} = $existing_biblionumbers;
- my $weight = ( $1 ? $1 : 0 ) + 1;
- $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
- $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
-
- # create a new ligne for this entry
- } else {
- $dbh->do( 'INSERT INTO nozebra SET server=' . $dbh->quote($server) . ', indexname="__RAW__",value=' . $dbh->quote($_) );
- $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-1;";
- }
- }
- }
- }
- }
- }
- return %result;
-}
-