API:EPrints/Search
EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects
Latest Source Code (3.4, 3.3) | Revision Log | Before editing this page please read Pod2Wiki
NAME
EPrints::Search - Represents a single search
DESCRIPTION
The Search object represents the conditions of a single search. It returns an EPrints::List object which stores the results of the search.
A Search object can also render itself as a web-form, populate itself with values from that web-form and render the results as a web page.
SYNOPSIS
# searching for articles and books in the archive, sorted by date: my $ds = $handle->get_dataset( "archive" ); my $search = EPrints::Search->new( satisfy_all => 1, handle => $handle, dataset => $ds, order => "-date" ); $search->add_field( $ds->get_field( "type" ), qw/ article book /, "EQ", "ANY" ); # getting the results: my $list = $search->perform_search; # Dispose of the Search object: $search->dispose;
SEE ALSO <EPrints::List> to know how to access the results of the search.
METHODS
$search = EPrints::Search->new( %params )
Create a new search expression.
The parameters are split into two parts. The general parameters and those which influence how the HTML form is rendered, and the results displayed.
GENERAL PARAMETERS
handle (required)
The current EPrints::Handle
dataset OR dataset_id (required)
Either the EPrints::DataSet to search, or the ID of it.
allow_blank (default 0)
Unless this is set, a search with no conditions will return zero records rather than all records.
satisfy_all (default 1)
If this is true than all search-fields much be satisfied, if false then results matching any search-field will be returned.
search_fields
A reference to an array of search field configuration structures. Each takes the form: { id=>"...", default=>"..", meta_fields=>"..." }
where the meaning is the same as for search configuration in cfg.d/eprint_search_*.pl
Search fields can also be added to the search expression after it has been constructed (by using $search->add_field(...)).
order
The order the results should be returned.
custom_order
"order" limits you to the orders specified in cfg.d/eprint_search_*.pl, and is usually used by the web page based searching. custom_order allows you to specify any order you like. The format is foo/-bar. This means that the results will be sorted by foo and then any with equal foo values will be reverse sorted by bar. More than 2 fields can be specified.
keep_cache
If true then the search results produced will be stored in the database even after the current script ends. This is useful for speeding up page 2 onwards of a search.
keep_cache may get set to true anyway for various reasons, but setting the parameter makes certain of it.
cache_id
The ID of a cached search. The cache contains both the results of the search, and the parameters used for the search.
If the cache still exists, it will set the default values of the search fields, and when the search is performed it will skip the search and build a search results object directly from the cache.
limit
Limit the number of matching records to limit.
prefix (default "")
When generating the web form and reading back from the web form, the prefix is inserted before the form names of all fields. This is useful if you need to put two search expressions in a single form for some reason.
staff (default 0)
If true then this is a "staff" search, which prevents searching unless the user is staff, and the results link to the staff URL of an item rather than the public URL.
filters
A reference to an array of filter definitions.
Filter definitions take the form of: { value=>"..", match=>"..", merge=>"..", id=>".." } and work much like normal search fields except that they do not appear in the web form so force certain search parameters on the user.
An optional parameter of describe=>0 can be set to supress the filter being mentioned in the description of the search.
$results = $search->perform_search
Execute this search and return a EPrints::List object representing the results.
$searchfield = $search->add_field( $metafields, $value, $match, $merge, $id, $filter, $show_help )
Adds the new search field $metafields (which is either a single EPrints::MetaField or a list of fields in an array ref) with default $value. If a search field already exists, the value of that field is replaced with $value.
$search->clear
Clear the search values of all search fields in the expression.
Resets satisfy_all to true.
$newsearch = $search->clone
Return a new search expression which is a duplicate of this one.
$xhtml = $search->render_description
Return an XHTML DOM description of this search expressions current parameters.
$xhtml = $search->render_conditions_description
Return an XHTML DOM description of this search expressions conditions. ie title is "foo"
$xhtml = $search->render_order_description
Return an XHTML DOM description of how this search is ordered.
$search->set_property( $property, $value );
Set any single property of this search, such as the order.