search - a search script for finding records in a Koha system (Version 3)
This script utilizes a new search API for Koha 3. It is designed to be simple to use and configure, yet capable of performing feats like stemming, field weighting, relevance ranking, support for multiple query language formats (CCL, CQL, PQF), full support for the bib1 attribute set, extended attribute sets defined in Zebra profiles, access to the full range of Z39.50 and SRU query options, federated searches on Z39.50/SRU targets, etc.
The API as represented in this script is mostly sound, even if the individual functions in Search.pm and Koha.pm need to be cleaned up. Of course, you are free to disagree :-)
I will attempt to describe what is happening at each part of this script. -- Joshua Ferraro <jmf AT liblime DOT com>
This script performs two functions:
These two functions share many of the same variables and modules, so the first task is to load what they have in common and determine which template to use. Once determined, proceed to only load the variables and procedures necessary for that function.
This is fairly straightforward, and I won't go into detail ;-)
If we're performing a search, this script performs three primary operations:
There are several additional secondary functions performed that I will not cover in detail.
There are several types of queries needed in the process of search and retrieve:
This is the most complex query that needs to be built. The original design goal was to use a custom CCL2PQF query parser to translate an incoming CCL query into a multi-leaf query to pass to Zebra. It needs to be multi-leaf to allow field weighting, koha-specific relevance ranking, and stemming. When I have a chance I'll try to flesh out this section to better explain.
This query incorporates query profiles that aren't compatible with most non-Zebra Z39.50 targets to acomplish the field weighting and relevance ranking.
This query is just the user's query expressed in CCL CQL, or PQF for passing to a non-zebra Z39.50 target (one that doesn't support the extended profile that Zebra does).
This is a simple string that completely expresses the query as a CGI string that can be used for future refinements of the query or as a part of a history feature.
This is a simple string that is human readable. It will contain '=', ',', etc.
This section takes the query strings and performs searches on the named servers, including the Koha Zebra server, stores the results in a deeply nested object, builds 'faceted results', and returns these objects.
The final major section of this script takes the objects collected thusfar and builds the HTML for output to the template and user.
Not yet completed...
my $type = C4::Context->preference("AdvancedSearchTypes") || "itemtypes"; my @advanced_search_types = prepare_adv_search_types($type);
Different types can be searched for in the advanced search. This takes the system preference that defines these types and parses it into an arrayref for the template.
"itemtypes" is handled specially, as itemtypes aren't an authorised value. It also accounts for the "item-level_itypes" system preference.