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

(-)a/C4/Search.pm (-16 / +21 lines)
Lines 1193-1203 sub parseQuery { Link Here
1193
        }
1193
        }
1194
        foreach my $limit (@limits) {
1194
        foreach my $limit (@limits) {
1195
        }
1195
        }
1196
        foreach my $modifier (@sort_by) {
1196
        if (scalar (@sort_by) > 0) {
1197
            $query .= " #$modifier";
1197
            my $modifier_re = '#(' . join( '|', @{$QParser->modifiers}) . ')';
1198
            $query =~ s/$modifier_re//g;
1199
            foreach my $modifier (@sort_by) {
1200
                $query .= " #$modifier";
1201
            }
1198
        }
1202
        }
1199
1203
1200
        $query_desc = $query;
1204
        $query_desc = $query;
1205
        $query_desc =~ s/\s+/ /g;
1201
        if ( C4::Context->preference("QueryWeightFields") ) {
1206
        if ( C4::Context->preference("QueryWeightFields") ) {
1202
        }
1207
        }
1203
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-br', { 'callback' => \&_handle_exploding_index });
1208
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-br', { 'callback' => \&_handle_exploding_index });
Lines 1205-1213 sub parseQuery { Link Here
1205
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-rl', { 'callback' => \&_handle_exploding_index });
1210
        $QParser->add_bib1_filter_map( 'biblioserver', 'su-rl', { 'callback' => \&_handle_exploding_index });
1206
        $QParser->parse( $query );
1211
        $QParser->parse( $query );
1207
        $operands[0] = "pqf=" . $QParser->target_syntax('biblioserver');
1212
        $operands[0] = "pqf=" . $QParser->target_syntax('biblioserver');
1208
# TODO: once we are using QueryParser, all this special case code for
1213
    } else {
1209
#       exploded search indexes will be replaced by a callback to
1214
        my $modifier_re = '#(' . join( '|', @{Koha::QueryParser::Driver::PQF->modifiers}) . ')';
1210
#       _handle_exploding_index
1215
        s/$modifier_re//g for @operands;
1211
    }
1216
    }
1212
1217
1213
    return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang, $query_desc);
1218
    return ( $operators, \@operands, $indexes, $limits, $sort_by, $scan, $lang, $query_desc);
Lines 1291-1307 sub buildQuery { Link Here
1291
        if ( @limits ) {
1296
        if ( @limits ) {
1292
            $q .= ' and '.join(' and ', @limits);
1297
            $q .= ' and '.join(' and ', @limits);
1293
        }
1298
        }
1294
        return ( undef, $q, $q, "q=ccl=$q", $q, '', '', '', '', 'ccl' );
1299
        return ( undef, $q, $q, "q=ccl=".uri_escape($q), $q, '', '', '', '', 'ccl' );
1295
    }
1300
    }
1296
    if ( $query =~ /^cql=/ ) {
1301
    if ( $query =~ /^cql=/ ) {
1297
        return ( undef, $', $', "q=cql=$'", $', '', '', '', '', 'cql' );
1302
        return ( undef, $', $', "q=cql=".uri_escape($'), $', '', '', '', '', 'cql' );
1298
    }
1303
    }
1299
    if ( $query =~ /^pqf=/ ) {
1304
    if ( $query =~ /^pqf=/ ) {
1300
        if ($query_desc) {
1305
        if ($query_desc) {
1301
            $query_cgi = "q=$query_desc";
1306
            $query_cgi = "q=".uri_escape($query_desc);
1302
        } else {
1307
        } else {
1303
            $query_desc = $';
1308
            $query_desc = $';
1304
            $query_cgi = "q=pqf=$'";
1309
            $query_cgi = "q=pqf=".uri_escape($');
1305
        }
1310
        }
1306
        return ( undef, $', $', $query_cgi, $query_desc, '', '', '', '', 'pqf' );
1311
        return ( undef, $', $', $query_cgi, $query_desc, '', '', '', '', 'pqf' );
1307
    }
1312
    }
Lines 1473-1481 sub buildQuery { Link Here
1473
                        $query     .= " $operators[$i-1] ";
1478
                        $query     .= " $operators[$i-1] ";
1474
                        $query     .= " $index_plus " unless $indexes_set;
1479
                        $query     .= " $index_plus " unless $indexes_set;
1475
                        $query     .= " $operand";
1480
                        $query     .= " $operand";
1476
                        $query_cgi .= "&op=$operators[$i-1]";
1481
                        $query_cgi .= "&op=".uri_escape($operators[$i-1]);
1477
                        $query_cgi .= "&idx=$index" if $index;
1482
                        $query_cgi .= "&idx=".uri_escape($index) if $index;
1478
                        $query_cgi .= "&q=$operands[$i]" if $operands[$i];
1483
                        $query_cgi .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1479
                        $query_desc .=
1484
                        $query_desc .=
1480
                          " $operators[$i-1] $index_plus $operands[$i]";
1485
                          " $operators[$i-1] $index_plus $operands[$i]";
1481
                    }
1486
                    }
Lines 1485-1492 sub buildQuery { Link Here
1485
                        $query      .= " and ";
1490
                        $query      .= " and ";
1486
                        $query      .= "$index_plus " unless $indexes_set;
1491
                        $query      .= "$index_plus " unless $indexes_set;
1487
                        $query      .= "$operand";
1492
                        $query      .= "$operand";
1488
                        $query_cgi  .= "&op=and&idx=$index" if $index;
1493
                        $query_cgi  .= "&op=and&idx=".uri_escape($index) if $index;
1489
                        $query_cgi  .= "&q=$operands[$i]" if $operands[$i];
1494
                        $query_cgi  .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1490
                        $query_desc .= " and $index_plus $operands[$i]";
1495
                        $query_desc .= " and $index_plus $operands[$i]";
1491
                    }
1496
                    }
1492
                }
1497
                }
Lines 1498-1505 sub buildQuery { Link Here
1498
                    $query .= " $index_plus " unless $indexes_set;
1503
                    $query .= " $index_plus " unless $indexes_set;
1499
                    $query .= $operand;
1504
                    $query .= $operand;
1500
                    $query_desc .= " $index_plus $operands[$i]";
1505
                    $query_desc .= " $index_plus $operands[$i]";
1501
                    $query_cgi  .= "&idx=$index" if $index;
1506
                    $query_cgi  .= "&idx=".uri_escape($index) if $index;
1502
                    $query_cgi  .= "&q=$operands[$i]" if $operands[$i];
1507
                    $query_cgi  .= "&q=".uri_escape($operands[$i]) if $operands[$i];
1503
                    $previous_operand = 1;
1508
                    $previous_operand = 1;
1504
                }
1509
                }
1505
            }    #/if $operands
1510
            }    #/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