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

(-)a/C4/AuthoritiesMarc.pm (-27 / +115 lines)
Lines 842-883 Comments : an improvement would be to return All the records that match. Link Here
842
842
843
=cut
843
=cut
844
844
845
sub _find_duplicate_authority_try {
846
    my ($try, $authorityfield, $authtypecode) = @_;
847
848
    my $filtervalues = qr([\001-\040\Q!'"`#$%&*+,-./:;<=>?@(){[}_|~\E\]]);
849
850
    my $op = 'and';
851
    if (C4::Context->preference('UseQueryParser')) {
852
        my $QParser = C4::Context->queryparser;
853
        if ($QParser) {
854
            $op = '&&';
855
        } else {
856
            $op = 'and';
857
        }
858
    }
859
860
    # build a request for SearchAuthorities
861
    my $query = "at=$authtypecode";
862
863
    my $duplicaterecord;
864
    if ($try->{field} and $try->{subfields}) {
865
        foreach my $s (@{ $try->{subfields} }) {
866
            my $v = $authorityfield->subfield($s);
867
            if ($v) {
868
                $v =~ s/$filtervalues/ /g;
869
                $v =~ s/^\s*//;
870
                $v =~ s/\s*$//;
871
                $query .= qq/ $op $try->{index}="$v"/;
872
            }
873
        }
874
        my $maxresults = C4::Context->preference('FindDuplicateAuthorityMaxResults') || 10;
875
        my ($error, $results, $total_hits) =
876
            C4::Search::SimpleSearch($query, 0, $maxresults, ["authorityserver"]);
877
        return unless (!defined $error and @{$results});
878
879
        foreach my $result (@$results) {
880
            my $marcrecord =
881
              C4::Search::new_record_from_zebra( 'authorityserver', $result );
882
            my @marcfields = $marcrecord->field($try->{field});
883
            next if (scalar @marcfields == 0);
884
            my $stillmatch = 1;
885
            foreach my $marcfield (@marcfields) {
886
                foreach my $subfield (@{ $try->{subfields} }) {
887
                    my $authoritysubfield = $authorityfield->subfield($subfield);
888
                    my $marcsubfield = $marcfield->subfield($subfield);
889
                    if ( (defined $authoritysubfield xor defined $marcsubfield)
890
                      or (defined $authoritysubfield
891
                        and $authoritysubfield ne $marcsubfield)
892
                    ) {
893
                        $stillmatch = 0;
894
                        last;
895
                    }
896
                }
897
                last unless $stillmatch;
898
            }
899
            if ($stillmatch) {
900
                $duplicaterecord = $marcrecord;
901
                last;
902
            }
903
        }
904
    } else {
905
        foreach my $s ($authorityfield->subfields()) {
906
            next unless ($s->[0] =~ /[A-z]/);
907
            $s->[1] =~ s/$filtervalues/ /g;
908
            $query .= qq/ $op $try->{index}="$s->[1]"/;
909
        }
910
        my ($error, $results, $total_hits) =
911
            C4::Search::SimpleSearch( $query, 0, 1, ["authorityserver"] );
912
        if (!defined $error and @{$results}) {
913
            $duplicaterecord =
914
              C4::Search::new_record_from_zebra( 'authorityserver',
915
                $results->[0] );
916
        }
917
    }
918
919
    return $duplicaterecord;
920
}
921
845
sub FindDuplicateAuthority {
922
sub FindDuplicateAuthority {
923
    my ($record, $authtypecode) = @_;
924
925
    return unless $record;
926
927
    my $opts = C4::Context->preference('FindDuplicateAuthorityOptions');
928
    return unless $opts;
846
929
847
    my ($record,$authtypecode)=@_;
848
#    warn "IN for ".$record->as_formatted;
849
    my $dbh = C4::Context->dbh;
930
    my $dbh = C4::Context->dbh;
850
#    warn "".$record->as_formatted;
931
    my $sth = $dbh->prepare("
851
    my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
932
        SELECT auth_tag_to_report FROM auth_types WHERE authtypecode = ?
933
    ");
852
    $sth->execute($authtypecode);
934
    $sth->execute($authtypecode);
853
    my ($auth_tag_to_report) = $sth->fetchrow;
935
    my ($auth_tag_to_report) = $sth->fetchrow;
854
    $sth->finish;
936
    $sth->finish;
855
#     warn "record :".$record->as_formatted."  auth_tag_to_report :$auth_tag_to_report";
937
856
    # build a request for SearchAuthorities
938
    my $authorityfield = $record->field($auth_tag_to_report);
857
    my $QParser;
939
    return unless $authorityfield;
858
    $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
940
859
    my $op;
941
    my @tries;
860
    if ($QParser) {
942
    $opts =~ s/ //g;
861
        $op = '&&';
943
    foreach my $try (split /\|/, $opts) {
862
    } else {
944
        my ($index, $matchcheck) = split m#/#, $try;
863
        $op = 'and';
945
        my ($field, @subfields);
864
    }
946
        if ($matchcheck and length($matchcheck) > 3) {
865
    my $query='at:'.$authtypecode.' ';
947
            $field = substr $matchcheck, 0, 3;
866
    my $filtervalues=qr([\001-\040\Q!'"`#$%&*+,-./:;<=>?@(){[}_|~\E\]]);
948
            @subfields = split(//, substr($matchcheck, 3));
867
    if ($record->field($auth_tag_to_report)) {
868
        foreach ($record->field($auth_tag_to_report)->subfields()) {
869
            $_->[1]=~s/$filtervalues/ /g; $query.= " $op he:\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
870
        }
949
        }
950
        push @tries, {
951
            index => $index,
952
            field => $field,
953
            subfields => \@subfields,
954
        };
871
    }
955
    }
872
    my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
956
873
    # there is at least 1 result => return the 1st one
957
    my $duplicaterecord;
874
    if (!defined $error && @{$results} ) {
958
    foreach my $try (@tries) {
875
        my $marcrecord = C4::Search::new_record_from_zebra(
959
        $duplicaterecord = _find_duplicate_authority_try($try, $authorityfield,
876
            'authorityserver',
960
            $authtypecode);
877
            $results->[0]
961
        last if $duplicaterecord;
878
        );
962
    }
879
        return $marcrecord->field('001')->data,BuildSummary($marcrecord,$marcrecord->field('001')->data,$authtypecode);
963
964
    if ($duplicaterecord) {
965
        my $authid = $duplicaterecord->field('001')->data;
966
        return $authid, BuildSummary($duplicaterecord, $authid, $authtypecode);
880
    }
967
    }
968
881
    # no result, returns nothing
969
    # no result, returns nothing
882
    return;
970
    return;
883
}
971
}
(-)a/installer/data/mysql/atomicupdate/bug_8994.sql (+4 lines)
Line 0 Link Here
1
INSERT INTO systempreferences (variable, value, explanation, options, type)
2
VALUES
3
('FindDuplicateAuthorityOptions', 'he,wrdl', 'Options to determine how to search for duplicate authorities. General form: "index1/XXXcc#index2" where indexX is the index where we want to search, and XXXcc the field(s) and subfield(s) we want to check for each search results (if omitted, the first result is returned as duplicate)', NULL, 'Free'),
4
('FindDuplicateAuthorityMaxResults', '10', 'Maximum number of results fetched when searching a duplicate', NULL, 'Integer');
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 131-136 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
131
('FacetLabelTruncationLength','20',NULL,'Specify the facet max length in OPAC','Integer'),
131
('FacetLabelTruncationLength','20',NULL,'Specify the facet max length in OPAC','Integer'),
132
('FacetMaxCount','20',NULL,'Specify the max facet count for each category','Integer'),
132
('FacetMaxCount','20',NULL,'Specify the max facet count for each category','Integer'),
133
('FilterBeforeOverdueReport','0','','Do not run overdue report until filter selected','YesNo'),
133
('FilterBeforeOverdueReport','0','','Do not run overdue report until filter selected','YesNo'),
134
('FindDuplicateAuthorityOptions','he,wrdl',NULL,'Options to determine how to search for duplicate authorities. General form: "index1/XXXcc|index2" where indexX is the index where we want to search, and XXXcc the field(s) and subfield(s) we want to check for each search results (if omitted, the first result is returned as duplicate)','Free'),
135
('FindDuplicateAuthorityMaxResults','10',NULL'Maximum number of results fetched when searching a duplicate','Free'),
134
('FineNotifyAtCheckin','0',NULL,'If ON notify librarians of overdue fines on the items they are checking in.','YesNo'),
136
('FineNotifyAtCheckin','0',NULL,'If ON notify librarians of overdue fines on the items they are checking in.','YesNo'),
135
('finesCalendar','noFinesWhenClosed','ignoreCalendar|noFinesWhenClosed','Specify whether to use the Calendar in calculating duedates and fines','Choice'),
137
('finesCalendar','noFinesWhenClosed','ignoreCalendar|noFinesWhenClosed','Specify whether to use the Calendar in calculating duedates and fines','Choice'),
136
('FinesIncludeGracePeriod','1',NULL,'If enabled, fines calculations will include the grace period.','YesNo'),
138
('FinesIncludeGracePeriod','1',NULL,'If enabled, fines calculations will include the grace period.','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref (-1 / +19 lines)
Lines 49-54 Authorities: Link Here
49
              defautl: "afrey50      ba0"
49
              defautl: "afrey50      ba0"
50
              type: textarea
50
              type: textarea
51
              class: code
51
              class: code
52
        -
53
            - pref: FindDuplicateAuthorityOptions
54
              class: long
55
            - '<br />Options to determine how to search for duplicate authorities when creating new authorities. General form: "index1/XXXcc | index2" where indexX is the index where we want to search, and XXXcc the field(s) and subfield(s) we want to check for each search results (if "XXXcc" part is omitted, the first result is returned as duplicate)'
56
            - '<br />Examples:'
57
            - '<br />- <tt>he,wrdl</tt>: Search in "he" index, do not check subfields data in search results, the first result is returned as a duplicate (default).'
58
            - '<br />- <tt>he,wrdl/2..ab</tt>: Search in "he" index, and compare 2XX$a and 2XX$b of search results with XXX$a and XXX$b of created authority (XXX is the "Authority field to copy"). The first matching authority is returned as duplicate.'
59
            - '<br />- <tt>he,wrdl | See,wrdl/4..ab</tt>: Search in "he" index and do not check subfields. If there is no results, search in "See" index and compare 4XX$a and 4XX$b of search results with XXX$a and XXX$b of created authority.'
60
            - '<br />Notes:'
61
            - '<br />- only authorities of the same type are returned by the search'
62
            - '<br />- the query to find authorities is build with subfields in syspref. For example <tt>he,wrdl/2..ab</tt> will search <tt>he,wrdl="2XX$a" and "he,wrdl="2XX$b"</tt>'
63
            - '<br />- if compared subfields are repeatable, only the first of each field is checked'
64
            - '<br />- spaces are insignificant'
65
            - '<br />- if value is empty, it disable authority duplicate searching.'
66
        -
67
            - 'Maximum number of results fetched when searching a duplicate:'
68
            - pref: FindDuplicateAuthorityMaxResults
69
              class: integer
70
            - "It's only used when FindDuplicateAuthorityOptions contains fields and subfields to check against (default: 10)"
52
    Linker:
71
    Linker:
53
        -
72
        -
54
            - Use the
73
            - Use the
55
- 

Return to bug 8994