Difference between revisions of "API:EPrints/Search"

From EPrints Documentation
Jump to: navigation, search
Line 31: Line 31:
 
   my $ds = $handle->get_dataset( "archive" );
 
   my $ds = $handle->get_dataset( "archive" );
 
    
 
    
   my $searchexp = EPrints::Search->new(
+
   my $search = EPrints::Search->new(
 
     satisfy_all => 1,
 
     satisfy_all => 1,
 
     handle => $handle,
 
     handle => $handle,
Line 38: Line 38:
 
   );
 
   );
 
    
 
    
   $searchexp->add_field( $ds->get_field( "type" ), qw/ article book /, "EQ", "ANY" );
+
   $search->add_field( $ds->get_field( "type" ), qw/ article book /, "EQ", "ANY" );
 
    
 
    
 
   # getting the results:
 
   # getting the results:
   my $list = $searchexp->perform_search;
+
   my $list = $search->perform_search;
 
    
 
    
 
   # Dispose of the Search object:
 
   # Dispose of the Search object:
   $searchexp->dispose;
+
   $search->dispose;
 
    
 
    
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 66: Line 66:
  
 
<!-- Pod2Wiki=item_new --></div>
 
<!-- Pod2Wiki=item_new --></div>
===$searchexp = EPrints::Search-&gt;new( %params )===
+
===$search = EPrints::Search-&gt;new( %params )===
  
 
Create a new search expression.
 
Create a new search expression.
Line 126: Line 126:
 
where the meaning is the same as for search configuration in cfg.d/eprint_search_*.pl
 
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-&gt;add_field(...)).
+
Search fields can also be added to the search expression after it has been constructed (by using $search-&gt;add_field(...)).
  
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
 
<div style='background-color: #e8e8f; margin: 0.5em 0em 1em 0em; border: solid 1px #cce;  padding: 0em 1em 0em 1em; font-size: 80%; '>
Line 222: Line 222:
  
 
<!-- Pod2Wiki=item_perform_search --></div>
 
<!-- Pod2Wiki=item_perform_search --></div>
===$results = $searchexp-&gt;perform_search===
+
===$results = $search-&gt;perform_search===
  
 
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.
Line 232: Line 232:
  
 
<!-- Pod2Wiki=item_add_field --></div>
 
<!-- Pod2Wiki=item_add_field --></div>
===$searchfield = $searchexp-&gt;add_field( $metafields, $value, $match, $merge, $id, $filter, $show_help )===
+
===$searchfield = $search-&gt;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.
 
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.
Line 242: Line 242:
  
 
<!-- Pod2Wiki=item_clear --></div>
 
<!-- Pod2Wiki=item_clear --></div>
===$searchexp-&gt;clear===
+
===$search-&gt;clear===
  
 
Clear the search values of all search fields in the expression.
 
Clear the search values of all search fields in the expression.
Line 254: Line 254:
  
 
<!-- Pod2Wiki=item_clone --></div>
 
<!-- Pod2Wiki=item_clone --></div>
===$newsearchexp = $searchexp-&gt;clone===
+
===$newsearch = $search-&gt;clone===
  
 
Return a new search expression which is a duplicate of this one.
 
Return a new search expression which is a duplicate of this one.
Line 264: Line 264:
  
 
<!-- Pod2Wiki=item_render_description --></div>
 
<!-- Pod2Wiki=item_render_description --></div>
===$xhtml = $searchexp-&gt;render_description===
+
===$xhtml = $search-&gt;render_description===
  
 
Return an XHTML DOM description of this search expressions current parameters.
 
Return an XHTML DOM description of this search expressions current parameters.
Line 274: Line 274:
  
 
<!-- Pod2Wiki=item_render_conditions_description --></div>
 
<!-- Pod2Wiki=item_render_conditions_description --></div>
===$xhtml = $searchexp-&gt;render_conditions_description===
+
===$xhtml = $search-&gt;render_conditions_description===
  
 
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"  
Line 284: Line 284:
  
 
<!-- Pod2Wiki=item_render_order_description --></div>
 
<!-- Pod2Wiki=item_render_order_description --></div>
===$xhtml = $searchexp-&gt;render_order_description===
+
===$xhtml = $search-&gt;render_order_description===
  
 
Return an XHTML DOM description of how this search is ordered.
 
Return an XHTML DOM description of how this search is ordered.
Line 294: Line 294:
  
 
<!-- Pod2Wiki=item_set_property --></div>
 
<!-- Pod2Wiki=item_set_property --></div>
===$searchexp-&gt;set_property( $property, $value );===
+
===$search-&gt;set_property( $property, $value );===
  
 
Set any single property of this search, such as the order.
 
Set any single property of this search, such as the order.

Revision as of 19:13, 25 August 2009


EPrints 3 Reference: Directory Structure - Metadata Fields - Repository Configuration - XML Config Files - XML Export Format - EPrints data structure - Core API - Data Objects


API: Core API

Latest Source Code (3.3, 3.2) | Revision Log | Before editing this page please read Pod2Wiki


NAME

EPrints::Search - Represents a single search

User Comments


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.

User Comments


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;
 

User Comments


SEE ALSO <EPrints::List> to know how to access the results of the search.

User Comments


METHODS

User Comments


$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

User Comments


handle (required)

The current EPrints::Handle

User Comments


dataset OR dataset_id (required)

Either the EPrints::DataSet to search, or the ID of it.

User Comments


allow_blank (default 0)

Unless this is set, a search with no conditions will return zero records rather than all records.

User Comments


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.

User Comments


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(...)).

User Comments


order

The order the results should be returned.

User Comments


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.

User Comments


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.

User Comments


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.

User Comments


limit

Limit the number of matching records to limit.

User Comments


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.

User Comments


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.

User Comments


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.

User Comments


$results = $search->perform_search

Execute this search and return a EPrints::List object representing the results.

User Comments


$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.

User Comments


$search->clear

Clear the search values of all search fields in the expression.

Resets satisfy_all to true.

User Comments


$newsearch = $search->clone

Return a new search expression which is a duplicate of this one.

User Comments


$xhtml = $search->render_description

Return an XHTML DOM description of this search expressions current parameters.

User Comments


$xhtml = $search->render_conditions_description

Return an XHTML DOM description of this search expressions conditions. ie title is "foo"

User Comments


$xhtml = $search->render_order_description

Return an XHTML DOM description of how this search is ordered.

User Comments


$search->set_property( $property, $value );

Set any single property of this search, such as the order.

User Comments