Difference between revisions of "API:EPrints/Search"
Line 10: | Line 10: | ||
'''EPrints::Search''' - Represents a single search | '''EPrints::Search''' - Represents a single search | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 21: | Line 21: | ||
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. | 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: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 46: | Line 46: | ||
$searchexp->dispose; | $searchexp->dispose; | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 53: | Line 53: | ||
<!-- Pod2Wiki=head_see_also_eprints_list_to_know_how_to_access_the_results_of_the_search --></div> | <!-- 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.== | ==SEE ALSO <EPrints::List> to know how to access the results of the search.== | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 60: | Line 60: | ||
<!-- Pod2Wiki=head_methods --></div> | <!-- Pod2Wiki=head_methods --></div> | ||
==METHODS== | ==METHODS== | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 74: | Line 74: | ||
GENERAL PARAMETERS | GENERAL PARAMETERS | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 84: | Line 84: | ||
The current [[API:EPrints/Handle|EPrints::Handle]] | The current [[API:EPrints/Handle|EPrints::Handle]] | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 94: | Line 94: | ||
Either the [[API:EPrints/DataSet|EPrints::DataSet]] to search, or the ID of it. | Either the [[API:EPrints/DataSet|EPrints::DataSet]] to search, or the ID of it. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 104: | Line 104: | ||
Unless this is set, a search with no conditions will return zero records rather than all records. | Unless this is set, a search with no conditions will return zero records rather than all records. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 114: | Line 114: | ||
If this is true than all search-fields much be satisfied, if false then results matching any search-field will be returned. | 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: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 128: | Line 128: | ||
Search fields can also be added to the search expression after it has been constructed (by using $searchexp->add_field(...)). | Search fields can also be added to the search expression after it has been constructed (by using $searchexp->add_field(...)). | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 138: | Line 138: | ||
The order the results should be returned. | The order the results should be returned. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 148: | Line 148: | ||
"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. | "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: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 160: | Line 160: | ||
keep_cache may get set to true anyway for various reasons, but setting the parameter makes certain of it. | keep_cache may get set to true anyway for various reasons, but setting the parameter makes certain of it. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 172: | Line 172: | ||
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. | 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: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 182: | Line 182: | ||
Limit the number of matching records to limit. | Limit the number of matching records to limit. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 192: | Line 192: | ||
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. | 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: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 202: | Line 202: | ||
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. | 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: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 216: | Line 216: | ||
An optional parameter of describe=>0 can be set to supress the filter being mentioned in the description of the search. | 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: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 226: | Line 226: | ||
Execute this search and return a [[API:EPrints/List|EPrints::List]] object representing the results. | Execute this search and return a [[API:EPrints/List|EPrints::List]] object representing the results. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 236: | Line 236: | ||
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. | 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: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 248: | Line 248: | ||
Resets satisfy_all to true. | Resets satisfy_all to true. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 258: | Line 258: | ||
Return a new search expression which is a duplicate of this one. | Return a new search expression which is a duplicate of this one. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 268: | Line 268: | ||
Return an XHTML DOM description of this search expressions current parameters. | Return an XHTML DOM description of this search expressions current parameters. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 278: | Line 278: | ||
Return an XHTML DOM description of this search expressions conditions. ie title is "foo" | Return an XHTML DOM description of this search expressions conditions. ie title is "foo" | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 288: | Line 288: | ||
Return an XHTML DOM description of how this search is ordered. | Return an XHTML DOM description of how this search is ordered. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> | ||
Line 298: | Line 298: | ||
Set any single property of this search, such as the order. | Set any single property of this search, such as the order. | ||
− | <div style='background-color: # | + | <div style='background-color: #e8e8f; 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> | <h4><span style='display:none'>User Comments</span></h4> | ||
<!-- Edit below this comment --> | <!-- Edit below this comment --> |
Revision as of 14:03, 24 August 2009
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 $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.