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

(-)a/C4/Search.pm (-16 / +21 lines)
Lines 1194-1204 sub parseQuery { Link Here
1194
        }
1194
        }
1195
        foreach my $limit (@limits) {
1195
        foreach my $limit (@limits) {
1196
        }
1196
        }
1197
        foreach my $modifier (@sort_by) {
1197
        if (scalar (@sort_by) > 0) {
1198
            $query .= " #$modifier";
1198
            my $modifier_re = '#(' . join( '|', @{$QParser->modifiers}) . ')';
1199
            $query =~ s/$modifier_re//g;
1200
            foreach my $modifier (@sort_by) {
1201
                $query .= " #$modifier";
1202
            }
1199
        }
1203
        }
1200
1204
1201
        $query_desc = $query;
1205
        $query_desc = $query;
1206
        $query_desc =~ s/\s+/ /g;
1202
        if ( C4::Context->preference("QueryWeightFields") ) {
1207
        if ( C4::Context->preference("QueryWeightFields") ) {
1203
        }
1208
        }
1204
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-br', { 'callback' => \&_handle_exploding_index });
1209
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-br', { 'callback' => \&_handle_exploding_index });
Lines 1206-1214 sub parseQuery { Link Here
1206
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-rl', { 'callback' => \&_handle_exploding_index });
1211
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-rl', { 'callback' => \&_handle_exploding_index });
1207
        $QParser->parse( $query );
1212
        $QParser->parse( $query );
1208
        $operands[0] = "pqf=" . $QParser->target_syntax('biblioserver');
1213
        $operands[0] = "pqf=" . $QParser->target_syntax('biblioserver');
1209
# TODO: once we are using QueryParser, all this special case code for
1214
    } else {
1210
#       exploded search indexes will be replaced by a callback to
1215
        my $modifier_re = '#(' . join( '|', @{Koha::QueryParser::Driver::PQF->modifiers}) . ')';
1211
#       _handle_exploding_index
1216
        s/$modifier_re//g for @operands;
1212
    }
1217
    }
1213
1218
1214
    return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang, $query_desc);
1219
    return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang, $query_desc);
Lines 1292-1308 sub buildQuery { Link Here
1292
        if ( @limits ) {
1297
        if ( @limits ) {
1293
            $q .= ' and '.join(' and ', @limits);
1298
            $q .= ' and '.join(' and ', @limits);
1294
        }
1299
        }
1295
        return ( undef, $q, $q, "q=ccl=$q", $q, '', '', '', '', 'ccl' );
1300
        return ( undef, $q, $q, "q=ccl=".uri_escape($q), $q, '', '', '', '', 'ccl' );
1296
    }
1301
    }
1297
    if ( $query =~ /^cql=/ ) {
1302
    if ( $query =~ /^cql=/ ) {
1298
        return ( undef, $', $', "q=cql=$'", $', '', '', '', '', 'cql' );
1303
        return ( undef, $', $', "q=cql=".uri_escape($'), $', '', '', '', '', 'cql' );
1299
    }
1304
    }
1300
    if ( $query =~ /^pqf=/ ) {
1305
    if ( $query =~ /^pqf=/ ) {
1301
        if ($query_desc) {
1306
        if ($query_desc) {
1302
            $query_cgi = "q=$query_desc";
1307
            $query_cgi = "q=".uri_escape($query_desc);
1303
        } else {
1308
        } else {
1304
            $query_desc = $';
1309
            $query_desc = $';
1305
            $query_cgi = "q=pqf=$'";
1310
            $query_cgi = "q=pqf=".uri_escape($');
1306
        }
1311
        }
1307
        return ( undef, $', $', $query_cgi, $query_desc, '', '', '', '', 'pqf' );
1312
        return ( undef, $', $', $query_cgi, $query_desc, '', '', '', '', 'pqf' );
1308
    }
1313
    }
Lines 1474-1482 sub buildQuery { Link Here
1474
                        $query     .= " $operators[$i-1] ";
1479
                        $query     .= " $operators[$i-1] ";
1475
                        $query     .= " $index_plus " unless $indexes_set;
1480
                        $query     .= " $index_plus " unless $indexes_set;
1476
                        $query     .= " $operand";
1481
                        $query     .= " $operand";
1477
                        $query_cgi .= "&op=$operators[$i-1]";
1482
                        $query_cgi .= "&op=".uri_escape($operators[$i-1]);
1478
                        $query_cgi .= "&idx=$index" if $index;
1483
                        $query_cgi .= "&idx=".uri_escape($index) if $index;
1479
                        $query_cgi .= "&q=$operands[$i]" if $operands[$i];
1484
                        $query_cgi .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1480
                        $query_desc .=
1485
                        $query_desc .=
1481
                          " $operators[$i-1] $index_plus $operands[$i]";
1486
                          " $operators[$i-1] $index_plus $operands[$i]";
1482
                    }
1487
                    }
Lines 1486-1493 sub buildQuery { Link Here
1486
                        $query      .= " and ";
1491
                        $query      .= " and ";
1487
                        $query      .= "$index_plus " unless $indexes_set;
1492
                        $query      .= "$index_plus " unless $indexes_set;
1488
                        $query      .= "$operand";
1493
                        $query      .= "$operand";
1489
                        $query_cgi  .= "&op=and&idx=$index" if $index;
1494
                        $query_cgi  .= "&op=and&idx=".uri_escape($index) if $index;
1490
                        $query_cgi  .= "&q=$operands[$i]" if $operands[$i];
1495
                        $query_cgi  .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1491
                        $query_desc .= " and $index_plus $operands[$i]";
1496
                        $query_desc .= " and $index_plus $operands[$i]";
1492
                    }
1497
                    }
1493
                }
