# remove valid operators
$result->{title} =~ s/(and|or|not)//g;
$query = "ti,ext=$result->{title}";
- $query .= " and mt=$result->{itemtype}" if ($result->{itemtype});
+ $query .= " and itemtype=$result->{itemtype}" if ($result->{itemtype});
if ($result->{author}){
$result->{author} =~ s /\\//g;
$result->{author} =~ s /\"//g;
$query_to_use = $simple_query;
}
- $query_to_use = $simple_query if $scan;
-
+ #$query_to_use = $simple_query if $scan;
+ #warn $simple_query if ($scan && $DEBUG);
# check if we've got a query_type defined
eval {
if ($query_type)
# embedded sorting: 0 a-z; 1 z-a
# $weighted_query .= ") or (sort1,aut=1";
}
+ elsif ( $index eq 'bc' ) {
+ $weighted_query .= "bc=\"$operand\"";
+ }
# if the index already has more than one qualifier, just wrap the operand
# in quotes and pass it back
elsif ($index =~ ',') {
# build the query itself
sub buildQuery {
- my ( $operators, $operands, $indexes, $limits, $sort_by ) = @_;
+ my ( $operators, $operands, $indexes, $limits, $sort_by, $scan) = @_;
my @operators = @$operators if $operators;
my @indexes = @$indexes if $indexes;
# a flag to determine whether or not to add the index to the query
my $indexes_set;
# if the user is sophisticated enough to specify an index, turn off some defaults
- if ($operands[$i] =~ /(:|=)/) {
+ if ($operands[$i] =~ /(:|=)/ || $scan) {
$weight_fields = 0;
$stemming = 0;
$remove_stopwords = 0;
# add limits
my $group_OR_limits;
+ my $availability_limit;
foreach my $this_limit (@limits) {
if ( $this_limit =~ /available/ ) {
- # FIXME: switch to zebra search for null values
- $limit .= " (($query and datedue=0000-00-00) or ($query and datedue=0000-00-00 not lost=1) or ($query and datedue=0000-00-00 not lost=2))";
+ # available is defined as (items.notloan is NULL) and (items.itemlost > 0 or NULL) (last clause handles NULL values for lost in zebra)
+ $availability_limit .="( ( allrecords,AlwaysMatches='' not onloan,AlwaysMatches='') and ((lost,st-numeric gt 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='')) )";
$limit_cgi .= "&limit=available";
$limit_desc .="";
}
$limit.=" and " if ($query || $limit );
$limit.="($group_OR_limits)";
}
+ if ($availability_limit) {
+ $limit.=" not " if ($query || $limit );
+ $limit.="$availability_limit";
+ }
# normalize the strings
+ $query =~ s/:/=/g;
+ $limit =~ s/:/=/g;
for ($query, $query_desc, $limit, $limit_desc) {
$_ =~ s/ / /g; # remove extra spaces
$_ =~ s/^ //g; # remove any beginning spaces
$_ =~ s/ $//g; # remove any ending spaces
- $_ =~ s/:/=/g; # causes probs for server
$_ =~ s/==/=/g; # remove double == from query
}
-
$query_cgi =~ s/^&//;
# append the limit to the query
my $marcrecord;
$marcrecord = MARC::File::USMARC::decode( $marcresults[$i] );
my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, '' );
+ $oldbiblio->{result_number} = $i+1;
# add image url if there is one
if ( $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} =~ /^http:/ ) {
$oldbiblio->{imageurl} =
# last check for norequest : if itemtype is notforloan, it can't be reserved either, whatever the items
$norequests = 1 if $itemtypes{$oldbiblio->{itemtype}}->{notforloan};
-
+ my $itemscount;
for my $key ( sort keys %$items ) {
+ $itemscount++;
my $this_item = {
branchname => $branches{$items->{$key}->{branchcode}},
branchcode => $items->{$key}->{branchcode},
wthdrawn => $items->{$key}->{wthdrawn},
lost => $items->{$key}->{itemlost},
};
- push @items_loop, $this_item;
+ # only show the number specified by the user
+ my $maxitems = (C4::Context->preference('maxItemsinSearchResults')) ? C4::Context->preference('maxItemsinSearchResults')- 1 : 1;
+ push @items_loop, $this_item unless $itemscount > $maxitems;;
}
$oldbiblio->{norequests} = $norequests;
$oldbiblio->{items_count} = $items_count;