Difference between revisions of "API:EPrints/Search"
Line 1: | Line 1: | ||
− | + | <!-- Pod2Wiki=_preamble_ | |
+ | This page has been automatically generated from the EPrints 3.2 source. Any wiki changes made between the 'Pod2Wiki=*' and 'Edit below this comment' comments will be lost. | ||
+ | --> | ||
+ | __NOTOC__ | ||
+ | {{Pod2Wiki}}{{API:Source|file=EPrints/Search.pm|package_name=EPrints::Search}}[[Category:API|Search]]<div><!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=head_name --></div> | ||
+ | ==NAME== | ||
+ | '''EPrints::Search''' - Represents a single search | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=head_description --></div> | ||
+ | ==DESCRIPTION== | ||
+ | The Search object represents the conditions of a single search. It returns an [[API:EPrints/List|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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=head_synopsis --></div> | ||
+ | ==SYNOPSIS== | ||
+ | # searching for articles and books in the archive, sorted by date: | ||
+ | my $ds = $handle->get_dataset( "archive" ); | ||
+ | |||
+ | my $searchexp = EPrints::Search->new( | ||
+ | satisfy_all => 1, | ||
+ | handle => $handle, | ||
+ | dataset => $ds, | ||
+ | order => "-date" | ||
+ | ); | ||
+ | |||
+ | $searchexp->add_field( $ds->get_field( "type" ), qw/ article book /, "EQ", "ANY" ); | ||
+ | |||
+ | # getting the results: | ||
+ | my $list = $searchexp->perform_search; | ||
+ | |||
+ | # Dispose of the Search object: | ||
+ | $searchexp->dispose; | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=head_see_also_eprints_list_to_know_how_to_access_the_results_of_the_search --></div> | ||
+ | ==SEE ALSO <EPrints::List> to know how to access the results of the search.== | ||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=head_methods --></div> | ||
+ | ==METHODS== | ||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_new --></div> | ||
+ | ===$searchexp = 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 | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_handle --></div> | ||
+ | ===handle (required)=== | ||
+ | |||
+ | The current [[API:EPrints/Handle|EPrints::Handle]] | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_dataset_id --></div> | ||
+ | ===dataset OR dataset_id (required)=== | ||
+ | |||
+ | Either the [[API:EPrints/DataSet|EPrints::DataSet]] to search, or the ID of it. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_allow_blank --></div> | ||
+ | ===allow_blank (default 0)=== | ||
+ | |||
+ | Unless this is set, a search with no conditions will return zero records rather than all records. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_satisfy_all --></div> | ||
+ | ===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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_search_fields --></div> | ||
+ | ===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 $searchexp->add_field(...)). | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_order --></div> | ||
+ | ===order=== | ||
+ | |||
+ | The order the results should be returned. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_custom_order --></div> | ||
+ | ===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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_keep_cache --></div> | ||
+ | ===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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_cache_id --></div> | ||
+ | ===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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_limit --></div> | ||
+ | ===limit=== | ||
+ | |||
+ | Limit the number of matching records to limit. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_prefix --></div> | ||
+ | ===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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_staff --></div> | ||
+ | ===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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_filters --></div> | ||
+ | ===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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_perform_search --></div> | ||
+ | ===$results = $searchexp->perform_search=== | ||
+ | |||
+ | Execute this search and return a [[API:EPrints/List|EPrints::List]] object representing the results. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_add_field --></div> | ||
+ | ===$searchfield = $searchexp->add_field( $metafields, $value, $match, $merge, $id, $filter, $show_help )=== | ||
+ | |||
+ | Adds the new search field $metafields (which is either a single [[API:EPrints/MetaField|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. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_clear --></div> | ||
+ | ===$searchexp->clear=== | ||
+ | |||
+ | Clear the search values of all search fields in the expression. | ||
+ | |||
+ | Resets satisfy_all to true. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_clone --></div> | ||
+ | ===$newsearchexp = $searchexp->clone=== | ||
+ | |||
+ | Return a new search expression which is a duplicate of this one. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_render_description --></div> | ||
+ | ===$xhtml = $searchexp->render_description=== | ||
+ | |||
+ | Return an XHTML DOM description of this search expressions current parameters. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_render_conditions_description --></div> | ||
+ | ===$xhtml = $searchexp->render_conditions_description=== | ||
+ | |||
+ | Return an XHTML DOM description of this search expressions conditions. ie title is "foo" | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_render_order_description --></div> | ||
+ | ===$xhtml = $searchexp->render_order_description=== | ||
+ | |||
+ | Return an XHTML DOM description of how this search is ordered. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=item_set_property --></div> | ||
+ | ===$searchexp->set_property( $property, $value );=== | ||
+ | |||
+ | Set any single property of this search, such as the order. | ||
+ | |||
+ | <div style='background-color: #eef; margin: 0.5em 0em 1em 0em; border: solid 1px #cce; padding: 0em 1em 0em 1em; font-size: 80%; '> | ||
+ | <h4><span style='display:none'>User Comments</span></h4> | ||
+ | <!-- Edit below this comment --> | ||
+ | |||
+ | |||
+ | <!-- Pod2Wiki=_postamble_ --><!-- Edit below this comment --> |
Revision as of 16:01, 19 August 2009
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 $searchexp = EPrints::Search->new( satisfy_all => 1, handle => $handle, dataset => $ds, order => "-date" ); $searchexp->add_field( $ds->get_field( "type" ), qw/ article book /, "EQ", "ANY" ); # getting the results: my $list = $searchexp->perform_search; # Dispose of the Search object: $searchexp->dispose;
SEE ALSO <EPrints::List> to know how to access the results of the search.
METHODS
$searchexp = 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 $searchexp->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 = $searchexp->perform_search
Execute this search and return a EPrints::List object representing the results.
$searchfield = $searchexp->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.
$searchexp->clear
Clear the search values of all search fields in the expression.
Resets satisfy_all to true.
$newsearchexp = $searchexp->clone
Return a new search expression which is a duplicate of this one.
$xhtml = $searchexp->render_description
Return an XHTML DOM description of this search expressions current parameters.
$xhtml = $searchexp->render_conditions_description
Return an XHTML DOM description of this search expressions conditions. ie title is "foo"
$xhtml = $searchexp->render_order_description
Return an XHTML DOM description of how this search is ordered.
$searchexp->set_property( $property, $value );
Set any single property of this search, such as the order.