use XML::Simple;
use C4::Dates qw(format_date);
use C4::XSLT;
+use C4::Branch;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
@ISA = qw(Exporter);
@EXPORT = qw(
- &findseealso
&FindDuplicate
&SimpleSearch
&searchResults
# make all your functions, whether exported or not;
-=head2 findseealso($dbh,$fields);
-
-C<$dbh> is a link to the DB handler.
-
-use C4::Context;
-my $dbh =C4::Context->dbh;
-
-C<$fields> is a reference to the fields array
-
-This function modifies the @$fields array and adds related fields to search on.
-
-FIXME: this function is probably deprecated in Koha 3
-
-=cut
-
-sub findseealso {
- my ( $dbh, $fields ) = @_;
- my $tagslib = GetMarcStructure(1);
- for ( my $i = 0 ; $i <= $#{$fields} ; $i++ ) {
- my ($tag) = substr( @$fields[$i], 1, 3 );
- my ($subfield) = substr( @$fields[$i], 4, 1 );
- @$fields[$i] .= ',' . $tagslib->{$tag}->{$subfield}->{seealso}
- if ( $tagslib->{$tag}->{$subfield}->{seealso} );
- }
-}
-
=head2 FindDuplicate
($biblionumber,$biblionumber,$title) = FindDuplicate($record);
# Check if we've got a query_type defined, if so, use it
eval {
- if ($query_type)
- {
- if ( $query_type =~ /^ccl/ ) {
- $query_to_use =~
- s/\:/\=/g; # change : to = last minute (FIXME)
- $results[$i] =
- $zconns[$i]->search(
- new ZOOM::Query::CCL2RPN( $query_to_use, $zconns[$i] )
- );
- }
- elsif ( $query_type =~ /^cql/ ) {
- $results[$i] =
- $zconns[$i]->search(
- new ZOOM::Query::CQL( $query_to_use, $zconns[$i] ) );
- }
- elsif ( $query_type =~ /^pqf/ ) {
- $results[$i] =
- $zconns[$i]->search(
- new ZOOM::Query::PQF( $query_to_use, $zconns[$i] ) );
- }
- }
- else {
- if ($scan) {
- $results[$i] =
- $zconns[$i]->scan(
- new ZOOM::Query::CCL2RPN( $query_to_use, $zconns[$i] )
- );
- }
- else {
- $results[$i] =
- $zconns[$i]->search(
- new ZOOM::Query::CCL2RPN( $query_to_use, $zconns[$i] )
- );
+ if ($query_type) {
+ if ($query_type =~ /^ccl/) {
+ $query_to_use =~ s/\:/\=/g; # change : to = last minute (FIXME)
+ $results[$i] = $zconns[$i]->search(new ZOOM::Query::CCL2RPN($query_to_use, $zconns[$i]));
+ } elsif ($query_type =~ /^cql/) {
+ $results[$i] = $zconns[$i]->search(new ZOOM::Query::CQL($query_to_use, $zconns[$i]));
+ } elsif ($query_type =~ /^pqf/) {
+ $results[$i] = $zconns[$i]->search(new ZOOM::Query::PQF($query_to_use, $zconns[$i]));
+ } else {
+ warn "Unknown query_type '$query_type'. Results undetermined.";
}
+ } elsif ($scan) {
+ $results[$i] = $zconns[$i]->scan( new ZOOM::Query::CCL2RPN($query_to_use, $zconns[$i]));
+ } else {
+ $results[$i] = $zconns[$i]->search(new ZOOM::Query::CCL2RPN($query_to_use, $zconns[$i]));
}
};
if ($@) {
if ( $servers[ $i - 1 ] =~ /biblioserver/ ) {
for my $link_value (
sort { $facets_counter->{$b} <=> $facets_counter->{$a} }
- keys %$facets_counter )
+ keys %$facets_counter )
{
my $expandable;
my $number_of_facets;
my @this_facets_array;
for my $one_facet (
sort {
- $facets_counter->{$link_value}
- ->{$b} <=> $facets_counter->{$link_value}->{$a}
+ $facets_counter->{$link_value}->{$b}
+ <=> $facets_counter->{$link_value}->{$a}
} keys %{ $facets_counter->{$link_value} }
)
{
$branches->{$one_facet}->{'branchname'};
}
- # but we're down with the whole label being in the link's title.
- my $facet_title_value = $one_facet;
-
- push @this_facets_array,
- (
- {
- facet_count =>
- $facets_counter->{$link_value}
- ->{$one_facet},
- facet_label_value => $facet_label_value,
- facet_title_value => $facet_title_value,
- facet_link_value => $facet_link_value,
- type_link_value => $link_value,
- },
- );
+ # but we're down with the whole label being in the link's title.
+ push @this_facets_array, {
+ facet_count => $facets_counter->{$link_value}->{$one_facet},
+ facet_label_value => $facet_label_value,
+ facet_title_value => $one_facet,
+ facet_link_value => $facet_link_value,
+ type_link_value => $link_value,
+ };
}
}
if ( ( $number_of_facets > 6 )
&& ( $expanded_facet ne $link_value ) );
}
- push @facets_loop,
- (
- {
- type_link_value => $link_value,
- type_id => $link_value . "_id",
- "type_label_" . $facets_info->{$link_value}->{'label_value'} => 1,
- facets => \@this_facets_array,
- expandable => $expandable,
- expand => $link_value,
- }
- ) unless ( ($facets_info->{$link_value}->{'label_value'} =~ /Libraries/) and (C4::Context->preference('singleBranchMode')) );
+ push @facets_loop, {
+ type_link_value => $link_value,
+ type_id => $link_value . "_id",
+ "type_label_" . $facets_info->{$link_value}->{'label_value'} => 1,
+ facets => \@this_facets_array,
+ expandable => $expandable,
+ expand => $link_value,
+ } unless ( ($facets_info->{$link_value}->{'label_value'} =~ /Libraries/) and (C4::Context->preference('singleBranchMode')) );
}
}
}
# we use IsAlpha unicode definition, to deal correctly with diacritics.
# otherwise, a French word like "leçon" woudl be split into "le" "çon", "le"
# is a stopword, we'd get "çon" and wouldn't find anything...
- foreach ( keys %{ C4::Context->stopwords } ) {
- next if ( $_ =~ /(and|or|not)/ ); # don't remove operators
- if ( $operand =~
- /(\P{IsAlpha}$_\P{IsAlpha}|^$_\P{IsAlpha}|\P{IsAlpha}$_$|^$_$)/ )
- {
- $operand =~ s/\P{IsAlpha}$_\P{IsAlpha}/ /gi;
- $operand =~ s/^$_\P{IsAlpha}/ /gi;
- $operand =~ s/\P{IsAlpha}$_$/ /gi;
- $operand =~ s/$1//gi;
- push @stopwords_removed, $_;
- }
- }
- }
+ foreach ( keys %{ C4::Context->stopwords } ) {
+ next if ( $_ =~ /(and|or|not)/ ); # don't remove operators
+ if ( my ($matched) = ($operand =~
+ /(\P{IsAlnum}\Q$_\E\P{IsAlnum}|^\Q$_\E\P{IsAlnum}|\P{IsAlnum}\Q$_\E$|^\Q$_\E$)/gi) )
+ {
+ $operand =~ s/\Q$matched\E/ /gi;
+ push @stopwords_removed, $_;
+ }
+ }
+ }
return ( $operand, \@stopwords_removed );
}
warn "---------\nEnter buildQuery\n---------" if $DEBUG;
# dereference
- my @operators = @$operators if $operators;
- my @indexes = @$indexes if $indexes;
- my @operands = @$operands if $operands;
- my @limits = @$limits if $limits;
- my @sort_by = @$sort_by if $sort_by;
+ my @operators = $operators ? @$operators : ();
+ my @indexes = $indexes ? @$indexes : ();
+ my @operands = $operands ? @$operands : ();
+ my @limits = $limits ? @$limits : ();
+ my @sort_by = $sort_by ? @$sort_by : ();
my $stemming = C4::Context->preference("QueryStemming") || 0;
my $auto_truncation = C4::Context->preference("QueryAutoTruncate") || 0;
# Some helpful index variants
my $index_plus = $index . $struct_attr . ":" if $index;
my $index_plus_comma = $index . $struct_attr . "," if $index;
- if ($auto_truncation){
-# FIXME Auto Truncation is only valid for LTR languages
-# use C4::Output;
-# use C4::Languages qw(regex_lang_subtags get_bidi);
-# $lang = $query->cookie('KohaOpacLanguage') if (defined $query && $query->cookie('KohaOpacLanguage'));
-# my $current_lang = regex_lang_subtags($lang);
-# my $bidi;
-# $bidi = get_bidi($current_lang->{script}) if $current_lang->{script};
- $index_plus_comma .= "rtrn:";
- }
# Remove Stopwords
if ($remove_stopwords) {
if ( $stopwords_removed && $DEBUG );
}
+ if ($auto_truncation){
+ #FIXME only valid with LTR scripts
+ $operand=join(" ",map{
+ "$_*"
+ }split (/\s+/,$operand));
+ warn $operand if $DEBUG;
+ }
+
# Detect Truncation
my $truncated_operand;
my( $nontruncated, $righttruncated, $lefttruncated,
$indexes_set = 1;
undef $weight_fields;
my $previous_truncation_operand;
- if ( scalar(@$nontruncated) > 0 ) {
+ if (scalar @$nontruncated) {
$truncated_operand .= "$index_plus @$nontruncated ";
$previous_truncation_operand = 1;
}
- if ( scalar(@$righttruncated) > 0 ) {
- $truncated_operand .= "and "
- if $previous_truncation_operand;
- $truncated_operand .=
- "$index_plus_comma" . "rtrn:@$righttruncated ";
+ if (scalar @$righttruncated) {
+ $truncated_operand .= "and " if $previous_truncation_operand;
+ $truncated_operand .= $index_plus_comma . "rtrn:@$righttruncated ";
$previous_truncation_operand = 1;
}
- if ( scalar(@$lefttruncated) > 0 ) {
- $truncated_operand .= "and "
- if $previous_truncation_operand;
- $truncated_operand .=
- "$index_plus_comma" . "ltrn:@$lefttruncated ";
+ if (scalar @$lefttruncated) {
+ $truncated_operand .= "and " if $previous_truncation_operand;
+ $truncated_operand .= $index_plus_comma . "ltrn:@$lefttruncated ";
$previous_truncation_operand = 1;
}
- if ( scalar(@$rightlefttruncated) > 0 ) {
- $truncated_operand .= "and "
- if $previous_truncation_operand;
- $truncated_operand .=
- "$index_plus_comma" . "rltrn:@$rightlefttruncated ";
+ if (scalar @$rightlefttruncated) {
+ $truncated_operand .= "and " if $previous_truncation_operand;
+ $truncated_operand .= $index_plus_comma . "rltrn:@$rightlefttruncated ";
$previous_truncation_operand = 1;
}
}
# Handle Stemming
my $stemmed_operand;
- $stemmed_operand = _build_stemmed_operand($operand)
- if $stemming;
+ $stemmed_operand = _build_stemmed_operand($operand) if $stemming;
+
warn "STEMMED OPERAND: >$stemmed_operand<" if $DEBUG;
# Handle Field Weighting
my $weighted_operand;
- $weighted_operand =
- _build_weighted_query( $operand, $stemmed_operand, $index )
- if $weight_fields;
+ if ($weight_fields) {
+ $weighted_operand = _build_weighted_query( $operand, $stemmed_operand, $index );
+ $operand = $weighted_operand;
+ $indexes_set = 1;
+ }
+
warn "FIELD WEIGHTED OPERAND: >$weighted_operand<" if $DEBUG;
- $operand = $weighted_operand if $weight_fields;
- $indexes_set = 1 if $weight_fields;
# If there's a previous operand, we need to add an operator
if ($previous_operand) {
# Regular old limits
else {
- if ($this_limit){
- $limit .= " and " if $limit || $query;
- $limit .= "$this_limit";
- $limit_cgi .= "&limit=$this_limit";
+ $limit .= " and " if $limit || $query;
+ $limit .= "$this_limit";
+ $limit_cgi .= "&limit=$this_limit";
+ if ($this_limit =~ /^branch:(.+)/) {
+ my $branchcode = $1;
+ my $branchname = GetBranchName($branchcode);
+ if (defined $branchname) {
+ $limit_desc .= " branch:$branchname";
+ } else {
+ $limit_desc .= " $this_limit";
+ }
+ } else {
$limit_desc .= " $this_limit";
- }
+ }
}
}
if ($group_OR_limits) {
$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; # remove double == from query
+ s/ / /g; # remove extra spaces
+ s/^ //g; # remove any beginning spaces
+ s/ $//g; # remove any ending spaces
+ s/==/=/g; # remove double == from query
}
$query_cgi =~ s/^&//; # remove unnecessary & from beginning of the query cgi
for ($query_cgi,$simple_query) {
- $_ =~ s/"//g;
+ s/"//g;
}
# append the limit to the query
$query .= " " . $limit;
elsif ($item->{$otherbranch}) { # Last resort
$item->{'branchname'} = $branches{$item->{$otherbranch}};
}
-
+
+ ($item->{'reserved'}) = C4::Reserves::CheckReserves($item->{itemnumber});
+
my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
- if ( $item->{onloan} ) {
+ if ( $item->{onloan} or $item->{reserved} ) {
$onloan_count++;
- my $key = $prefix . $item->{due_date};
+ my $key = $prefix . $item->{onloan} . $item->{barcode};
$onloan_items->{$key}->{due_date} = format_date($item->{onloan});
$onloan_items->{$key}->{count}++ if $item->{$hbranch};
$onloan_items->{$key}->{branchname} = $item->{branchname};
|| $item->{itemlost}
|| $item->{damaged}
|| $item->{notforloan}
+ || $item->{reserved}
|| ($transfertwhen ne ''))
{
$wthdrawn_count++ if $item->{wthdrawn};
$left = 'subject' if $left =~ '^su$';
$left = 'koha-Auth-Number' if $left =~ '^an$';
$left = 'keyword' if $left =~ '^kw$';
+ $left = 'itemtype' if $left =~ '^mc$'; # Fix for Bug 2599 - Search limits not working for NoZebra
warn "handling leaf... left:$left operator:$operator right:$right" if $DEBUG;
+ my $dbh = C4::Context->dbh;
if ( $operator && $left ne 'keyword' ) {
-
#do a specific search
- my $dbh = C4::Context->dbh;
$operator = 'LIKE' if $operator eq '=' and $right =~ /%/;
- my $sth =
- $dbh->prepare(
+ my $sth = $dbh->prepare(
"SELECT biblionumbers,value FROM nozebra WHERE server=? AND indexname=? AND value $operator ?"
- );
+ );
warn "$left / $operator / $right\n" if $DEBUG;
# split each word, query the DB and build the biblionumbers result
if ($results) {
warn "NZAND" if $DEBUG;
$results = NZoperatorAND($biblionumbers,$results);
- }
- else {
+ } else {
$results = $biblionumbers;
}
}
}
else {
-
#do a complete search (all indexes), if index='kw' do complete search too.
- my $dbh = C4::Context->dbh;
- my $sth =
- $dbh->prepare(
+ my $sth = $dbh->prepare(
"SELECT biblionumbers FROM nozebra WHERE server=? AND value LIKE ?"
- );
+ );
# split each word, query the DB and build the biblionumbers result
foreach ( split / /, $string ) {
my $popularity = $sth->fetchrow || 0;
# hint : the key is popularity.title because we can have
-# many results with the same popularity. In this cas, sub-ordering is done by title
+# many results with the same popularity. In this case, sub-ordering is done by title
# we also have biblionumber to avoid bug for 2 biblios with the same title & popularity
# (un-frequent, I agree, but we won't forget anything that way ;-)
$popularity{ sprintf( "%10d", $popularity ) . $title