View | Details | Raw Unified | Return to bug 7430
Collapse All | Expand All

(-)a/C4/AuthoritiesMarc.pm (-28 / +4 lines)
Lines 26-31 use C4::AuthoritiesMarc::MARC21; Link Here
26
use C4::AuthoritiesMarc::UNIMARC;
26
use C4::AuthoritiesMarc::UNIMARC;
27
use C4::Charset;
27
use C4::Charset;
28
use C4::Log;
28
use C4::Log;
29
use Koha::Utils;
30
use Koha::Search;
29
31
30
use vars qw($VERSION @ISA @EXPORT);
32
use vars qw($VERSION @ISA @EXPORT);
31
33
Lines 37-43 BEGIN { Link Here
37
	@ISA = qw(Exporter);
39
	@ISA = qw(Exporter);
38
	@EXPORT = qw(
40
	@EXPORT = qw(
39
	    &GetTagsLabels
41
	    &GetTagsLabels
40
	    &GetAuthType
41
	    &GetAuthTypeCode
42
	    &GetAuthTypeCode
42
    	&GetAuthMARCFromKohaField 
43
    	&GetAuthMARCFromKohaField 
43
44
Lines 729-735 sub AddAuthority { Link Here
729
    $sth->finish;
730
    $sth->finish;
730
    logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
731
    logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
731
  }
732
  }
732
  ModZebra($authid,'specialUpdate',"authorityserver",$oldRecord,$record);
733
  AddToIndexQueue($authid,'specialUpdate',"authorityserver",$oldRecord,$record);
733
  return ($authid);
734
  return ($authid);
734
}
735
}
735
736
Lines 747-753 sub DelAuthority { Link Here
747
    my $dbh=C4::Context->dbh;
748
    my $dbh=C4::Context->dbh;
748
749
749
    logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
750
    logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
750
    ModZebra($authid,"recordDelete","authorityserver",GetAuthority($authid),undef);
751
    AddToIndexQueue($authid,"recordDelete","authorityserver",GetAuthority($authid),undef);
751
    my $sth = $dbh->prepare("DELETE FROM auth_header WHERE authid=?");
752
    my $sth = $dbh->prepare("DELETE FROM auth_header WHERE authid=?");
752
    $sth->execute($authid);
753
    $sth->execute($authid);
753
}
754
}
Lines 839-869 sub GetAuthority { Link Here
839
    return ($record);
840
    return ($record);
840
}
841
}
841
842
842
=head2 GetAuthType 
843
844
  $result = &GetAuthType($authtypecode)
845
846
If the authority type specified by C<$authtypecode> exists,
847
returns a hashref of the type's fields.  If the type
848
does not exist, returns undef.
849
850
=cut
851
852
sub GetAuthType {
853
    my ($authtypecode) = @_;
854
    my $dbh=C4::Context->dbh;
855
    my $sth;
856
    if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority 
857
                                # type (FIXME but why?)
858
        $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
859
        $sth->execute($authtypecode);
860
        if (my $res = $sth->fetchrow_hashref) {
861
            return $res; 
862
        }
863
    }
864
    return;
865
}
866
867
843
868
=head2 FindDuplicateAuthority
844
=head2 FindDuplicateAuthority
869
845
(-)a/C4/Biblio.pm (-359 / +6 lines)
Lines 39-44 use C4::Linker; Link Here
39
require C4::Heading;
39
require C4::Heading;
40
require C4::Serials;
40
require C4::Serials;
41
require C4::Items;
41
require C4::Items;
42
use Koha::Search;
43
use Koha::Utils;
42
44
43
use vars qw($VERSION @ISA @EXPORT);
45
use vars qw($VERSION @ISA @EXPORT);
44
46
Lines 89-95 BEGIN { Link Here
89
91
90
      &GetAuthorisedValueDesc
92
      &GetAuthorisedValueDesc
91
      &GetMarcStructure
93
      &GetMarcStructure
92
      &GetMarcFromKohaField
93
      &GetFrameworkCode
94
      &GetFrameworkCode
94
      &TransformKohaToMarc
95
      &TransformKohaToMarc
95
      &PrepHostMarcField
96
      &PrepHostMarcField
Lines 134-140 BEGIN { Link Here
134
      &TransformHtmlToMarc
135
      &TransformHtmlToMarc
135
      &TransformHtmlToXml
136
      &TransformHtmlToXml
136
      &PrepareItemrecordDisplay
137
      &PrepareItemrecordDisplay
137
      &GetNoZebraIndexes
138
    );
138
    );
139
}
139
}
140
140
Lines 436-442 sub DelBiblio { Link Here
436
        # the previous version of the record
436
        # the previous version of the record
437
        $oldRecord = GetMarcBiblio($biblionumber);
437
        $oldRecord = GetMarcBiblio($biblionumber);
438
    }
438
    }
439
    ModZebra( $biblionumber, "recordDelete", "biblioserver", $oldRecord, undef );
439
    AddToIndexQueue( $biblionumber, "recordDelete", "biblioserver", $oldRecord, undef );
440
440
441
    # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
441
    # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
442
    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
442
    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
