Difference between revisions of "API:EPrints/DataSet"

From EPrints Documentation
Jump to: navigation, search
Line 1: Line 1:
<!-- Pod2Wiki=_preamble_  
<!-- 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.
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.
  -->{{API}}{{Pod2Wiki}}{{API:Source|file=EPrints/DataSet.pm|package_name=EPrints::DataSet}}[[Category:API|DATASET]][[Category:API:EPrints/DataSet|DATASET]]<div><!-- Edit below this comment -->
  -->{{API}}{{Pod2Wiki}}{{API:Source|file=perl_lib/EPrints/DataSet.pm|package_name=EPrints::DataSet}}[[Category:API|DATASET]][[Category:API:EPrints/DataSet|DATASET]]<div><!-- Edit below this comment -->

Revision as of 15:26, 16 December 2011

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


EPrints::DataSet - a set of records with the same metadata scheme

User Comments


 my $dataset = $repository->dataset( "inbox" );
 print sprintf("There are %d records in the inbox\n",
 $string = $dataset->base_id; # eprint
 $string = $dataset->id; # inbox
 $dataobj = $dataset->create_dataobj( $data );
 $user = $dataset->dataobj( 23 );
 $search = $dataset->prepare_search( %options );
 $list = $dataset->search( %options ); # prepare_search( %options )->execute
 $list = $dataset->search; # match ALL
 $metafield = $dataset->field( $fieldname );
 $metafield = $dataset->key_field;
 @metafields = $dataset->fields; 
 $dataset->search->map( sub {}, $ctx );
 $n = $dataset->search->count; 
 $ids = $dataset->search->ids;
 $list = $dataset->list( \@ids );

User Comments


This module describes a dataset.

A repository has several datasets that make up the repository's metadata schema. The list of dataset ids can be obtained from the repository object (see EPrints::Repository).

A normal dataset (eg. "user") has a package associated with it (eg. EPrints::DataObj::User) which must be a subclass of EPrints::DataObj and a number of SQL tables which are prefixed with the dataset name. Most datasets also have a set of associated EPrints::MetaField's which may be optional or required depending on the type eg. books have editors but posters don't but they are both EPrints.

The fields contained in a dataset are defined by the data object and by any additional fields defined in cfg.d. Some datasets don't have any fields.

Some datasets are "virtual" datasets made from others. Examples include "inbox", "archive", "buffer" and "deletion" which are all virtual datasets of of the "eprint" dataset. That is to say "inbox" is a subset of "eprint" and by inference contains EPrints::DataObj::EPrint. You can define your own virtual datasets which opperate on existing datasets.

User Comments


New datasets can be defined in a configuration file, e.g.

 $c->{datasets}->{bread} = {
   class => "EPrints::DataObj::Bread",
   sqlname => "bread",

This defines a dataset with the id bread (must be unique). The dataobj package (class) to instantiate objects with is EPrints::DataObj::Bread, which must be a sub-class of EPrints::DataObj. Lastly, the database tables used by the dataset will be called 'bread' or prefixed 'bread_'.

Other optional properties:

 columns - an array ref of field ids to default the user view to
 datestamp - field id to use to sort this dataset
 import - is the dataset importable?
 index - is the dataset text-indexed?
 order - is the dataset orderable?
 virtual - completely virtual dataset (no database tables)

To make one dataset a virtual dataset of another (as 'inbox' is to 'eprint') use the following properties:

 confid - the super-dataset this is a virtual sub-dataset of
 dataset_id_field - the field containing the sub-dataset id
 filters - an array ref of filters to apply when retrieving records

As with system datasets, the EPrints::MetaFields can be defined via EPrints::DataObj/get_system_field_info or via configuration:

   { name => "breadid", type => "counter", sql_counter => "bread" }
   { name => "toasted", type => "bool", }
   { name => "description", type => "text", }

See EPrints::RepositoryConfig/add_dataset_field for details on add_dataset_field.

Creating a fully-operational dataset will require more configuration files. You will probably want at least a workflow, citations for the summary page, search results etc, and permissions and searching settings:

 push @{$c->{user_roles}->{admin}}, qw(
 push @{$c->{plugins}->{"Export::SummaryPage"}->{params}->{accept}}, qw(
 $c->{datasets}->{bread}->{search}->{simple} = {
   search_fields => {
     id => "q",
     meta_fields => [qw(

User Comments


User Comments

Class Methods

User Comments

Object Methods

User Comments


$id = $ds->base_id
 $ds = $repo->dataset( "inbox" );
 $id = $ds->base_id; # returns "eprint"

Returns the identifier of the base dataset for this dataset (same as id unless this dataset is virtual).

User Comments


$metafield = $ds->field( $fieldname )

Returns the EPrints::MetaField from this dataset with the given name, or undef.

User Comments


$id = $ds->id

Return the id of this dataset.

User Comments


$n = $ds->count( $session )

Return the number of records in this dataset.

User Comments


@fields = $ds->fields

Returns a list of the EPrints::MetaFields belonging to this dataset.

User Comments


$field = $ds->key_field

Return the EPrints::MetaField representing the primary key field.

Always the first field.

User Comments


$dataobj = $ds->make_dataobj( $epdata )

Return an object of the class associated with this dataset, always a subclass of EPrints::DataObj.

$epdata is a hash of values for fields in this dataset.

Returns $epdata if no class is associated with this dataset.

User Comments


$obj = $ds->create_dataobj( $data )

Returns a new object in this dataset based on $data or undef on failure.

If $data describes sub-objects then those will also be created.

User Comments


$dataobj = $ds->dataobj( $id )

Returns the object from this dataset with the given id, or undefined.

User Comments


$repository = $ds->repository

Returns the EPrints::Repository to which this dataset belongs.

User Comments


$searchexp = $ds->prepare_search( %options )

Returns a EPrints::Search for this dataset with %options.

User Comments


$list = $ds->search( %options )

Short-cut to prepare_search( %options )->execute.

User Comments



Satify all conditions specified. 0 means satisfy any of the conditions specified. Default is 1

User Comments



Do search as an adminstrator means you get everything back

User Comments


"custom_order" => "field1/-field2/field3"

Order the search results by field order. prefixing the field name with a "-" results in reverse ordering

User Comments


"search_fields" => \@({meta_fields=>[ "field1", "field2" "document.field3" ], merge=>"ANY", match=>"EX", value=>"bees"}, {meta_fields=>[ "field4" ], value=>"honey"});

Return values where field1 field2 or field3 is "bees" and field2 is "honey" (assuming satisfy all is set)

User Comments


"limit" => 10

Only return 10 results

User Comments


$list = $ds->list( $ids )

Returns a EPrints::List for this dataset for the given $ids list.

User Comments


User Comments