Bugzilla – Attachment 16192 Details for
Bug 9239
Koha should share Evergreen's QueryParser module for parsing queries
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9239 QA follow-up: better error handling
Bug-9239-QA-follow-up-better-error-handling.patch (text/plain), 5.81 KB, created by
Jared Camins-Esakov
on 2013-03-17 01:28:46 UTC
(
hide
)
Description:
Bug 9239 QA follow-up: better error handling
Filename:
MIME Type:
Creator:
Jared Camins-Esakov
Created:
2013-03-17 01:28:46 UTC
Size:
5.81 KB
patch
obsolete
>From f1a72b9a65fc80d6239ff38b9a18585d9f2e50ac Mon Sep 17 00:00:00 2001 >From: Jared Camins-Esakov <jcamins@cpbibliography.com> >Date: Thu, 14 Mar 2013 08:43:13 -0400 >Subject: [PATCH] Bug 9239 QA follow-up: better error handling > >* Fix a long-standing bug in the linker that could crash the linker when >run against odd data. >* Sanitize input to SimpleSearch. >* Correctly handle CCL indexes with QP. > >Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> >Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com> >--- > C4/AuthoritiesMarc.pm | 1 + > C4/Search.pm | 40 +++++++++++++++++++++++++--------------- > 2 files changed, 26 insertions(+), 15 deletions(-) > >diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm >index 5d66e48..db06f3d 100644 >--- a/C4/AuthoritiesMarc.pm >+++ b/C4/AuthoritiesMarc.pm >@@ -1213,6 +1213,7 @@ sub GetAuthorizedHeading { > unless ($record = $args->{record}) { > return unless $args->{authid}; > $record = GetAuthority($args->{authid}); >+ return unless $record; > } > if (C4::Context->preference('marcflavour') eq 'UNIMARC') { > # construct UNIMARC summary, that is quite different from MARC21 one >diff --git a/C4/Search.pm b/C4/Search.pm >index d20e403..e97c956 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -253,6 +253,7 @@ sub SimpleSearch { > $query = $QParser->target_syntax($servers[$i]); > $zoom_queries[$i] = new ZOOM::Query::PQF( $query, $zconns[$i]); > } else { >+ $query =~ s/:/=/g; > $zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]); > } > $tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] ); >@@ -1117,7 +1118,7 @@ on authority data). > =cut > > sub _handle_exploding_index { >- my ($QParser, $struct, $filter, $params, $negate, $server) = @_; >+ my ($QParser, $filter, $params, $negate, $server) = @_; > my $index = $filter; > my $term = join(' ', @$params); > >@@ -1127,7 +1128,7 @@ sub _handle_exploding_index { > > my $codesubfield = $marcflavour eq 'UNIMARC' ? '5' : 'w'; > my $wantedcodes = ''; >- my @subqueries = ( "su:\"$term\""); >+ my @subqueries = ( "\@attr 1=Subject \@attr 4=1 \"$term\""); > my ($error, $results, $total_hits) = SimpleSearch( "he:$term", undef, undef, [ "authorityserver" ] ); > foreach my $auth (@$results) { > my $record = MARC::Record->new_from_usmarc($auth); >@@ -1142,12 +1143,11 @@ sub _handle_exploding_index { > } > foreach my $reference (@references) { > my $codes = $reference->subfield($codesubfield); >- push @subqueries, 'su:"' . $reference->as_string('abcdefghijlmnopqrstuvxyz') . '"' if (($codes && $codes eq $wantedcodes) || !$wantedcodes); >+ push @subqueries, '@attr 1=Subject @attr 4=1 "' . $reference->as_string('abcdefghijlmnopqrstuvxyz') . '"' if (($codes && $codes eq $wantedcodes) || !$wantedcodes); > } > } > } >- my $query = '(' x scalar(@subqueries) . join(') || ', @subqueries) . ')'; >- warn $query; >+ my $query = ' @or ' x (scalar(@subqueries) - 1) . join(' ', @subqueries); > return $query; > } > >@@ -1179,7 +1179,7 @@ sub parseQuery { > > my $QParser; > $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser') || $query =~ s/^qp=//); >- undef $QParser if ($query =~ m/^(ccl=|pqf=|cql=)/ || grep (/\w,\w|\w=\w/, @operands) ); >+ undef $QParser if ($query =~ m/^(ccl=|pqf=|cql=)/ || grep (/\w,\w|\w=\w/, @operands, @indexes) ); > undef $QParser if (scalar @limits > 0); > > if ($QParser) >@@ -1189,13 +1189,19 @@ sub parseQuery { > next unless $operands[$ii]; > $query .= $operators[ $ii - 1 ] eq 'or' ? ' || ' : ' && ' > if ($query); >- $query .= >- ( $indexes[$ii] ? "$indexes[$ii]:" : '' ) . $operands[$ii]; >+ if ( $indexes[$ii] =~ m/su-/ ) { >+ $query .= $indexes[$ii] . '(' . $operands[$ii] . ')'; >+ } >+ else { >+ $query .= >+ ( $indexes[$ii] ? "$indexes[$ii]:" : '' ) . $operands[$ii]; >+ } > } > foreach my $limit (@limits) { > } >- if (scalar (@sort_by) > 0) { >- my $modifier_re = '#(' . join( '|', @{$QParser->modifiers}) . ')'; >+ if ( scalar(@sort_by) > 0 ) { >+ my $modifier_re = >+ '#(' . join( '|', @{ $QParser->modifiers } ) . ')'; > $query =~ s/$modifier_re//g; > foreach my $modifier (@sort_by) { > $query .= " #$modifier"; >@@ -1206,12 +1212,16 @@ sub parseQuery { > $query_desc =~ s/\s+/ /g; > if ( C4::Context->preference("QueryWeightFields") ) { > } >- $QParser->add_bib1_filter_map( 'biblioserver', 'su-br', { 'callback' => \&_handle_exploding_index }); >- $QParser->add_bib1_filter_map( 'biblioserver', 'su-na', { 'callback' => \&_handle_exploding_index }); >- $QParser->add_bib1_filter_map( 'biblioserver', 'su-rl', { 'callback' => \&_handle_exploding_index }); >- $QParser->parse( $query ); >+ $QParser->add_bib1_filter_map( 'su-br' => 'biblioserver' => >+ { 'target_syntax_callback' => \&_handle_exploding_index } ); >+ $QParser->add_bib1_filter_map( 'su-na' => 'biblioserver' => >+ { 'target_syntax_callback' => \&_handle_exploding_index } ); >+ $QParser->add_bib1_filter_map( 'su-rl' => 'biblioserver' => >+ { 'target_syntax_callback' => \&_handle_exploding_index } ); >+ $QParser->parse($query); > $operands[0] = "pqf=" . $QParser->target_syntax('biblioserver'); >- } else { >+ } >+ else { > require Koha::QueryParser::Driver::PQF; > my $modifier_re = '#(' . join( '|', @{Koha::QueryParser::Driver::PQF->modifiers}) . ')'; > s/$modifier_re//g for @operands; >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9239
:
14020
|
14021
|
14022
|
14023
|
14172
|
14173
|
14174
|
14175
|
14180
|
14181
|
14182
|
14183
|
14847
|
14949
|
14950
|
14951
|
14952
|
14953
|
15121
|
15437
|
15865
|
15867
|
15929
|
15999
|
16004
|
16051
|
16125
|
16130
|
16131
|
16132
|
16133
|
16136
|
16140
|
16141
|
16142
|
16143
|
16144
|
16145
|
16146
|
16147
|
16148
|
16149
|
16150
|
16151
|
16152
|
16153
|
16154
|
16155
|
16180
|
16181
|
16182
|
16183
|
16184
|
16185
|
16186
|
16187
|
16188
|
16189
|
16190
|
16191
| 16192 |
16193
|
16194
|
16195