X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FSearch.pm;h=554174cb2890545f371ba62c6e62e9f60b1e16f8;hb=df4b588c6e7166a50ca5724fde16e75c2c84d18c;hp=5007f238d3ccf54c038ec0456247f42860bd2942;hpb=e5c824400956ca95cd753060200c4e1227269d56;p=koha.git diff --git a/C4/Search.pm b/C4/Search.pm index 5007f238d3..554174cb28 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -27,6 +27,7 @@ use XML::Simple; use C4::Dates qw(format_date); use C4::XSLT; use C4::Branch; +use C4::Reserves; # CheckReserves use C4::Debug; use YAML; use URI::Escape; @@ -783,6 +784,195 @@ sub _build_weighted_query { return $weighted_query; } +=head2 getIndexes + +Return an array with available indexes. + +=cut + +sub getIndexes{ + my @indexes = ( + # biblio indexes + 'ab', + 'Abstract', + 'acqdate', + 'allrecords', + 'an', + 'Any', + 'at', + 'au', + 'aub', + 'aud', + 'audience', + 'auo', + 'aut', + 'Author', + 'Author-in-order ', + 'Author-personal-bibliography', + 'Authority-Number', + 'authtype', + 'bc', + 'biblionumber', + 'bio', + 'biography', + 'callnum', + 'cfn', + 'Chronological-subdivision', + 'cn-bib-source', + 'cn-bib-sort', + 'cn-class', + 'cn-item', + 'cn-prefix', + 'cn-suffix', + 'cpn', + 'Code-institution', + 'Conference-name', + 'Conference-name-heading', + 'Conference-name-see', + 'Conference-name-seealso', + 'Content-type', + 'Control-number', + 'copydate', + 'Corporate-name', + 'Corporate-name-heading', + 'Corporate-name-see', + 'Corporate-name-seealso', + 'ctype', + 'date-entered-on-file', + 'Date-of-acquisition', + 'Date-of-publication', + 'Dewey-classification', + 'extent', + 'fic', + 'fiction', + 'Form-subdivision', + 'format', + 'Geographic-subdivision', + 'he', + 'Heading', + 'Heading-use-main-or-added-entry', + 'Heading-use-series-added-entry ', + 'Heading-use-subject-added-entry', + 'Host-item', + 'id-other', + 'Illustration-code', + 'ISBN', + 'ISSN', + 'itemtype', + 'kw', + 'Koha-Auth-Number', + 'l-format', + 'language', + 'lc-card', + 'LC-card-number', + 'lcn', + 'llength', + 'ln', + 'Local-classification', + 'Local-number', + 'Match-heading', + 'Match-heading-see-from', + 'Material-type', + 'mc-itemtype', + 'mc-rtype', + 'mus', + 'Name-geographic', + 'Name-geographic-heading', + 'Name-geographic-see', + 'Name-geographic-seealso', + 'nb', + 'Note', + 'ns', + 'nt', + 'pb', + 'Personal-name', + 'Personal-name-heading', + 'Personal-name-see', + 'Personal-name-seealso', + 'pl', + 'Place-publication', + 'pn', + 'popularity', + 'pubdate', + 'Publisher', + 'Record-type', + 'rtype', + 'se', + 'See', + 'See-also', + 'sn', + 'Stock-number', + 'su', + 'Subject', + 'Subject-heading-thesaurus', + 'Subject-name-personal', + 'Subject-subdivision', + 'Summary', + 'Suppress', + 'su-geo', + 'su-na', + 'su-to', + 'su-ut', + 'ut', + 'Term-genre-form', + 'Term-genre-form-heading', + 'Term-genre-form-see', + 'Term-genre-form-seealso', + 'ti', + 'Title', + 'Title-cover', + 'Title-series', + 'Title-uniform', + 'Title-uniform-heading', + 'Title-uniform-see', + 'Title-uniform-seealso', + 'totalissues', + 'yr', + + # items indexes + 'acqsource', + 'barcode', + 'bc', + 'branch', + 'ccode', + 'classification-source', + 'cn-sort', + 'coded-location-qualifier', + 'copynumber', + 'damaged', + 'datelastborrowed', + 'datelastseen', + 'holdingbranch', + 'homebranch', + 'issues', + 'item', + 'itemnumber', + 'itype', + 'Local-classification', + 'location', + 'lost', + 'materials-specified', + 'mc-ccode', + 'mc-itype', + 'mc-loc', + 'notforloan', + 'onloan', + 'price', + 'renewals', + 'replacementprice', + 'replacementpricedate', + 'reserves', + 'restricted', + 'stack', + 'uri', + 'withdrawn', + + # subject related + ); + + return \@indexes; +} + =head2 buildQuery ( $error, $query, @@ -819,9 +1009,10 @@ sub buildQuery { # no stemming/weight/fuzzy in NoZebra if ( C4::Context->preference("NoZebra") ) { - $stemming = 0; - $weight_fields = 0; - $fuzzy_enabled = 0; + $stemming = 0; + $weight_fields = 0; + $fuzzy_enabled = 0; + $auto_truncation = 0; } my $query = $operands[0]; @@ -838,6 +1029,17 @@ sub buildQuery { my $stopwords_removed; # flag to determine if stopwords have been removed + my $cclq; + my $cclindexes = getIndexes(); + if( $query !~ /\s*ccl=/ ){ + for my $index (@$cclindexes){ + if($query =~ /($index)(,?\w)*[:=]/){ + $cclq = 1; + } + } + $query = "ccl=$query" if($cclq); + } + # for handling ccl, cql, pqf queries in diagnostic mode, skip the rest of the steps # DIAGNOSTIC ONLY!! if ( $query =~ /^ccl=/ ) { @@ -914,6 +1116,11 @@ sub buildQuery { ) = ( 0, 0, 0, 0, 0 ); } + + if(not $index){ + $index = 'kw'; + } + # Set default structure attribute (word list) my $struct_attr; unless ( $indexes_set || !$index || $index =~ /(st-|phr|ext|wrdl)/ ) { @@ -936,8 +1143,8 @@ sub buildQuery { if ($auto_truncation){ unless ( $index =~ /(st-|phr|ext)/ ) { #FIXME only valid with LTR scripts - $operand=join(" ",map{ - "$_*" + $operand=join(" ",map{ + (index($_,"*")>0?"$_":"$_*") }split (/\s+/,$operand)); warn $operand if $DEBUG; } @@ -1101,6 +1308,8 @@ sub buildQuery { # This is flawed , means we can't search anything with : in it # if user wants to do ccl or cql, start the query with that # $query =~ s/:/=/g; + $query =~ s/(?<=(ti|au|pb|su|an|kw|mc)):/=/g; + $query =~ s/(?<=rtrn):/=/g; $limit =~ s/:/=/g; for ( $query, $query_desc, $limit, $limit_desc ) { s/ / /g; # remove extra spaces @@ -1212,12 +1421,6 @@ sub searchResults { # loop through all of the records we've retrieved for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) { my $marcrecord = MARC::File::USMARC::decode( $marcresults[$i] ); -<<<<<<< HEAD:C4/Search.pm - -======= - my $biblionumber; - ->>>>>>> C4/Search.pm followup auto_truncation 3.0.x cherry-pick:C4/Search.pm if ($bibliotag<10){ $fw = GetFrameworkCode($marcrecord->field($bibliotag)->data); }else{ @@ -1314,6 +1517,7 @@ sub searchResults { my $itemdamaged_count = 0; my $item_in_transit_count = 0; my $can_place_holds = 0; + my $item_onhold_count = 0; my $items_count = scalar(@fields); my $maxitems = ( C4::Context->preference('maxItemsinSearchResults') ) @@ -1371,6 +1575,10 @@ sub searchResults { my $transfertwhen = ''; my ($transfertfrom, $transfertto); + # is item on the reserve shelf? + my $reservestatus = 0; + my $reserveitem; + unless ($item->{wthdrawn} || $item->{itemlost} || $item->{damaged} @@ -1390,6 +1598,7 @@ sub searchResults { # should map transit status to record indexed in Zebra. # ($transfertwhen, $transfertfrom, $transfertto) = C4::Circulation::GetTransfers($item->{itemnumber}); + ($reservestatus, $reserveitem) = C4::Reserves::CheckReserves($item->{itemnumber}); } # item is withdrawn, lost or damaged @@ -1397,12 +1606,14 @@ sub searchResults { || $item->{itemlost} || $item->{damaged} || $item->{notforloan} + || $reservestatus eq 'Waiting' || ($transfertwhen ne '')) { $wthdrawn_count++ if $item->{wthdrawn}; $itemlost_count++ if $item->{itemlost}; $itemdamaged_count++ if $item->{damaged}; $item_in_transit_count++ if $transfertwhen ne ''; + $item_onhold_count++ if $reservestatus eq 'Waiting'; $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan}; $other_count++; @@ -1411,6 +1622,7 @@ sub searchResults { $other_items->{$key}->{$_} = $item->{$_}; } $other_items->{$key}->{intransit} = ($transfertwhen ne '') ? 1 : 0; + $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0; $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value; $other_items->{$key}->{count}++ if $item->{$hbranch}; $other_items->{$key}->{location} = $shelflocations->{ $item->{location} }; @@ -1448,6 +1660,9 @@ sub searchResults { } # XSLT processing of some stuff + use C4::Charset; + SetUTF8Flag($marcrecord); + $debug && warn $marcrecord->as_formatted; if (C4::Context->preference("XSLTResultsDisplay") && !$scan) { $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display( $oldbiblio->{biblionumber}, $marcrecord, 'Results' ); @@ -1472,6 +1687,7 @@ sub searchResults { $oldbiblio->{itemlostcount} = $itemlost_count; $oldbiblio->{damagedcount} = $itemdamaged_count; $oldbiblio->{intransitcount} = $item_in_transit_count; + $oldbiblio->{onholdcount} = $item_onhold_count; $oldbiblio->{orderedcount} = $ordered_count; $oldbiblio->{isbn} =~ s/-//g; # deleting - in isbn to enable amazon content @@ -2304,6 +2520,7 @@ OR adds a new authority record =item C * I had to add this to Search.pm (instead of the logical Biblio.pm) because of a circular dependency (this sub uses SimpleSearch, and Search.pm uses Biblio.pm) + =back =cut