<<

NAME

C4::Search - Functions for searching the Koha catalog.

SYNOPSIS

See opac/opac-search.pl or catalogue/search.pl for example of usage

DESCRIPTION

This module provides searching functions for Koha's bibliographic databases

FUNCTIONS

findseealso($dbh,$fields);

$dbh is a link to the DB handler.

use C4::Context; my $dbh =C4::Context->dbh;

$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

FindDuplicate

($biblionumber,$biblionumber,$title) = FindDuplicate($record);

This function attempts to find duplicate records using a hard-coded, fairly simplistic algorithm

SimpleSearch

( $error, $results, $total_hits ) = SimpleSearch( $query, $offset, $max_results, [@servers] );

This function provides a simple search API on the bibliographic catalog

input arg:
    * $query can be a simple keyword or a complete CCL query
    * @servers is optional. Defaults to biblioserver as found in koha-conf.xml
    * $offset - If present, represents the number of records at the beggining to omit. Defaults to 0
    * $max_results - if present, determines the maximum number of records to fetch. undef is All. defaults to undef.
Output:
    * $error is a empty unless an error is detected
    * \@results is an array of records.
    * $total_hits is the number of hits that would have been returned with no limit
usage in the script:

my ( $error, $marcresults, $total_hits ) = SimpleSearch($query);

if (defined $error) { $template->param(query_error => $error); warn "error: ".$error; output_html_with_http_headers $input, $cookie, $template->output; exit; }

my $hits = scalar @$marcresults; my @results;

for my $i (0..$hits) { my %resultsloop; my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]); my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');

    #build the hash for the template.
    $resultsloop{highlight}       = ($i % 2)?(1):(0);
    $resultsloop{title}           = $biblio->{'title'};
    $resultsloop{subtitle}        = $biblio->{'subtitle'};
    $resultsloop{biblionumber}    = $biblio->{'biblionumber'};
    $resultsloop{author}          = $biblio->{'author'};
    $resultsloop{publishercode}   = $biblio->{'publishercode'};
    $resultsloop{publicationyear} = $biblio->{'publicationyear'};

    push @results, \%resultsloop;
}

$template->param(result=>\@results);

getRecords

( undef, $results_hashref, \@facets_loop ) = getRecords (

        $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
        $results_per_page, $offset,       $expanded_facet, $branches,
        $query_type,       $scan
    );

The all singing, all dancing, multi-server, asynchronous, scanning, searching, record nabbing, facet-building

See verbse embedded documentation.

buildQuery

( $error, $query, $simple_query, $query_cgi, $query_desc, $limit, $limit_cgi, $limit_desc, $stopwords_removed, $query_type ) = getRecords ( $operators, $operands, $indexes, $limits, $sort_by, $scan);

Build queries and limits in CCL, CGI, Human, handle truncation, stemming, field weighting, stopwords, fuzziness, etc.

See verbose embedded documentation.

searchResults

Format results in a form suitable for passing to the template

NZgetRecords

  NZgetRecords has the same API as zera getRecords, even if some parameters are not managed

NZanalyse

  NZanalyse : get a CQL string as parameter, and returns a list of biblionumber;title,biblionumber;title,...
  the list is built from an inverted index in the nozebra SQL table
  note that title is here only for convenience : the sorting will be very fast when requested on title
  if the sorting is requested on something else, we will have to reread all results, and that may be longer.

NZorder

  $finalresult = NZorder($biblionumbers, $ordering,$results_per_page,$offset);
  
  TODO :: Description

ModBiblios

($countchanged,$listunchanged) = ModBiblios($listbiblios, $tagsubfield,$initvalue,$targetvalue,$test);

this function changes all the values $initvalue in subfield $tag$subfield in any record in $listbiblios test parameter if set donot perform change to records in database.

input arg:
    * $listbiblios is an array ref to marcrecords to be changed
    * $tagsubfield is the reference of the subfield to change.
    * $initvalue is the value to search the record for
    * $targetvalue is the value to set the subfield to
    * $test is to be set only not to perform changes in database.
Output arg: * $countchanged counts all the changes performed. * $listunchanged contains the list of all the biblionumbers of records unchanged.
usage in the script:

my ($countchanged, $listunchanged) = EditBiblios($results->{RECORD}, $tagsubfield,$initvalue,$targetvalue);; #If one wants to display unchanged records, you should get biblios foreach @$listunchanged $template->param(countchanged => $countchanged, loopunchanged=>$listunchanged);

AUTHOR

Koha Developement team <info@koha.org>

<<