1498
                }
Lines 1499-1506 sub buildQuery { Link Here
1499
                    $query .= " $index_plus " unless $indexes_set;
1504
                    $query .= " $index_plus " unless $indexes_set;
1500
                    $query .= $operand;
1505
                    $query .= $operand;
1501
                    $query_desc .= " $index_plus $operands[$i]";
1506
                    $query_desc .= " $index_plus $operands[$i]";
1502
                    $query_cgi  .= "&idx=$index" if $index;
1507
                    $query_cgi  .= "&idx=".uri_escape($index) if $index;
1503
                    $query_cgi  .= "&q=$operands[$i]" if $operands[$i];
1508
                    $query_cgi  .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1504
                    $previous_operand = 1;
1509
                    $previous_operand = 1;
1505
                }
1510
                }
1506
            }    #/if $operands
1511
            }    #/if $operands
(-)a/opac/opac-search.pl (-2 / +7 lines)
Lines 358-367 unless (@servers) { Link Here
358
# operators include boolean and proximity operators and are used
358
# operators include boolean and proximity operators and are used
359
# to evaluate multiple operands
359
# to evaluate multiple operands
360
my @operators = $cgi->param('op');
360
my @operators = $cgi->param('op');
361
@operators = map { uri_unescape($_) } @operators;
361
362
362
# indexes are query qualifiers, like 'title', 'author', etc. They
363
# indexes are query qualifiers, like 'title', 'author', etc. They
363
# can be single or multiple parameters separated by comma: kw,right-Truncation 
364
# can be single or multiple parameters separated by comma: kw,right-Truncation 
364
my @indexes = $cgi->param('idx');
365
my @indexes = $cgi->param('idx');
366
@indexes = map { uri_unescape($_) } @indexes;
365
367
366
# if a simple index (only one)  display the index used in the top search box
368
# if a simple index (only one)  display the index used in the top search box
367
if ($indexes[0] && !$indexes[1]) {
369
if ($indexes[0] && !$indexes[1]) {
Lines 369-384 if ($indexes[0] && !$indexes[1]) { Link Here
369
}
371
}
370
# an operand can be a single term, a phrase, or a complete ccl query
372
# an operand can be a single term, a phrase, or a complete ccl query
371
my @operands = $cgi->param('q');
373
my @operands = $cgi->param('q');
374
@operands = map { uri_unescape($_) } @operands;
372
375
373
$template->{VARS}->{querystring} = join(' ', @operands);
376
$template->{VARS}->{querystring} = join(' ', @operands);
374
377
375
# if a simple search, display the value in the search box
378
# if a simple search, display the value in the search box
376
if ($operands[0] && !$operands[1]) {
379
if ($operands[0] && !$operands[1]) {
377
    $template->param(ms_value => $operands[0]);
380
    my $ms_query = $operands[0];
381
    $ms_query =~ s/ #\S+//;
382
    $template->param(ms_value => $ms_query);
378
}
383
}
379
384
380
# limits are use to limit to results to a pre-defined category such as branch or language
385
# limits are use to limit to results to a pre-defined category such as branch or language
381
my @limits = $cgi->param('limit');
386
my @limits = $cgi->param('limit');
387
@limits = map { uri_unescape($_) } @limits;
382
388
383
if($params->{'multibranchlimit'}) {
389
if($params->{'multibranchlimit'}) {
384
    push @limits, '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
390
    push @limits, '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')';
385
- 

Return to bug 9239