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

(-)a/C4/Search.pm (-5 / +68 lines)
Lines 251-256 sub SimpleSearch { Link Here
251
                $zoom_queries[$i] = new ZOOM::Query::PQF( $query, $zconns[$i]);
251
                $zoom_queries[$i] = new ZOOM::Query::PQF( $query, $zconns[$i]);
252
            } else {
252
            } else {
253
                $query =~ s/:/=/g;
253
                $query =~ s/:/=/g;
254
                $query =~ s/\?//g; #Remove ? because this error is thrown :> CCL parsing error (10014) Right truncation not supported ZOOM for query: title=MISSÄ ON JATKOT? at /C4/Search.pm line 276.
254
                $zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]);
255
                $zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]);
255
            }
256
            }
256
            $tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] );
257
            $tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] );
Lines 327-333 sub getRecords { Link Here
327
    my (
328
    my (
328
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
329
        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
329
        $results_per_page, $offset,       $expanded_facet, $branches,
330
        $results_per_page, $offset,       $expanded_facet, $branches,
330
        $itemtypes,        $query_type,   $scan,           $opac
331
        $itemtypes,        $query_type,   $scan,           $opac,        $availableLimit
331
    ) = @_;
332
    ) = @_;
332
333
333
    my @servers = @$servers_ref;
334
    my @servers = @$servers_ref;
Lines 347-352 sub getRecords { Link Here
347
348
348
    my @facets_loop;    # stores the ref to array of hashes for template facets loop
349
    my @facets_loop;    # stores the ref to array of hashes for template facets loop
349
350
351
    #Get the required marc tags for determining branch-based availability.
352
    my ( $holdingbranchField, $holdingbranchSubfield, $onloanField, $onloanSubfield, $notforloanField, $notforloanSubfield );
353
    if ($availableLimit) {
354
        ( $holdingbranchField, $holdingbranchSubfield ) = GetMarcFromKohaField( "items.holdingbranch" );
355
        ( $onloanField, $onloanSubfield ) = GetMarcFromKohaField( "items.onloan" );
356
        ( $notforloanField, $notforloanSubfield ) = GetMarcFromKohaField( "items.notforloan" );
357
    }
358
359
350
    ### LOOP THROUGH THE SERVERS
360
    ### LOOP THROUGH THE SERVERS
351
    for ( my $i = 0 ; $i < @servers ; $i++ ) {
361
    for ( my $i = 0 ; $i < @servers ; $i++ ) {
352
        $zconns[$i] = C4::Context->Zconn( $servers[$i], 1 );
362
        $zconns[$i] = C4::Context->Zconn( $servers[$i], 1 );
Lines 450-455 sub getRecords { Link Here
450
                    $times = $size;
460
                    $times = $size;
451
                }
461
                }
452
462
463
                #If we are using pagination to display other resultset pages.
464
                #The results_hash needs to contain Records starting from the given
465
                #offset.
466
                if ($offset > 0) {
467
                    $results_hash->{'RECORDS'}->[$offset-1] = undef;
468
                }
469
                
453
                for ( my $j = $offset ; $j < $times ; $j++ ) {
470
                for ( my $j = $offset ; $j < $times ; $j++ ) {
454
                    my $records_hash;
471
                    my $records_hash;
455
                    my $record;
472
                    my $record;
Lines 491-499 sub getRecords { Link Here
491
508
492
                    # not an index scan
509
                    # not an index scan
493
                    else {
510
                    else {
494
                        $record = $results[ $i - 1 ]->record($j)->raw();
511
                        $record = $results[ $i - 1 ]->record($j);
512
                        last() unless $record;
513
                        $record = $record->raw();
495
                        # warn "RECORD $j:".$record;
514
                        # warn "RECORD $j:".$record;
496
                        $results_hash->{'RECORDS'}[$j] = $record;
515
516
                        if (  $availableLimit  && #Availablelimit is 1 if there is no limit=branch:FTL given
517
                              not(isAvailableFromMARCXML( $record, $availableLimit, $holdingbranchField, $holdingbranchSubfield, $onloanField, $onloanSubfield, $notforloanField, $notforloanSubfield )) ) {
518
                            $times++; #Skip this record, but make sure we still get the $results_per_page results to display.
519
                            $results_hash->{'hits'}--; #This wasn't a hit after all :(
520
                            next();
521
                        }
522
523
                        push @{$results_hash->{'RECORDS'}}, $record;
497
                    }
524
                    }
498
525
499
                }
526
                }
Lines 1581-1588 sub buildQuery { Link Here
1581
## 'available' is defined as (items.onloan is NULL) and (items.itemlost = 0)
1608
## 'available' is defined as (items.onloan is NULL) and (items.itemlost = 0)
1582
## In English:
1609
## In English:
1583
## all records not indexed in the onloan register (zebra) and all records with a value of lost equal to 0
1610
## all records not indexed in the onloan register (zebra) and all records with a value of lost equal to 0
1584
            $availability_limit .=
1611
#            $availability_limit .=
1585
"( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and (lost,st-numeric=0) )"; #or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
1612
#"( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and (lost,st-numeric=0) )"; #or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
1586
            $limit_cgi  .= "&limit=available";
1613
            $limit_cgi  .= "&limit=available";
1587
            $limit_desc .= "";
1614
            $limit_desc .= "";
1588
        }
1615
        }
Lines 2461-2466 sub new_record_from_zebra { Link Here
2461
2488
2462
}
2489
}
2463
2490
2491
#Check each item in the MARCXML-String for onloan or notforloan
2492
#Return 1 when the first available item is found.
2493
#PARAM $limitHoldingbranch, counterintuitively is 1, if no holdingbranch based limiting is desired,
2494
#                           and the holdingbranch code if we want to limit by branch.
2495
2496
sub isAvailableFromMARCXML {
2497
    my ( $recordXML, $limitHoldingbranch, $holdingbranchField, $holdingbranchSubfield, $onloanField, $onloanSubfield, $notforloanField, $notforloanSubfield ) = @_;
2498
2499
    my @itemsFields = $recordXML =~ /<datafield tag="$holdingbranchField".*?>(.*?)<\/datafield>/sg;
2500
2501
    foreach my $fieldStr (@itemsFields) {
2502
        my ($itemHoldingbranch, $itemOnloan, $itemNotforloan);
2503
        
2504
        if ($fieldStr =~ /<subfield code="$onloanSubfield">(.*?)<\/subfield>/s) {
2505
            $itemOnloan = $1;
2506
            next() if $itemOnloan;
2507
        }
2508
        if ($fieldStr =~ /<subfield code="$notforloanSubfield">(.*?)<\/subfield>/s) {
2509
            $itemNotforloan = $1;
2510
            next() if $itemNotforloan;
2511
        }
2512
        if ($limitHoldingbranch != 1) { #Check for holdingbranch-based availability.
2513
            if ($fieldStr =~ /<subfield code="$holdingbranchSubfield">(.*?)<\/subfield>/s) {
2514
                $itemHoldingbranch = $1;
2515
            }
2516
            if ($itemHoldingbranch && $itemHoldingbranch eq $limitHoldingbranch) {
2517
                return 1; #Available ! wooee!
2518
            }
2519
        }
2520
        else {
2521
            return 1; #We are not checking for holdingbranch-based availability, so any availability is fine!
2522
        }
2523
    }
2524
    return 0;
2525
}
2526
2464
END { }    # module clean-up code here (global destructor)
2527
END { }    # module clean-up code here (global destructor)
2465
2528
2466
1;
2529
1;
(-)a/catalogue/search.pl (-2 / +9 lines)
Lines 425-436 if($params->{'multibranchlimit'}) { Link Here
425
    push @limits, $multibranch if ($multibranch ne  '()');
425
    push @limits, $multibranch if ($multibranch ne  '()');
426
}
426
}
427
427
428
my $available;
428
my ($available, $availableBranch);
429
foreach my $limit(@limits) {
429
foreach my $limit(@limits) {
430
    if ($limit =~/available/) {
430
    if ($limit =~/available/) {
431
        $available = 1;
431
        $available = 1;
432
    }
432
    }
433
    elsif ($limit =~ /branch:(.*?)$/) { #Catch holdingbranch from facets and branch from advanced search
434
        $availableBranch = $1;
435
    }
436
}
437
if ($availableBranch && $available) {
438
    $available = $availableBranch;
433
}
439
}
440
undef $availableBranch; #Don't pollute namespace!
434
$template->param(available => $available);
441
$template->param(available => $available);
435
442
436
# append year limits if they exist
443
# append year limits if they exist
Lines 528-534 my @results_array; Link Here
528
my $results_hashref;
535
my $results_hashref;
529
536
530
eval {
537
eval {
531
    ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$query_type,$scan);
538
    ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$query_type,$scan,undef,$available);
532
};
539
};
533
540
534
# This sorts the facets into alphabetical order
541
# This sorts the facets into alphabetical order
(-)a/opac/opac-search.pl (-3 / +9 lines)
Lines 410-421 if($params->{'multibranchlimit'}) { Link Here
410
    push @limits, $multibranch if ($multibranch ne  '()');
410
    push @limits, $multibranch if ($multibranch ne  '()');
411
}
411
}
412
412
413
my $available;
413
my ($available, $availableBranch);
414
foreach my $limit(@limits) {
414
foreach my $limit(@limits) {
415
    if ($limit =~/available/) {
415
    if ($limit =~/available/) {
416
        $available = 1;
416
        $available = 1;
417
    }
417
    }
418
    elsif ($limit =~ /branch:(.*?)$/) { #Catch holdingbranch from facets and branch from advanced search
419
        $availableBranch = $1;
420
    }
421
}
422
if ($availableBranch && $available) {
423
    $available = $availableBranch;
418
}
424
}
425
undef $availableBranch; #Don't pollute namespace!
419
$template->param(available => $available);
426
$template->param(available => $available);
420
427
421
# append year limits if they exist
428
# append year limits if they exist
Lines 519-525 if ($tag) { Link Here
519
    $pasarParams .= '&amp;simple_query=' . $simple_query;
526
    $pasarParams .= '&amp;simple_query=' . $simple_query;
520
    $pasarParams .= '&amp;query_type=' . $query_type if ($query_type);
527
    $pasarParams .= '&amp;query_type=' . $query_type if ($query_type);
521
    eval {
528
    eval {
522
        ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$query_type,$scan,1);
529
        ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$query_type,$scan,1,$available);
523
    };
530
    };
524
}
531
}
525
# This sorts the facets into alphabetical order
532
# This sorts the facets into alphabetical order
526
- 

Return to bug 11677