Lines 540-546 sub LinkBibHeadingsToAuthorities { Link Here
540
            if (defined $current_link && C4::Context->preference('LinkerKeepStale')) {
540
            if (defined $current_link && C4::Context->preference('LinkerKeepStale')) {
541
                $results{'fuzzy'}->{$heading->display_form()}++;
541
                $results{'fuzzy'}->{$heading->display_form()}++;
542
            } elsif (C4::Context->preference('AutoCreateAuthorities')) {
542
            } elsif (C4::Context->preference('AutoCreateAuthorities')) {
543
                my $authtypedata=C4::AuthoritiesMarc::GetAuthType($heading->auth_type());
543
                my $authtypedata=GetAuthType($heading->auth_type());
544
                my $marcrecordauth=MARC::Record->new();
544
                my $marcrecordauth=MARC::Record->new();
545
                if (C4::Context->preference('marcflavour') eq 'MARC21') {
545
                if (C4::Context->preference('marcflavour') eq 'MARC21') {
546
                    $marcrecordauth->leader('     nz  a22     o  4500');
546
                    $marcrecordauth->leader('     nz  a22     o  4500');
Lines 1107-1128 sub GetUsedMarcStructure($) { Link Here
1107
    return $sth->fetchall_arrayref( {} );
1107
    return $sth->fetchall_arrayref( {} );
1108
}
1108
}
1109
1109
1110
=head2 GetMarcFromKohaField
1111
1112
  ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
1113
1114
Returns the MARC fields & subfields mapped to the koha field 
1115
for the given frameworkcode
1116
1117
=cut
1118
1119
sub GetMarcFromKohaField {
1120
    my ( $kohafield, $frameworkcode ) = @_;
1121
    return 0, 0 unless $kohafield and defined $frameworkcode;
1122
    my $relations = C4::Context->marcfromkohafield;
1123
    return ( $relations->{$frameworkcode}->{$kohafield}->[0], $relations->{$frameworkcode}->{$kohafield}->[1] );
1124
}
1125
1126
=head2 GetMarcBiblio
1110
=head2 GetMarcBiblio
1127
1111
1128
  my $record = GetMarcBiblio($biblionumber, [$embeditems]);
1112
  my $record = GetMarcBiblio($biblionumber, [$embeditems]);
Lines 2819-2906 $newRecord is the MARC::Record containing the new record. It is usefull only whe Link Here
2819
2803
2820
sub ModZebra {
2804
sub ModZebra {
2821
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2805
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2822
    my ( $biblionumber, $op, $server, $oldRecord, $newRecord ) = @_;
2823
    my $dbh = C4::Context->dbh;
2824
2806
2825
    # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2807
    # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2826
    # at the same time
2808
    # at the same time
2827
    # replaced by a zebraqueue table, that is filled with ModZebra to run.
2809
    # replaced by a zebraqueue table, that is filled with ModZebra to run.
2828
    # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2810
    # the table is emptied by misc/cronjobs/zebraqueue_start.pl script
2811
    AddToIndexQueue(@_)
2829
2812
2830
    if ( C4::Context->preference("NoZebra") ) {
2831
2832
        # lock the nozebra table : we will read index lines, update them in Perl process
2833
        # and write everything in 1 transaction.
2834
        # lock the table to avoid someone else overwriting what we are doing
2835
        $dbh->do('LOCK TABLES nozebra WRITE,biblio WRITE,biblioitems WRITE, systempreferences WRITE, auth_types WRITE, auth_header WRITE, auth_subfield_structure READ');
2836
        my %result;    # the result hash that will be built by deletion / add, and written on mySQL at the end, to improve speed
2837
        if ( $op eq 'specialUpdate' ) {
2838
2839
            # OK, we have to add or update the record
2840
            # 1st delete (virtually, in indexes), if record actually exists
2841
            if ($oldRecord) {
2842
                %result = _DelBiblioNoZebra( $biblionumber, $oldRecord, $server );
2843
            }
2844
2845
            # ... add the record
2846
            %result = _AddBiblioNoZebra( $biblionumber, $newRecord, $server, %result );
2847
        } else {
2848
2849
            # it's a deletion, delete the record...
2850
            # warn "DELETE the record $biblionumber on $server".$record->as_formatted;
2851
            %result = _DelBiblioNoZebra( $biblionumber, $oldRecord, $server );
2852
        }
2853
2854
        # ok, now update the database...
2855
        my $sth = $dbh->prepare("UPDATE nozebra SET biblionumbers=? WHERE server=? AND indexname=? AND value=?");
2856
        foreach my $key ( keys %result ) {
2857
            foreach my $index ( keys %{ $result{$key} } ) {
2858
                $sth->execute( $result{$key}->{$index}, $server, $key, $index );
2859
            }
2860
        }
2861
        $dbh->do('UNLOCK TABLES');
2862
    } else {
2863
2864
        #
2865
        # we use zebra, just fill zebraqueue table
2866
        #
2867
        my $check_sql = "SELECT COUNT(*) FROM zebraqueue 
2868
                         WHERE server = ?
2869
                         AND   biblio_auth_number = ?
2870
                         AND   operation = ?
2871
                         AND   done = 0";
2872
        my $check_sth = $dbh->prepare_cached($check_sql);
2873
        $check_sth->execute( $server, $biblionumber, $op );
2874
        my ($count) = $check_sth->fetchrow_array;
2875
        $check_sth->finish();
2876
        if ( $count == 0 ) {
2877
            my $sth = $dbh->prepare("INSERT INTO zebraqueue  (biblio_auth_number,server,operation) VALUES(?,?,?)");
2878
            $sth->execute( $biblionumber, $server, $op );
2879
            $sth->finish;
2880
        }
2881
    }
2882
}
2883
2884
=head2 GetNoZebraIndexes
2885
2886
  %indexes = GetNoZebraIndexes;
2887
2888
return the data from NoZebraIndexes syspref.
2889
2890
=cut
2891
2892
sub GetNoZebraIndexes {
2893
    my $no_zebra_indexes = C4::Context->preference('NoZebraIndexes');
2894
    my %indexes;
2895
  INDEX: foreach my $line ( split /['"],[\n\r]*/, $no_zebra_indexes ) {
2896
        $line =~ /(.*)=>(.*)/;
2897
        my $index  = $1;    # initial ' or " is removed afterwards
2898
        my $fields = $2;
2899
        $index  =~ s/'|"|\s//g;
2900
        $fields =~ s/'|"|\s//g;
2901
        $indexes{$index} = $fields;
2902
    }
2903
    return %indexes;
2904
}
2813
}
2905
2814
2906
=head2 EmbedItemsInMarcBiblio
2815
=head2 EmbedItemsInMarcBiblio
Lines 2935-3202 sub EmbedItemsInMarcBiblio { Link Here
2935
2844
2936
=head1 INTERNAL FUNCTIONS
2845
=head1 INTERNAL FUNCTIONS
2937
2846
2938
=head2 _DelBiblioNoZebra($biblionumber,$record,$server);
2939
2940
function to delete a biblio in NoZebra indexes
2941
This function does NOT delete anything in database : it reads all the indexes entries
2942
that have to be deleted & delete them in the hash
2943
2944
The SQL part is done either :
2945
 - after the Add if we are modifying a biblio (delete + add again)
2946
 - immediatly after this sub if we are doing a true deletion.
2947
2948
$server can be 'biblioserver' or 'authorityserver' : it indexes biblios or authorities (in the same table, $server being part of the table itself
2949
2950
=cut
2951
2952
sub _DelBiblioNoZebra {
2953
    my ( $biblionumber, $record, $server ) = @_;
2954
2955
    # Get the indexes
2956
    my $dbh = C4::Context->dbh;
2957
2958
    # Get the indexes
2959
    my %index;
2960
    my $title;
2961
    if ( $server eq 'biblioserver' ) {
2962
        %index = GetNoZebraIndexes;
2963
2964
        # get title of the record (to store the 10 first letters with the index)
2965
        my ( $titletag, $titlesubfield ) = GetMarcFromKohaField( 'biblio.title', '' );    # FIXME: should be GetFrameworkCode($biblionumber) ??
2966
        $title = lc( $record->subfield( $titletag, $titlesubfield ) );
2967
    } else {
2968
2969
        # for authorities, the "title" is the $a mainentry
2970
        my ( $auth_type_tag, $auth_type_sf ) = C4::AuthoritiesMarc::get_auth_type_location();
2971
        my $authref = C4::AuthoritiesMarc::GetAuthType( $record->subfield( $auth_type_tag, $auth_type_sf ) );
2972
        warn "ERROR : authtype undefined for " . $record->as_formatted unless $authref;
2973
        $title = $record->subfield( $authref->{auth_tag_to_report}, 'a' );
2974
        $index{'mainmainentry'} = $authref->{'auth_tag_to_report'} . 'a';
2975
        $index{'mainentry'}     = $authref->{'auth_tag_to_report'} . '*';
2976
        $index{'auth_type'}     = "${auth_type_tag}${auth_type_sf}";
2977
    }
2978
2979
    my %result;
2980
2981
    # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
2982
    $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
2983
2984
    # limit to 10 char, should be enough, and limit the DB size
2985
    $title = substr( $title, 0, 10 );
2986
2987
    #parse each field
2988
    my $sth2 = $dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
2989
    foreach my $field ( $record->fields() ) {
2990
2991
        #parse each subfield
2992
        next if $field->tag < 10;
2993
        foreach my $subfield ( $field->subfields() ) {
2994
            my $tag          = $field->tag();
2995
            my $subfieldcode = $subfield->[0];
2996
            my $indexed      = 0;
2997
2998
            # check each index to see if the subfield is stored somewhere
2999
            # otherwise, store it in __RAW__ index
3000
            foreach my $key ( keys %index ) {
3001
3002
                #                 warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
3003
                if ( $index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/ ) {
3004
                    $indexed = 1;
3005
                    my $line = lc $subfield->[1];
3006
3007
                    # remove meaningless value in the field...
3008
                    $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3009
3010
                    # ... and split in words
3011
                    foreach ( split / /, $line ) {
3012
                        next unless $_;    # skip  empty values (multiple spaces)
3013
                                           # if the entry is already here, do nothing, the biblionumber has already be removed
3014
                        unless ( defined( $result{$key}->{$_} ) && ( $result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/ ) ) {
3015
3016
                            # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
3017
                            $sth2->execute( $server, $key, $_ );
3018
                            my $existing_biblionumbers = $sth2->fetchrow;
3019
3020
                            # it exists
3021
                            if ($existing_biblionumbers) {
3022
3023
                                #                                 warn " existing for $key $_: $existing_biblionumbers";
3024
                                $result{$key}->{$_} = $existing_biblionumbers;
3025
                                $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
3026
                            }
3027
                        }
3028
                    }
3029
                }
3030
            }
3031
3032
            # the subfield is not indexed, store it in __RAW__ index anyway
3033
            unless ($indexed) {
3034
                my $line = lc $subfield->[1];
3035
                $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
3036
3037
                # ... and split in words
3038
                foreach ( split / /, $line ) {
3039
                    next unless $_;    # skip  empty values (multiple spaces)
3040
                                       # if the entry is already here, do nothing, the biblionumber has already be removed
3041
                    unless ( $result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/ ) {
3042
3043
                        # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
3044
                        $sth2->execute( $server, '__RAW__', $_ );
3045
                        my $existing_biblionumbers = $sth2->fetchrow;
3046
3047
                        # it exists
3048
                        if ($existing_biblionumbers) {
3049
                            $result{'__RAW__'}->{$_} = $existing_biblionumbers;
3050
                            $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
3051
                        }
3052
                    }
3053
                }
3054
            }
3055
        }
3056
    }
3057
    return %result;
3058
}
3059
3060
=head2 _AddBiblioNoZebra
3061
3062
  _AddBiblioNoZebra($biblionumber, $record, $server, %result);
3063
3064
function to add a biblio in NoZebra indexes
3065
3066
=cut
3067
3068
sub _AddBiblioNoZebra {
3069
    my ( $biblionumber, $record, $server, %result ) = @_;
3070
    my $dbh = C4::Context->dbh;
3071
3072
    # Get the indexes
3073
    my %index;
3074
    my $title;
3075
    if ( $server eq 'biblioserver' ) {
3076
        %index = GetNoZebraIndexes;
3077
3078
        # get title of the record (to store the 10 first letters with the index)
3079
        my ( $titletag, $titlesubfield ) = GetMarcFromKohaField( 'biblio.title', '' );    # FIXME: should be GetFrameworkCode($biblionumber) ??
3080
        $title = lc( $record->subfield( $titletag, $titlesubfield ) );
3081
    } else {
3082
3083
        # warn "server : $server";
3084
        # for authorities, the "title" is the $a mainentry
3085
        my ( $auth_type_tag, $auth_type_sf ) = C4::AuthoritiesMarc::get_auth_type_location();
3086
        my $authref = C4::AuthoritiesMarc::GetAuthType( $record->subfield( $auth_type_tag, $auth_type_sf ) );
3087
        warn "ERROR : authtype undefined for " . $record->as_formatted unless $authref;
3088
        $title = $record->subfield( $authref->{auth_tag_to_report}, 'a' );
3089
        $index{'mainmainentry'} = $authref->{auth_tag_to_report} . 'a';
3090
        $index{'mainentry'}     = $authref->{auth_tag_to_report} . '*';
3091
        $index{'auth_type'}     = "${auth_type_tag}${auth_type_sf}";
3092
    }
3093
3094
    # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
3095
    $title =~ s/ |\.|,|;|\[|\]|\(|\)|\*|-|'|:|=|\r|\n//g;
3096
3097
    # limit to 10 char, should be enough, and limit the DB size
3098
    $title = substr( $title, 0, 10 );
3099
3100
    #parse each field
3101
    my $sth2 = $dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
3102
    foreach my $field ( $record->fields() ) {
3103
3104
        #parse each subfield
3105
        ###FIXME: impossible to index a 001-009 value with NoZebra
3106
        next if $field->tag < 10;
3107
        foreach my $subfield ( $field->subfields() ) {
3108
            my $tag          = $field->tag();
3109
            my $subfieldcode = $subfield->[0];
3110
            my $indexed      = 0;
3111
3112
            #             warn "INDEXING :".$subfield->[1];
3113
            # check each index to see if the subfield is stored somewhere
3114
            # otherwise, store it in __RAW__ index
3115
            foreach my $key ( keys %index ) {
3116
3117
                #                 warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
3118
                if ( $index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/ ) {
3119
                    $indexed = 1;
3120
                    my $line = lc $subfield->[1];
3121
3122
                    # remove meaningless value in the field...
3123
                    $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
3124
3125
                    # ... and split in words
3126
                    foreach ( split / /, $line ) {
3127
                        next unless $_;    # skip  empty values (multiple spaces)
3128
                                           # if the entry is already here, improve weight
3129
3130
                        #                         warn "managing $_";
3131
                        if ( exists $result{$key}->{$_} && $result{$key}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/ ) {
3132
                            my $weight = $1 + 1;
3133
                            $result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
3134
                            $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
3135
                        } else {
3136
3137
                            # get the value if it exist in the nozebra table, otherwise, create it
3138
                            $sth2->execute( $server, $key, $_ );
3139
                            my $existing_biblionumbers = $sth2->fetchrow;
3140
3141
                            # it exists
3142
                            if ($existing_biblionumbers) {
3143
                                $result{$key}->{"$_"} = $existing_biblionumbers;
3144
                                my $weight = defined $1 ? $1 + 1 : 1;
3145
                                $result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
3146
                                $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
3147
3148
                                # create a new ligne for this entry
3149
                            } else {
3150
3151
                                #                             warn "INSERT : $server / $key / $_";
3152
                                $dbh->do( 'INSERT INTO nozebra SET server=' . $dbh->quote($server) . ', indexname=' . $dbh->quote($key) . ',value=' . $dbh->quote($_) );
3153
                                $result{$key}->{"$_"} .= "$biblionumber,$title-1;";
3154
                            }
3155
                        }
3156
                    }
3157
                }
3158
            }
3159
3160
            # the subfield is not indexed, store it in __RAW__ index anyway
3161
            unless ($indexed) {
3162
                my $line = lc $subfield->[1];
3163
                $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
3164
3165
                # ... and split in words
3166
                foreach ( split / /, $line ) {
3167
                    next unless $_;    # skip  empty values (multiple spaces)
3168
                                       # if the entry is already here, improve weight
3169
                    my $tmpstr = $result{'__RAW__'}->{"$_"} || "";
3170
                    if ( $tmpstr =~ /$biblionumber,\Q$title\E\-(\d+);/ ) {
3171
                        my $weight = $1 + 1;
3172
                        $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
3173
                        $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
3174
                    } else {
3175
3176
                        # get the value if it exist in the nozebra table, otherwise, create it
3177
                        $sth2->execute( $server, '__RAW__', $_ );
3178
                        my $existing_biblionumbers = $sth2->fetchrow;
3179
3180
                        # it exists
3181
                        if ($existing_biblionumbers) {
3182
                            $result{'__RAW__'}->{"$_"} = $existing_biblionumbers;
3183
                            my $weight = ( $1 ? $1 : 0 ) + 1;
3184
                            $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
3185
                            $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
3186
3187
                            # create a new ligne for this entry
3188
                        } else {
3189
                            $dbh->do( 'INSERT INTO nozebra SET server=' . $dbh->quote($server) . ',  indexname="__RAW__",value=' . $dbh->quote($_) );
3190
                            $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-1;";
3191
                        }
3192
                    }
3193
                }
3194
            }
3195
        }
3196
    }
3197
    return %result;
3198
}
3199
3200
=head2 _find_value
2847
=head2 _find_value
3201
2848
3202
  ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
2849
  ($indicators, $value) = _find_value($tag, $subfield, $record,$encoding);
Lines 3715-3721 sub ModBiblioMarc { Link Here
3715
    $sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?");
3362
    $sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?");
3716
    $sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding), $biblionumber );
3363
    $sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding), $biblionumber );
3717
    $sth->finish;
3364
    $sth->finish;
3718
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", $oldRecord, $record );
3365
    AddToIndexQueue( $biblionumber, "specialUpdate", "biblioserver", $oldRecord, $record );
3719
    return $biblionumber;
3366
    return $biblionumber;
3720
}
3367
}
3721
3368
(-)a/C4/ImportBatch.pm (+1 lines)
Lines 25-30 use C4::Koha; Link Here
25
use C4::Biblio;
25
use C4::Biblio;
26
use C4::Items;
26
use C4::Items;
27
use C4::Charset;
27
use C4::Charset;
28
use Koha::Utils;
28
29
29
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30
31
(-)a/C4/Items.pm (-5 / +7 lines)
Lines 34-39 require C4::Reserves; Link Here
34
use C4::Charset;
34
use C4::Charset;
35
use C4::Acquisition;
35
use C4::Acquisition;
36
use List::MoreUtils qw/any/;
36
use List::MoreUtils qw/any/;
37
use Koha::Utils;
38
use Koha::Search;
37
use Data::Dumper; # used as part of logging item record changes, not just for
39
use Data::Dumper; # used as part of logging item record changes, not just for
38
                  # debugging; so please don't remove this
40
                  # debugging; so please don't remove this
39
41
Lines 268-274 sub AddItem { Link Here
268
	my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
270
	my ( $itemnumber, $error ) = _koha_new_item( $item, $item->{barcode} );
269
    $item->{'itemnumber'} = $itemnumber;
271
    $item->{'itemnumber'} = $itemnumber;
270
272
271
    ModZebra( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
273
    AddToIndexQueue( $item->{biblionumber}, "specialUpdate", "biblioserver", undef, undef );
272
   
274
   
273
    logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
275
    logaction("CATALOGUING", "ADD", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
274
    
276
    
Lines 519-525 sub ModItem { Link Here
519
521
520
    # request that bib be reindexed so that searching on current
522
    # request that bib be reindexed so that searching on current
521
    # item status is possible
523
    # item status is possible
522
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
524
    AddToIndexQueue( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
523
525
524
    logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item)) if C4::Context->preference("CataloguingLog");
526
    logaction("CATALOGUING", "MODIFY", $itemnumber, Dumper($item)) if C4::Context->preference("CataloguingLog");
525
}
527
}
Lines 582-588 sub DelItem { Link Here
582
584
583
    # get the MARC record
585
    # get the MARC record
584
    my $record = GetMarcBiblio($biblionumber);
586
    my $record = GetMarcBiblio($biblionumber);
585
    ModZebra( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
587
    AddToIndexQueue( $biblionumber, "specialUpdate", "biblioserver", undef, undef );
586
588
587
    # backup the record
589
    # backup the record
588
    my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
590
    my $copy2deleted = $dbh->prepare("UPDATE deleteditems SET marc=? WHERE itemnumber=?");
Lines 2172-2179 sub MoveItemFromBiblio { Link Here
2172
    $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
2174
    $sth = $dbh->prepare("UPDATE items SET biblioitemnumber = ?, biblionumber = ? WHERE itemnumber = ? AND biblionumber = ?");
2173
    my $return = $sth->execute($tobiblioitem, $tobiblio, $itemnumber, $frombiblio);
2175
    my $return = $sth->execute($tobiblioitem, $tobiblio, $itemnumber, $frombiblio);
2174
    if ($return == 1) {
2176
    if ($return == 1) {
2175
        ModZebra( $tobiblio, "specialUpdate", "biblioserver", undef, undef );
2177
        AddToIndexQueue( $tobiblio, "specialUpdate", "biblioserver", undef, undef );
2176
        ModZebra( $frombiblio, "specialUpdate", "biblioserver", undef, undef );
2178
        AddToIndexQueue( $frombiblio, "specialUpdate", "biblioserver", undef, undef );
2177
	    # Checking if the item we want to move is in an order 
2179
	    # Checking if the item we want to move is in an order 
2178
        my $order = GetOrderFromItemnumber($itemnumber);
2180
        my $order = GetOrderFromItemnumber($itemnumber);
2179
	    if ($order) {
2181
	    if ($order) {
(-)a/C4/Labels/Label.pm (+1 lines)
Lines 11-16 use Data::Dumper; Link Here
11
use C4::Context;
11
use C4::Context;
12
use C4::Debug;
12
use C4::Debug;
13
use C4::Biblio;
13
use C4::Biblio;
14
use Koha::Utils;
14
15
15
BEGIN {
16
BEGIN {
16
    use version; our $VERSION = qv('1.0.0_1');
17
    use version; our $VERSION = qv('1.0.0_1');
(-)a/C4/Search.pm (-203 / +3 lines)
Lines 33-38 use C4::Debug; Link Here
33
use C4::Items;
33
use C4::Items;
34
use YAML;
34
use YAML;
35
use URI::Escape;
35
use URI::Escape;
36
use Koha::Search;
37
use Koha::Utils;
36
38
37
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
39
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
38
40
Lines 812-1019 sub _build_weighted_query { Link Here
812
    return $weighted_query;
814
    return $weighted_query;
813
}
815
}
814
816
815
=head2 getIndexes
816
817
Return an array with available indexes.
818
819
=cut
820
821
sub getIndexes{
822
    my @indexes = (
823
                    # biblio indexes
824
                    'ab',
825
                    'Abstract',
826
                    'acqdate',
827
                    'allrecords',
828
                    'an',
829
                    'Any',
830
                    'at',
831
                    'au',
832
                    'aub',
833
                    'aud',
834
                    'audience',
835
                    'auo',
836
                    'aut',
837
                    'Author',
838
                    'Author-in-order ',
839
                    'Author-personal-bibliography',
840
                    'Authority-Number',
841
                    'authtype',
842
                    'bc',
843
		    'Bib-level',
844
                    'biblionumber',
845
                    'bio',
846
                    'biography',
847
                    'callnum',
848
                    'cfn',
849
                    'Chronological-subdivision',
850
                    'cn-bib-source',
851
                    'cn-bib-sort',
852
                    'cn-class',
853
                    'cn-item',
854
                    'cn-prefix',
855
                    'cn-suffix',
856
                    'cpn',
857
                    'Code-institution',
858
                    'Conference-name',
859
                    'Conference-name-heading',
860
                    'Conference-name-see',
861
                    'Conference-name-seealso',
862
                    'Content-type',
863
                    'Control-number',
864
                    'copydate',
865
                    'Corporate-name',
866
                    'Corporate-name-heading',
867
                    'Corporate-name-see',
868
                    'Corporate-name-seealso',
869
                    'ctype',
870
                    'date-entered-on-file',
871
                    'Date-of-acquisition',
872
                    'Date-of-publication',
873
                    'Dewey-classification',
874
                    'EAN',
875
                    'extent',
876
                    'fic',
877
                    'fiction',
878
                    'Form-subdivision',
879
                    'format',
880
                    'Geographic-subdivision',
881
                    'he',
882
                    'Heading',
883
                    'Heading-use-main-or-added-entry',
884
                    'Heading-use-series-added-entry ',
885
                    'Heading-use-subject-added-entry',
886
                    'Host-item',
887
                    'id-other',
888
                    'Illustration-code',
889
                    'ISBN',
890
                    'isbn',
891
                    'ISSN',
892
                    'issn',
893
                    'itemtype',
894
                    'kw',
895
                    'Koha-Auth-Number',
896
                    'l-format',
897
                    'language',
898
                    'lc-card',
899
                    'LC-card-number',
900
                    'lcn',
901
                    'llength',
902
                    'ln',
903
                    'Local-classification',
904
                    'Local-number',
905
                    'Match-heading',
906
                    'Match-heading-see-from',
907
                    'Material-type',
908
                    'mc-itemtype',
909
                    'mc-rtype',
910
                    'mus',
911
                    'name',
912
                    'Music-number',
913
                    'Name-geographic',
914
                    'Name-geographic-heading',
915
                    'Name-geographic-see',
916
                    'Name-geographic-seealso',
917
                    'nb',
918
                    'Note',
919
                    'notes',
920
                    'ns',
921
                    'nt',
922
                    'pb',
923
                    'Personal-name',
924
                    'Personal-name-heading',
925
                    'Personal-name-see',
926
                    'Personal-name-seealso',
927
                    'pl',
928
                    'Place-publication',
929
                    'pn',
930
                    'popularity',
931
                    'pubdate',
932
                    'Publisher',
933
                    'Record-control-number',
934
                    'rcn',
935
                    'Record-type',
936
                    'rtype',
937
                    'se',
938
                    'See',
939
                    'See-also',
940
                    'sn',
941
                    'Stock-number',
942
                    'su',
943
                    'Subject',
944
                    'Subject-heading-thesaurus',
945
                    'Subject-name-personal',
946
                    'Subject-subdivision',
947
                    'Summary',
948
                    'Suppress',
949
                    'su-geo',
950
                    'su-na',
951
                    'su-to',
952
                    'su-ut',
953
                    'ut',
954
                    'UPC',
955
                    'Term-genre-form',
956
                    'Term-genre-form-heading',
957
                    'Term-genre-form-see',
958
                    'Term-genre-form-seealso',
959
                    'ti',
960
                    'Title',
961
                    'Title-cover',
962
                    'Title-series',
963
                    'Title-host',
964
                    'Title-uniform',
965
                    'Title-uniform-heading',
966
                    'Title-uniform-see',
967
                    'Title-uniform-seealso',
968
                    'totalissues',
969
                    'yr',
970
971
                    # items indexes
972
                    'acqsource',
973
                    'barcode',
974
                    'bc',
975
                    'branch',
976
                    'ccode',
977
                    'classification-source',
978
                    'cn-sort',
979
                    'coded-location-qualifier',
980
                    'copynumber',
981
                    'damaged',
982
                    'datelastborrowed',
983
                    'datelastseen',
984
                    'holdingbranch',
985
                    'homebranch',
986
                    'issues',
987
                    'item',
988
                    'itemnumber',
989
                    'itype',
990
                    'Local-classification',
991
                    'location',
992
                    'lost',
993
                    'materials-specified',
994
                    'mc-ccode',
995
                    'mc-itype',
996
                    'mc-loc',
997
                    'notforloan',
998
                    'onloan',
999
                    'price',
1000
                    'renewals',
1001
                    'replacementprice',
1002
                    'replacementpricedate',
1003
                    'reserves',
1004
                    'restricted',
1005
                    'stack',
1006
                    'stocknumber',
1007
                    'inv',
1008
                    'uri',
1009
                    'withdrawn',
1010
1011
                    # subject related
1012
                  );
1013
1014
    return \@indexes;
1015
}
1016
1017
=head2 buildQuery
817
=head2 buildQuery
1018
818
1019
( $error, $query,
819
( $error, $query,
Lines 1071-1077 sub buildQuery { Link Here
1071
    my $stopwords_removed;    # flag to determine if stopwords have been removed
871
    my $stopwords_removed;    # flag to determine if stopwords have been removed
1072
872
1073
    my $cclq       = 0;
873
    my $cclq       = 0;
1074
    my $cclindexes = getIndexes();
874
    my $cclindexes = GetIndexes();
1075
    if ( $query !~ /\s*ccl=/ ) {
875
    if ( $query !~ /\s*ccl=/ ) {
1076
        while ( !$cclq && $query =~ /(?:^|\W)([\w-]+)(,[\w-]+)*[:=]/g ) {
876
        while ( !$cclq && $query =~ /(?:^|\W)([\w-]+)(,[\w-]+)*[:=]/g ) {
1077
            my $dx = lc($1);
877
            my $dx = lc($1);
(-)a/C4/Serials.pm (+1 lines)
Lines 32-37 use C4::Search; Link Here
32
use C4::Letters;
32
use C4::Letters;
33
use C4::Log;    # logaction
33
use C4::Log;    # logaction
34
use C4::Debug;
34
use C4::Debug;
35
use Koha::Utils;
35
36
36
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
37
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
37
38
(-)a/Koha/Search.pm (+113 lines)
Line 0 Link Here
1
package Koha::Search;
2
3
# Copyright 2011 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
Koha::Search - Interface to bibliographic/authority record searching
23
24
=head1 SYNOPSIS
25
26
  use Koha::Search;
27
28
=head1 DESCRIPTION
29
30
Interface to Koha::Search::Engine functionality for bibliographic and authority
31
record searching.
32
33
=head1 FUNCTIONS
34
35
=cut
36
37
use strict;
38
use warnings;
39
require Exporter;
40
use C4::Context;
41
use Koha::Search::Engine;
42
43
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
44
45
46
BEGIN {
47
    $VERSION = 3.01;
48
    $DEBUG = ($ENV{DEBUG}) ? 1 : 0;
49
    our $search_engine = Koha::Search::Engine->new();
50
}
51
52
=head1 NAME
53
54
Koha::Search - Functions for searching the Koha catalog.
55
56
=head1 SYNOPSIS
57
58
See opac/opac-search.pl or catalogue/search.pl for example of usage
59
60
=head1 DESCRIPTION
61
62
This module provides searching functions for Koha's bibliographic databases
63
64
=head1 FUNCTIONS
65
66
=cut
67
68
69
@ISA    = qw(Exporter);
70
@EXPORT = qw(
71
    &AddToIndexQueue
72
    &GetIndexes
73
);
74
75
our $search_engine;
76
77
sub AddToIndexQueue {
78
    if (!(C4::Context->preference('SearchEngine')=~/IndexOff/i)){ # solr allows disabling indexing
79
        return $search_engine->add_to_index_queue( @_ );
80
    }
81
    return undef;
82
}
83
84
=head2 GetIndexes
85
86
  %indexes = GetIndexes;
87
88
Return a hash of indexes provided by the active search engine
89
90
=cut
91
92
sub GetIndexes {
93
    return $search_engine->get_indexes( @_ );
94
}
95
96
=head2 EXPORT
97
98
AddToIndexQueue
99
GetIndexes
100
101
=head1 SEE ALSO
102
103
Koha::Search::Engine::Zebra
104
105
=head1 AUTHOR
106
107
Jared Camins-Esakov, C & P Bibliography Services, E<lt>jcamins@cpbibliography.comE<gt>
108
109
=cut
110
111
1;
112
113
__END__
(-)a/Koha/Search/Engine.pm (+121 lines)
Line 0 Link Here
1
package Koha::Search::Engine;
2
3
# Copyright 2011 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
=head1 NAME
21
22
Koha::Search::Engine - Base class for Koha search engine interfaces
23
24
=head1 SYNOPSIS
25
26
  use Koha::Search::Engine;
27
28
=head1 DESCRIPTION
29
30
Base class for Koha::Search::Engine::X. Subclasses need to provide the
31
following methods:
32
33
B<add_to_index_queue> - add the specified object to the index queue
34
35
B<get_indexes> - get a list of indexes provided by the search engine
36
37
=head1 FUNCTIONS
38
39
=cut
40
41
use strict;
42
use warnings;
43
use C4::Context;
44
45
BEGIN {
46
    our $VERSION = 3.01;
47
48
    my $engine_module = "Koha::Search::Engine::" . (C4::Context->preference("SearchEngine") || 'Zebra');
49
    eval "require $engine_module";
50
}
51
52
sub new {
53
    my $class = shift;
54
55
    my $self = { };
56
57
    my $engine_module = "Koha::Search::Engine::" . (C4::Context->preference("SearchEngine") || 'Zebra');
58
59
    $self->{'engine'} = $engine_module->new();
60
    bless $self, $class;
61
    return $self;
62
}
63
64
=head2 add_to_index_queue
65
66
  $search_engine->add_to_index_queue( $indexnumber, $op, $server, $oldRecord, $newRecord );
67
68
$indexnumber is the id number of the object we want to index
69
70
$op is specialUpdate or delete, and is used to know what we want to do
71
72
$server is the server that we want to update
73
74
$oldRecord is the MARC::Record containing the previous version of the record.
75
This is used only by the NoZebra engine.
76
77
$newRecord is the MARC::Record containing the new record. This is used only by
78
the NoZebra engine.
79
80
=cut
81
82
sub add_to_index_queue {
83
    my $self = shift;
84
85
    return $self->{'engine'}->add_to_index_queue(@_);
86
}
87
88
=head2 get_indexes
89
90
  %indexes = $search_engine->get_indexes;
91
92
Return a hash of indexes provided by the active search engine
93
94
=cut
95
96
97
sub get_indexes {
98
    my $self = shift;
99
100
    return $self->{'engine'}->get_indexes(@_);
101
}
102
103
=head2 EXPORT
104
105
None by default.
106
107
=head1 SEE ALSO
108
109
Koha::Search
110
Koha::Search::Engine::NoZebra
111
Koha::Search::Engine::Zebra
112
113
=head1 AUTHOR
114
115
Jared Camins-Esakov, C & P Bibliography Services, E<lt>jcamins@cpbibliography.comE<gt>
116
117
=cut
118
119
1;
120
121
__END__
(-)a/Koha/Search/Engine/NoZebra.pm (+355 lines)
Line 0 Link Here
1
package Koha::Search::Engine::NoZebra;
2
3
# Copyright 2011 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use C4::Context;
23
use Koha::Utils;
24
25
use base qw(Koha::Search::Engine);
26
27
sub new {
28
    my $class = shift;
29
30
    my $self = { };
31
    bless $self, $class;
32
    return $self;
33
}
34
35
sub add_to_index_queue {
36
    my ( $self, $indexnumber, $op, $server, $oldRecord, $newRecord ) = @_;
37
    my $dbh = C4::Context->dbh;
38
# lock the nozebra table : we will read index lines, update them in Perl process
39
# and write everything in 1 transaction.
40
# lock the table to avoid someone else overwriting what we are doing
41
    $dbh->do('LOCK TABLES nozebra WRITE,biblio WRITE,biblioitems WRITE, systempreferences WRITE, auth_types WRITE, auth_header WRITE, auth_subfield_structure READ');
42
    my %result;    # the result hash that will be built by deletion / add, and written on mySQL at the end, to improve speed
43
        if ( $op eq 'specialUpdate' ) {
44
45
# OK, we have to add or update the record
46
# 1st delete (virtually, in indexes), if record actually exists
47
            if ($oldRecord) {
48
                %result = _DelBiblioNoZebra( $indexnumber, $oldRecord, $server );
49
            }
50
51
# ... add the record
52
            %result = _AddBiblioNoZebra( $indexnumber, $newRecord, $server, %result );
53
        } else {
54
55
# it's a deletion, delete the record...
56
# warn "DELETE the record $indexnumber on $server".$record->as_formatted;
57
            %result = _DelBiblioNoZebra( $indexnumber, $oldRecord, $server );
58
        }
59
60
# ok, now update the database...
61
    my $sth = $dbh->prepare("UPDATE nozebra SET indexnumbers=? WHERE server=? AND indexname=? AND value=?");
62
    foreach my $key ( keys %result ) {
63
        foreach my $index ( keys %{ $result{$key} } ) {
64
            $sth->execute( $result{$key}->{$index}, $server, $key, $index );
65
        }
66
    }
67
    $dbh->do('UNLOCK TABLES');
68
}
69
70
sub get_indexes {
71
    my $no_zebra_indexes = C4::Context->preference('NoZebraIndexes');
72
    my %indexes;
73
  INDEX: foreach my $line ( split /['"],[\n\r]*/, $no_zebra_indexes ) {
74
        $line =~ /(.*)=>(.*)/;
75
        my $index  = $1;    # initial ' or " is removed afterwards
76
        my $fields = $2;
77
        $index  =~ s/'|"|\s//g;
78
        $fields =~ s/'|"|\s//g;
79
        $indexes{$index} = $fields;
80
    }
81
    return %indexes;
82
}
83
84
=head1 INTERNAL FUNCTIONS
85
86
=head2 _DelBiblioNoZebra($biblionumber,$record,$server);
87
88
function to delete a biblio in NoZebra indexes
89
This function does NOT delete anything in database : it reads all the indexes entries
90
that have to be deleted & delete them in the hash
91
92
The SQL part is done either :
93
 - after the Add if we are modifying a biblio (delete + add again)
94
 - immediatly after this sub if we are doing a true deletion.
95
96
$server can be 'biblioserver' or 'authorityserver' : it indexes biblios or authorities (in the same table, $server being part of the table itself
97
98
=cut
99
100
sub _DelBiblioNoZebra {
101
    my ( $biblionumber, $record, $server ) = @_;
102
103
    # Get the indexes
104
    my $dbh = C4::Context->dbh;
105
106
    # Get the indexes
107
    my %index;
108
    my $title;
109
    if ( $server eq 'biblioserver' ) {
110
        %index = get_indexes;
111
112
        # get title of the record (to store the 10 first letters with the index)
113
        my ( $titletag, $titlesubfield ) = GetMarcFromKohaField( 'biblio.title', '' );    # FIXME: should be GetFrameworkCode($biblionumber) ??
114
        $title = lc( $record->subfield( $titletag, $titlesubfield ) );
115
    } else {
116
117
        # for authorities, the "title" is the $a mainentry
118
        my ( $auth_type_tag, $auth_type_sf ) = C4::AuthoritiesMarc::get_auth_type_location();
119
        my $authref = GetAuthType( $record->subfield( $auth_type_tag, $auth_type_sf ) );
120
        warn "ERROR : authtype undefined for " . $record->as_formatted unless $authref;
121
        $title = $record->subfield( $authref->{auth_tag_to_report}, 'a' );
122
        $index{'mainmainentry'} = $authref->{'auth_tag_to_report'} . 'a';
123
        $index{'mainentry'}     = $authref->{'auth_tag_to_report'} . '*';
124
        $index{'auth_type'}     = "${auth_type_tag}${auth_type_sf}";
125
    }
126
127
    my %result;
128
129
    # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
130
    $title =~ s/ |,|;|\[|\]|\(|\)|\*|-|'|=//g;
131
132
    # limit to 10 char, should be enough, and limit the DB size
133
    $title = substr( $title, 0, 10 );
134
135
    #parse each field
136
    my $sth2 = $dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
137
    foreach my $field ( $record->fields() ) {
138
139
        #parse each subfield
140
        next if $field->tag < 10;
141
        foreach my $subfield ( $field->subfields() ) {
142
            my $tag          = $field->tag();
143
            my $subfieldcode = $subfield->[0];
144
            my $indexed      = 0;
145
146
            # check each index to see if the subfield is stored somewhere
147
            # otherwise, store it in __RAW__ index
148
            foreach my $key ( keys %index ) {
149
150
                #                 warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
151
                if ( $index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/ ) {
152
                    $indexed = 1;
153
                    my $line = lc $subfield->[1];
154
155
                    # remove meaningless value in the field...
156
                    $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
157
158
                    # ... and split in words
159
                    foreach ( split / /, $line ) {
160
                        next unless $_;    # skip  empty values (multiple spaces)
161
                                           # if the entry is already here, do nothing, the biblionumber has already be removed
162
                        unless ( defined( $result{$key}->{$_} ) && ( $result{$key}->{$_} =~ /$biblionumber,$title\-(\d);/ ) ) {
163
164
                            # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
165
                            $sth2->execute( $server, $key, $_ );
166
                            my $existing_biblionumbers = $sth2->fetchrow;
167
168
                            # it exists
169
                            if ($existing_biblionumbers) {
170
171
                                #                                 warn " existing for $key $_: $existing_biblionumbers";
172
                                $result{$key}->{$_} = $existing_biblionumbers;
173
                                $result{$key}->{$_} =~ s/$biblionumber,$title\-(\d);//;
174
                            }
175
                        }
176
                    }
177
                }
178
            }
179
180
            # the subfield is not indexed, store it in __RAW__ index anyway
181
            unless ($indexed) {
182
                my $line = lc $subfield->[1];
183
                $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:/ /g;
184
185
                # ... and split in words
186
                foreach ( split / /, $line ) {
187
                    next unless $_;    # skip  empty values (multiple spaces)
188
                                       # if the entry is already here, do nothing, the biblionumber has already be removed
189
                    unless ( $result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/ ) {
190
191
                        # get the index value if it exist in the nozebra table and remove the entry, otherwise, do nothing
192
                        $sth2->execute( $server, '__RAW__', $_ );
193
                        my $existing_biblionumbers = $sth2->fetchrow;
194
195
                        # it exists
196
                        if ($existing_biblionumbers) {
197
                            $result{'__RAW__'}->{$_} = $existing_biblionumbers;
198
                            $result{'__RAW__'}->{$_} =~ s/$biblionumber,$title\-(\d);//;
199
                        }
200
                    }
201
                }
202
            }
203
        }
204
    }
205
    return %result;
206
}
207
208
=head2 _AddBiblioNoZebra
209
210
  _AddBiblioNoZebra($biblionumber, $record, $server, %result);
211
212
function to add a biblio in NoZebra indexes
213
214
=cut
215
216
sub _AddBiblioNoZebra {
217
    my ( $biblionumber, $record, $server, %result ) = @_;
218
    my $dbh = C4::Context->dbh;
219
220
    # Get the indexes
221
    my %index;
222
    my $title;
223
    if ( $server eq 'biblioserver' ) {
224
        %index = get_indexes;
225
226
        # get title of the record (to store the 10 first letters with the index)
227
        my ( $titletag, $titlesubfield ) = GetMarcFromKohaField( 'biblio.title', '' );    # FIXME: should be GetFrameworkCode($biblionumber) ??
228
        $title = lc( $record->subfield( $titletag, $titlesubfield ) );
229
    } else {
230
231
        # warn "server : $server";
232
        # for authorities, the "title" is the $a mainentry
233
        my ( $auth_type_tag, $auth_type_sf ) = C4::AuthoritiesMarc::get_auth_type_location();
234
        my $authref = GetAuthType( $record->subfield( $auth_type_tag, $auth_type_sf ) );
235
        warn "ERROR : authtype undefined for " . $record->as_formatted unless $authref;
236
        $title = $record->subfield( $authref->{auth_tag_to_report}, 'a' );
237
        $index{'mainmainentry'} = $authref->{auth_tag_to_report} . 'a';
238
        $index{'mainentry'}     = $authref->{auth_tag_to_report} . '*';
239
        $index{'auth_type'}     = "${auth_type_tag}${auth_type_sf}";
240
    }
241
242
    # remove blancks comma (that could cause problem when decoding the string for CQL retrieval) and regexp specific values
243
    $title =~ s/ |\.|,|;|\[|\]|\(|\)|\*|-|'|:|=|\r|\n//g;
244
245
    # limit to 10 char, should be enough, and limit the DB size
246
    $title = substr( $title, 0, 10 );
247
248
    #parse each field
249
    my $sth2 = $dbh->prepare('SELECT biblionumbers FROM nozebra WHERE server=? AND indexname=? AND value=?');
250
    foreach my $field ( $record->fields() ) {
251
252
        #parse each subfield
253
        ###FIXME: impossible to index a 001-009 value with NoZebra
254
        next if $field->tag < 10;
255
        foreach my $subfield ( $field->subfields() ) {
256
            my $tag          = $field->tag();
257
            my $subfieldcode = $subfield->[0];
258
            my $indexed      = 0;
259
260
            #             warn "INDEXING :".$subfield->[1];
261
            # check each index to see if the subfield is stored somewhere
262
            # otherwise, store it in __RAW__ index
263
            foreach my $key ( keys %index ) {
264
265
                #                 warn "examining $key index : ".$index{$key}." for $tag $subfieldcode";
266
                if ( $index{$key} =~ /$tag\*/ or $index{$key} =~ /$tag$subfieldcode/ ) {
267
                    $indexed = 1;
268
                    my $line = lc $subfield->[1];
269
270
                    # remove meaningless value in the field...
271
                    $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
272
273
                    # ... and split in words
274
                    foreach ( split / /, $line ) {
275
                        next unless $_;    # skip  empty values (multiple spaces)
276
                                           # if the entry is already here, improve weight
277
278
                        #                         warn "managing $_";
279
                        if ( exists $result{$key}->{$_} && $result{$key}->{"$_"} =~ /$biblionumber,\Q$title\E\-(\d+);/ ) {
280
                            my $weight = $1 + 1;
281
                            $result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
282
                            $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
283
                        } else {
284
285
                            # get the value if it exist in the nozebra table, otherwise, create it
286
                            $sth2->execute( $server, $key, $_ );
287
                            my $existing_biblionumbers = $sth2->fetchrow;
288
289
                            # it exists
290
                            if ($existing_biblionumbers) {
291
                                $result{$key}->{"$_"} = $existing_biblionumbers;
292
                                my $weight = defined $1 ? $1 + 1 : 1;
293
                                $result{$key}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//g;
294
                                $result{$key}->{"$_"} .= "$biblionumber,$title-$weight;";
295
296
                                # create a new ligne for this entry
297
                            } else {
298
299
                                #                             warn "INSERT : $server / $key / $_";
300
                                $dbh->do( 'INSERT INTO nozebra SET server=' . $dbh->quote($server) . ', indexname=' . $dbh->quote($key) . ',value=' . $dbh->quote($_) );
301
                                $result{$key}->{"$_"} .= "$biblionumber,$title-1;";
302
                            }
303
                        }
304
                    }
305
                }
306
            }
307
308
            # the subfield is not indexed, store it in __RAW__ index anyway
309
            unless ($indexed) {
310
                my $line = lc $subfield->[1];
311
                $line =~ s/-|\.|\?|,|;|!|'|\(|\)|\[|\]|{|}|"|<|>|&|\+|\*|\/|=|:|\r|\n/ /g;
312
313
                # ... and split in words
314
                foreach ( split / /, $line ) {
315
                    next unless $_;    # skip  empty values (multiple spaces)
316
                                       # if the entry is already here, improve weight
317
                    my $tmpstr = $result{'__RAW__'}->{"$_"} || "";
318
                    if ( $tmpstr =~ /$biblionumber,\Q$title\E\-(\d+);/ ) {
319
                        my $weight = $1 + 1;
320
                        $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
321
                        $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
322
                    } else {
323
324
                        # get the value if it exist in the nozebra table, otherwise, create it
325
                        $sth2->execute( $server, '__RAW__', $_ );
326
                        my $existing_biblionumbers = $sth2->fetchrow;
327
328
                        # it exists
329
                        if ($existing_biblionumbers) {
330
                            $result{'__RAW__'}->{"$_"} = $existing_biblionumbers;
331
                            my $weight = ( $1 ? $1 : 0 ) + 1;
332
                            $result{'__RAW__'}->{"$_"} =~ s/$biblionumber,\Q$title\E\-(\d+);//;
333
                            $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-$weight;";
334
335
                            # create a new ligne for this entry
336
                        } else {
337
                            $dbh->do( 'INSERT INTO nozebra SET server=' . $dbh->quote($server) . ',  indexname="__RAW__",value=' . $dbh->quote($_) );
338
                            $result{'__RAW__'}->{"$_"} .= "$biblionumber,$title-1;";
339
                        }
340
                    }
341
                }
342
            }
343
        }
344
    }
345
    return %result;
346
}
347
348
1;
349
__END__
350
351
=head1 NAME
352
353
Koha::Search::Engine::NoZebra - interface to deprecated NoZebra as the search engine for Koha
354
355
=cut
(-)a/Koha/Search/Engine/Zebra.pm (+257 lines)
Line 0 Link Here
1
package Koha::Search::Engine::Zebra;
2
3
# Copyright 2011 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
23
use base qw(Koha::Search::Engine);
24
25
sub new {
26
    my $class = shift;
27
28
    my $self = { };
29
    bless $self, $class;
30
    return $self;
31
}
32
33
sub add_to_index_queue {
34
    my ( $self, $indexnumber, $op, $server, $oldRecord, $newRecord ) = @_;
35
    my $dbh = C4::Context->dbh;
36
#
37
# we use zebra, just fill zebraqueue table
38
#
39
    my $check_sql = "SELECT COUNT(*) FROM zebraqueue 
40
        WHERE server = ?
41
        AND   biblio_auth_number = ?
42
        AND   operation = ?
43
        AND   done = 0";
44
    my $check_sth = $dbh->prepare_cached($check_sql);
45
    $check_sth->execute( $server, $indexnumber, $op );
46
    my ($count) = $check_sth->fetchrow_array;
47
    $check_sth->finish();
48
    if ( $count == 0 ) {
49
        my $sth = $dbh->prepare("INSERT INTO zebraqueue  (biblio_auth_number,server,operation) VALUES(?,?,?)");
50
        $sth->execute( $indexnumber, $server, $op );
51
        $sth->finish;
52
    }
53
}
54
55
sub get_indexes {
56
    my @indexes = (
57
                    # biblio indexes
58
                    'ab',
59
                    'Abstract',
60
                    'acqdate',
61
                    'allrecords',
62
                    'an',
63
                    'Any',
64
                    'at',
65
                    'au',
66
                    'aub',
67
                    'aud',
68
                    'audience',
69
                    'auo',
70
                    'aut',
71
                    'Author',
72
                    'Author-in-order ',
73
                    'Author-personal-bibliography',
74
                    'Authority-Number',
75
                    'authtype',
76
                    'bc',
77
		    'Bib-level',
78
                    'biblionumber',
79
                    'bio',
80
                    'biography',
81
                    'callnum',
82
                    'cfn',
83
                    'Chronological-subdivision',
84
                    'cn-bib-source',
85
                    'cn-bib-sort',
86
                    'cn-class',
87
                    'cn-item',
88
                    'cn-prefix',
89
                    'cn-suffix',
90
                    'cpn',
91
                    'Code-institution',
92
                    'Conference-name',
93
                    'Conference-name-heading',
94
                    'Conference-name-see',
95
                    'Conference-name-seealso',
96
                    'Content-type',
97
                    'Control-number',
98
                    'copydate',
99
                    'Corporate-name',
100
                    'Corporate-name-heading',
101
                    'Corporate-name-see',
102
                    'Corporate-name-seealso',
103
                    'ctype',
104
                    'date-entered-on-file',
105
                    'Date-of-acquisition',
106
                    'Date-of-publication',
107
                    'Dewey-classification',
108
                    'EAN',
109
                    'extent',
110
                    'fic',
111
                    'fiction',
112
                    'Form-subdivision',
113
                    'format',
114
                    'Geographic-subdivision',
115
                    'he',
116
                    'Heading',
117
                    'Heading-use-main-or-added-entry',
118
                    'Heading-use-series-added-entry ',
119
                    'Heading-use-subject-added-entry',
120
                    'Host-item',
121
                    'id-other',
122
                    'Illustration-code',
123
                    'ISBN',
124
                    'isbn',
125
                    'ISSN',
126
                    'issn',
127
                    'itemtype',
128
                    'kw',
129
                    'Koha-Auth-Number',
130
                    'l-format',
131
                    'language',
132
                    'lc-card',
133
                    'LC-card-number',
134
                    'lcn',
135
                    'llength',
136
                    'ln',
137
                    'Local-classification',
138
                    'Local-number',
139
                    'Match-heading',
140
                    'Match-heading-see-from',
141
                    'Material-type',
142
                    'mc-itemtype',
143
                    'mc-rtype',
144
                    'mus',
145
                    'name',
146
                    'Music-number',
147
                    'Name-geographic',
148
                    'Name-geographic-heading',
149
                    'Name-geographic-see',
150
                    'Name-geographic-seealso',
151
                    'nb',
152
                    'Note',
153
                    'notes',
154
                    'ns',
155
                    'nt',
156
                    'pb',
157
                    'Personal-name',
158
                    'Personal-name-heading',
159
                    'Personal-name-see',
160
                    'Personal-name-seealso',
161
                    'pl',
162
                    'Place-publication',
163
                    'pn',
164
                    'popularity',
165
                    'pubdate',
166
                    'Publisher',
167
                    'Record-control-number',
168
                    'rcn',
169
                    'Record-type',
170
                    'rtype',
171
                    'se',
172
                    'See',
173
                    'See-also',
174
                    'sn',
175
                    'Stock-number',
176
                    'su',
177
                    'Subject',
178
                    'Subject-heading-thesaurus',
179
                    'Subject-name-personal',
180
                    'Subject-subdivision',
181
                    'Summary',
182
                    'Suppress',
183
                    'su-geo',
184
                    'su-na',
185
                    'su-to',
186
                    'su-ut',
187
                    'ut',
188
                    'UPC',
189
                    'Term-genre-form',
190
                    'Term-genre-form-heading',
191
                    'Term-genre-form-see',
192
                    'Term-genre-form-seealso',
193
                    'ti',
194
                    'Title',
195
                    'Title-cover',
196
                    'Title-series',
197
                    'Title-host',
198
                    'Title-uniform',
199
                    'Title-uniform-heading',
200
                    'Title-uniform-see',
201
                    'Title-uniform-seealso',
202
                    'totalissues',
203
                    'yr',
204
205
                    # items indexes
206
                    'acqsource',
207
                    'barcode',
208
                    'bc',
209
                    'branch',
210
                    'ccode',
211
                    'classification-source',
212
                    'cn-sort',
213
                    'coded-location-qualifier',
214
                    'copynumber',
215
                    'damaged',
216
                    'datelastborrowed',
217
                    'datelastseen',
218
                    'holdingbranch',
219
                    'homebranch',
220
                    'issues',
221
                    'item',
222
                    'itemnumber',
223
                    'itype',
224
                    'Local-classification',
225
                    'location',
226
                    'lost',
227
                    'materials-specified',
228
                    'mc-ccode',
229
                    'mc-itype',
230
                    'mc-loc',
231
                    'notforloan',
232
                    'onloan',
233
                    'price',
234
                    'renewals',
235
                    'replacementprice',
236
                    'replacementpricedate',
237
                    'reserves',
238
                    'restricted',
239
                    'stack',
240
                    'stocknumber',
241
                    'inv',
242
                    'uri',
243
                    'withdrawn',
244
245
                    # subject related
246
                  );
247
    return \@indexes;
248
}
249
250
1;
251
__END__
252
253
=head1 NAME
254
255
Koha::Search::Engine::Zebra - interface to Zebra as the search engine for Koha
256
257
=cut
(-)a/Koha/Utils.pm (+119 lines)
Line 0 Link Here
1
package Koha::Utils;
2
3
# Copyright 2011 C & P Bibliography Services
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use strict;
21
use warnings;
22
use C4::Context;
23
24
use vars qw($VERSION @ISA @EXPORT);
25
26
BEGIN {
27
    our $VERSION = 3.01;
28
    our $DEBUG = ($ENV{DEBUG}) ? 1 : 0;
29
}
30
31
=head1 NAME
32
33
Koha::Utils - Various utility functions for accessing a Koha instance's
34
configuration
35
36
=head1 SYNOPSIS
37
38
  use Koha::Utils;
39
40
=head1 DESCRIPTION
41
42
Various high-level utility functions for getting information about a Koha
43
instance's configuration options, to complement the low-level functions in
44
Koha::Context.
45
46
47
=head1 FUNCTIONS
48
49
=cut
50
51
require Exporter;
52
@ISA = qw( Exporter );
53
@EXPORT = qw(
54
    &GetMarcFromKohaField
55
    &GetAuthType
56
);
57
58
59
60
=head2 GetMarcFromKohaField
61
62
  ($MARCfield,$MARCsubfield)=GetMarcFromKohaField($kohafield,$frameworkcode);
63
64
Returns the MARC fields & subfields mapped to the koha field 
65
for the given frameworkcode
66
67
=cut
68
69
sub GetMarcFromKohaField {
70
    my ( $kohafield, $frameworkcode ) = @_;
71
    return 0, 0 unless $kohafield and defined $frameworkcode;
72
    my $relations = C4::Context->marcfromkohafield;
73
    return ( $relations->{$frameworkcode}->{$kohafield}->[0], $relations->{$frameworkcode}->{$kohafield}->[1] );
74
}
75
76
=head2 GetAuthType 
77
78
  $result = &GetAuthType($authtypecode)
79
80
If the authority type specified by C<$authtypecode> exists,
81
returns a hashref of the type's fields.  If the type
82
does not exist, returns undef.
83
84
=cut
85
86
sub GetAuthType {
87
    my ($authtypecode) = @_;
88
    my $dbh=C4::Context->dbh;
89
    my $sth;
90
    if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority 
91
                                # type (FIXME but why?)
92
        $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
93
        $sth->execute($authtypecode);
94
        if (my $res = $sth->fetchrow_hashref) {
95
            return $res; 
96
        }
97
    }
98
    return;
99
}
100
101
102
=head2 EXPORT
103
104
GetMarcFromKohaField
105
GetAuthType
106
107
=head1 SEE ALSO
108
109
Koha::Context
110
111
=head1 AUTHOR
112
113
Jared Camins-Esakov, C & P Bibliography Services, E<lt>jcamins@cpbibliography.comE<gt>
114
115
=cut
116
117
1;
118
119
__END__
(-)a/acqui/addorderiso2709.pl (+1 lines)
Lines 45-50 use C4::Dates; Link Here
45
use C4::Suggestions;    # GetSuggestion
45
use C4::Suggestions;    # GetSuggestion
46
use C4::Branch;         # GetBranches
46
use C4::Branch;         # GetBranches
47
use C4::Members;
47
use C4::Members;
48
use Koha::Utils;
48
49
49
my $input = new CGI;
50
my $input = new CGI;
50
my ($template, $loggedinuser, $cookie) = get_template_and_user({
51
my ($template, $loggedinuser, $cookie) = get_template_and_user({
(-)a/acqui/neworderempty.pl (+1 lines)
Lines 87-92 use C4::Koha; Link Here
87
use C4::Branch;			# GetBranches
87
use C4::Branch;			# GetBranches
88
use C4::Members;
88
use C4::Members;
89
use C4::Search qw/FindDuplicate/;
89
use C4::Search qw/FindDuplicate/;
90
use Koha::Utils;
90
91
91
#needed for z3950 import:
92
#needed for z3950 import:
92
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
93
use C4::ImportBatch qw/GetImportRecordMarc SetImportRecordStatus/;
(-)a/authorities/authorities.pl (+1 lines)
Lines 30-35 use Date::Calc qw(Today); Link Here
30
use MARC::File::USMARC;
30
use MARC::File::USMARC;
31
use MARC::File::XML;
31
use MARC::File::XML;
32
use C4::Biblio;
32
use C4::Biblio;
33
use Koha::Utils;
33
use vars qw( $tagslib);
34
use vars qw( $tagslib);
34
use vars qw( $authorised_values_sth);
35
use vars qw( $authorised_values_sth);
35
use vars qw( $is_a_modif );
36
use vars qw( $is_a_modif );
(-)a/authorities/blinddetail-biblio-search.pl (+1 lines)
Lines 46-51 use C4::Output; Link Here
46
use CGI;
46
use CGI;
47
use MARC::Record;
47
use MARC::Record;
48
use C4::Koha;
48
use C4::Koha;
49
use Koha::Utils;
49
50
50
my $query = new CGI;
51
my $query = new CGI;
51
52
(-)a/authorities/detail-biblio-search.pl (+1 lines)
Lines 47-52 use C4::Output; Link Here
47
use CGI;
47
use CGI;
48
use MARC::Record;
48
use MARC::Record;
49
use C4::Koha;
49
use C4::Koha;
50
use Koha::Utils;
50
# use C4::Biblio;
51
# use C4::Biblio;
51
# use C4::Catalogue;
52
# use C4::Catalogue;
52
53
(-)a/catalogue/MARCdetail.pl (+1 lines)
Lines 58-63 use C4::Acquisition; Link Here
58
use C4::Members; # to use GetMember
58
use C4::Members; # to use GetMember
59
use C4::Serials;    #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
59
use C4::Serials;    #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
60
use C4::Search;		# enabled_staff_search_views
60
use C4::Search;		# enabled_staff_search_views
61
use Koha::Utils;
61
62
62
63
63
my $query        = new CGI;
64
my $query        = new CGI;
(-)a/cataloguing/addbiblio.pl (+1 lines)
Lines 35-40 use C4::Branch; # XXX subfield_is_koha_internal_p Link Here
35
use C4::ClassSource;
35
use C4::ClassSource;
36
use C4::ImportBatch;
36
use C4::ImportBatch;
37
use C4::Charset;
37
use C4::Charset;
38
use Koha::Utils;
38
39
39
use Date::Calc qw(Today);
40
use Date::Calc qw(Today);
40
use MARC::File::USMARC;
41
use MARC::File::USMARC;
(-)a/cataloguing/additem.pl (+1 lines)
Lines 31-36 use C4::Koha; # XXX subfield_is_koha_internal_p Link Here
31
use C4::Branch; # XXX subfield_is_koha_internal_p
31
use C4::Branch; # XXX subfield_is_koha_internal_p
32
use C4::ClassSource;
32
use C4::ClassSource;
33
use C4::Dates;
33
use C4::Dates;
34
use Koha::Utils;
34
use List::MoreUtils qw/any/;
35
use List::MoreUtils qw/any/;
35
36
36
use MARC::File::XML;
37
use MARC::File::XML;
(-)a/cataloguing/value_builder/barcode.pl (+1 lines)
Lines 22-27 use warnings; Link Here
22
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings
22
no warnings 'redefine'; # otherwise loading up multiple plugins fills the log with subroutine redefine warnings
23
23
24
use C4::Context;
24
use C4::Context;
25
use Koha::Utils;
25
require C4::Dates;
26
require C4::Dates;
26
27
27
my $DEBUG = 0;
28
my $DEBUG = 0;
(-)a/cataloguing/value_builder/dateaccessioned.pl (+1 lines)
Lines 19-24 Link Here
19
19
20
use strict;
20
use strict;
21
#use warnings; FIXME - Bug 2505
21
#use warnings; FIXME - Bug 2505
22
use Koha::Utils;
22
23
23
=head1
24
=head1
24
25
(-)a/circ/branchoverdues.pl (+1 lines)
Lines 28-33 use C4::Biblio; Link Here
28
use C4::Koha;
28
use C4::Koha;
29
use C4::Debug;
29
use C4::Debug;
30
use C4::Branch;
30
use C4::Branch;
31
use Koha::Utils;
31
32
32
=head1 branchoverdues.pl
33
=head1 branchoverdues.pl
33
34
(-)a/installer/data/mysql/atomicupdate/bug_7430_add_searchengine_syspref (+8 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
use strict;
3
use warnings;
4
use C4::Context;
5
my $dbh=C4::Context->dbh;
6
my $searchengine = C4::Context->preference('NoZebra') ? 'NoZebra' : 'Zebra';
7
$dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('SearchEngine','" . $searchengine . "','Chooses which search engine to use in Koha.','Zebra|NoZebra','Choice');");
8
print "Upgrade done (Configured bug 7430, added new SearchEngine syspref)\n";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+7 lines)
Lines 1-6 Link Here
1
Searching:
1
Searching:
2
    Features:
2
    Features:
3
        -
3
        -
4
            - pref: SearchEngine
5
            - Use the
6
              choices:
7
                  Zebra: Zebra
8
                  NoZebra: NoZebra
9
            - search engine in Koha.
10
        -
4
            - pref: NoZebra
11
            - pref: NoZebra
5
              choices:
12
              choices:
6
                  yes: "Don't use"
13
                  yes: "Don't use"
(-)a/misc/batchImportMARCWithBiblionumbers.pl (+1 lines)
Lines 14-19 BEGIN { Link Here
14
14
15
use C4::Context;
15
use C4::Context;
16
use C4::Biblio;
16
use C4::Biblio;
17
use Koha::Utils;
17
use MARC::Record;
18
use MARC::Record;
18
use MARC::File::USMARC;
19
use MARC::File::USMARC;
19
use MARC::File::XML;
20
use MARC::File::XML;
(-)a/misc/batchRebuildBiblioTables.pl (+1 lines)
Lines 16-21 BEGIN { Link Here
16
use MARC::Record;
16
use MARC::Record;
17
use C4::Context;
17
use C4::Context;
18
use C4::Biblio;
18
use C4::Biblio;
19
use Koha::Utils;
19
use Time::HiRes qw(gettimeofday);
20
use Time::HiRes qw(gettimeofday);
20
21
21
use Getopt::Long;
22
use Getopt::Long;
(-)a/misc/migration_tools/22_to_30/missing090field.pl (+1 lines)
Lines 15-20 BEGIN { Link Here
15
15
16
use C4::Context;
16
use C4::Context;
17
use C4::Biblio;
17
use C4::Biblio;
18
use Koha::Utils;
18
use MARC::Record;
19
use MARC::Record;
19
use MARC::File::USMARC;
20
use MARC::File::USMARC;
20
21
(-)a/misc/migration_tools/bulkmarcimport.pl (+1 lines)
Lines 17-22 use MARC::File::XML; Link Here
17
use MARC::Record;
17
use MARC::Record;
18
use MARC::Batch;
18
use MARC::Batch;
19
use MARC::Charset;
19
use MARC::Charset;
20
use Koha::Utils;
20
21
21
use C4::Context;
22
use C4::Context;
22
use C4::Biblio;
23
use C4::Biblio;
(-)a/misc/migration_tools/merge_authority.pl (+1 lines)
Lines 15-20 use C4::Context; Link Here
15
use C4::Search;
15
use C4::Search;
16
use C4::Biblio;
16
use C4::Biblio;
17
use C4::AuthoritiesMarc;
17
use C4::AuthoritiesMarc;
18
use Koha::Utils;
18
use Time::HiRes qw(gettimeofday);
19
use Time::HiRes qw(gettimeofday);
19
20
20
use Getopt::Long;
21
use Getopt::Long;
(-)a/misc/migration_tools/rebuild_nozebra.pl (-4 / +6 lines)
Lines 2-9 Link Here
2
2
3
use C4::Context;
3
use C4::Context;
4
use Getopt::Long;
4
use Getopt::Long;
5
use C4::Search;
5
use C4::Biblio;
6
use C4::Biblio;
6
use C4::AuthoritiesMarc;
7
use C4::AuthoritiesMarc;
8
use Koha::Utils;
7
9
8
use strict;
10
use strict;
9
#use warnings; FIXME - Bug 2505
11
#use warnings; FIXME - Bug 2505
Lines 76-82 $dbh->do("update systempreferences set value=1 where variable='NoZebra'"); Link Here
76
78
77
$dbh->do("truncate nozebra");
79
$dbh->do("truncate nozebra");
78
80
79
my %index = GetNoZebraIndexes();
81
my %index = GetIndexes();
80
82
81
if  (!%index || $sysprefs ) {
83
if  (!%index || $sysprefs ) {
82
    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
84
    if (C4::Context->preference('marcflavour') eq 'UNIMARC') {
Lines 94-100 if (!%index || $sysprefs ) { Link Here
94
        'subject' => '600*,601*,606*,610*',
96
        'subject' => '600*,601*,606*,610*',
95
        'dewey' => '676a',
97
        'dewey' => '676a',
96
        'host-item' => '995a,995c',\" where variable='NoZebraIndexes'");
98
        'host-item' => '995a,995c',\" where variable='NoZebraIndexes'");
97
        %index = GetNoZebraIndexes();
99
        %index = GetIndexes();
98
    } elsif (C4::Context->preference('marcflavour') eq 'MARC21') {
100
    } elsif (C4::Context->preference('marcflavour') eq 'MARC21') {
99
        $dbh->do("UPDATE systempreferences SET value=\"
101
        $dbh->do("UPDATE systempreferences SET value=\"
100
'title' => '130a,210a,222a,240a,243a,245a,245b,246a,246b,247a,247b,250a,250b,440a,830a',
102
'title' => '130a,210a,222a,240a,243a,245a,245b,246a,246b,247a,247b,250a,250b,440a,830a',
Lines 118-124 if (!%index || $sysprefs ) { Link Here
118
'collection' => '9528',
120
'collection' => '9528',
119
\"WHERE variable='NoZebraIndexes'");
121
\"WHERE variable='NoZebraIndexes'");
120
122
121
        %index = GetNoZebraIndexes();
123
        %index = GetIndexes();
122
    }
124
    }
123
}
125
}
124
$|=1;
126
$|=1;
Lines 254-260 while (my ($authid) = $sth->fetchrow) { Link Here
254
    
256
    
255
    my %index;
257
    my %index;
256
    # for authorities, the "title" is the $a mainentry
258
    # for authorities, the "title" is the $a mainentry
257
    my $authref = C4::AuthoritiesMarc::GetAuthType(C4::AuthoritiesMarc::GetAuthTypeCode($authid));
259
    my $authref = GetAuthType(C4::AuthoritiesMarc::GetAuthTypeCode($authid));
258
260
259
    warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
261
    warn "ERROR : authtype undefined for ".$record->as_formatted unless $authref;
260
    my $title = $record->subfield($authref->{auth_tag_to_report},'a');
262
    my $title = $record->subfield($authref->{auth_tag_to_report},'a');
(-)a/misc/migration_tools/rebuild_zebra.pl (+1 lines)
Lines 10-15 use File::Path; Link Here
10
use C4::Biblio;
10
use C4::Biblio;
11
use C4::AuthoritiesMarc;
11
use C4::AuthoritiesMarc;
12
use C4::Items;
12
use C4::Items;
13
use Koha::Utils;
13
14
14
# 
15
# 
15
# script that checks zebradir structure & create directories & mandatory files if needed
16
# script that checks zebradir structure & create directories & mandatory files if needed
(-)a/opac/opac-MARCdetail.pl (+1 lines)
Lines 52-57 use MARC::Record; Link Here
52
use C4::Biblio;
52
use C4::Biblio;
53
use C4::Acquisition;
53
use C4::Acquisition;
54
use C4::Koha;
54
use C4::Koha;
55
use Koha::Utils;
55
56
56
my $query = new CGI;
57
my $query = new CGI;
57
58
(-)a/opac/opac-authoritiesdetail.pl (+1 lines)
Lines 46-51 use C4::Output; Link Here
46
use CGI;
46
use CGI;
47
use MARC::Record;
47
use MARC::Record;
48
use C4::Koha;
48
use C4::Koha;
49
use Koha::Utils;
49
50
50
51
51
my $query = new CGI;
52
my $query = new CGI;
(-)a/serials/serials-edit.pl (+1 lines)
Lines 72-77 use C4::Koha; Link Here
72
use C4::Output;
72
use C4::Output;
73
use C4::Context;
73
use C4::Context;
74
use C4::Serials;
74
use C4::Serials;
75
use Koha::Utils;
75
use List::MoreUtils qw/uniq/;
76
use List::MoreUtils qw/uniq/;
76
77
77
my $query           = CGI->new();
78
my $query           = CGI->new();
(-)a/svc/bib (+1 lines)
Lines 24-29 use warnings; Link Here
24
use CGI;
24
use CGI;
25
use C4::Auth qw/check_api_auth/;
25
use C4::Auth qw/check_api_auth/;
26
use C4::Biblio;
26
use C4::Biblio;
27
use Koha::Utils;
27
use XML::Simple;
28
use XML::Simple;
28
29
29
my $query = new CGI;
30
my $query = new CGI;
(-)a/svc/new_bib (+1 lines)
Lines 26-31 use C4::Auth qw/check_api_auth/; Link Here
26
use C4::Biblio;
26
use C4::Biblio;
27
use XML::Simple;
27
use XML::Simple;
28
use C4::Charset;
28
use C4::Charset;
29
use Koha::Utils;
29
30
30
my $query = new CGI;
31
my $query = new CGI;
31
binmode STDOUT, ":utf8";
32
binmode STDOUT, ":utf8";
(-)a/t/db_dependent/lib/KohaTest/AuthoritiesMarc.pm (-1 lines)
Lines 23-29 sub methods : Test( 1 ) { Link Here
23
                      ModAuthority 
23
                      ModAuthority 
24
                      GetAuthorityXML 
24
                      GetAuthorityXML 
25
                      GetAuthority 
25
                      GetAuthority 
26
                      GetAuthType 
27
                      FindDuplicateAuthority 
26
                      FindDuplicateAuthority 
28
                      BuildSummary
27
                      BuildSummary
29
                      BuildUnimarcHierarchies
28
                      BuildUnimarcHierarchies
(-)a/t/db_dependent/lib/KohaTest/Biblio/ModBiblio.pm (+1 lines)
Lines 8-13 use Test::More; Link Here
8
8
9
use C4::Biblio;
9
use C4::Biblio;
10
use C4::Items;
10
use C4::Items;
11
use Koha::Utils;
11
12
12
=head2 STARTUP METHODS
13
=head2 STARTUP METHODS
13
14
(-)a/t/db_dependent/lib/KohaTest/ImportBatch/BatchStageCommitRevert.pm (+1 lines)
Lines 9-14 use Test::More; Link Here
9
use C4::ImportBatch;
9
use C4::ImportBatch;
10
use C4::Matcher;
10
use C4::Matcher;
11
use C4::Biblio;
11
use C4::Biblio;
12
use Koha::Utils;
12
13
13
# define test records for various batches
14
# define test records for various batches
14
sub startup_60_make_test_records : Test( startup ) {
15
sub startup_60_make_test_records : Test( startup ) {
(-)a/tools/batchMod.pl (+1 lines)
Lines 33-38 use C4::BackgroundJob; Link Here
33
use C4::ClassSource;
33
use C4::ClassSource;
34
use C4::Dates;
34
use C4::Dates;
35
use C4::Debug;
35
use C4::Debug;
36
use Koha::Utils;
36
use MARC::File::XML;
37
use MARC::File::XML;
37
38
38
my $input = new CGI;
39
my $input = new CGI;
(-)a/tools/export.pl (-1 / +1 lines)
Lines 25-30 use C4::Biblio; # GetMarcBiblio GetXmlBiblio Link Here
25
use CGI;
25
use CGI;
26
use C4::Koha;    # GetItemTypes
26
use C4::Koha;    # GetItemTypes
27
use C4::Branch;  # GetBranches
27
use C4::Branch;  # GetBranches
28
use Koha::Utils;
28
29
29
my $query = new CGI;
30
my $query = new CGI;
30
my $op=$query->param("op") || '';
31
my $op=$query->param("op") || '';
31
- 

Return to bug 7430