[EP-tech] Re: Documentation for EPrint searches
Ian Stuart
Ian.Stuart at ed.ac.uk
Tue May 28 16:13:25 BST 2013
Cheers Seb....
How about 3.2 (half of us are still old-fashioned that way :chuckle: )
This is the very basics that I already know:
# Right... which datasets are we searching?
my $dso = $session->get_repository->get_dataset("archive");
# Set up a search object
my $searchexp1 = EPrints::Search->new(
satisfy_all => 1,
session => $session,
dataset => $dso,
);
# Find all the eprints where "foo" is "Ian"
$searchexp1->add_field( $dso->get_field("foo"), 'Ian' );
# now search for all eprints where we have "last modified" date of
# yesterday (using Time::Piece & Time::Seconds here)
my $time = localtime;
my $diff = 3; # Number of months the report covers
my $sdate = $time->strftime("%Y-%m-%d");
$time -= ( ONE_MONTH * $diff );
my $edate = $time->strftime("%Y-%m-%d");
my $date = "${edate}-${sdate}";
$searchexp1->add_field( $dso->get_field("lastmod"), $date );
# do the search
my $results1 = $searchexp1->perform_search;
my $total_new = $results1->count;
print "$total_new records modified\n" if ( $noise > 0 );
# This is where do something with the results from our search
foreach my $epid ( sort @{ $results1->ids } ) {
my $ep = $dso->dataobj($epid);
print $ep->export('Text');
print "\n---------------\n";
} ## end foreach my $epid ( sort @{ ...})
# and tidy up
$results1->dispose;
I'd still like to know how to restrict the search to only include
records where a particular field is defined (such as a creators id
[email address])
On 28/05/13 15:37, Sebastien Francois wrote:
> Hi Ian,
>
> On recent versions of EPrints (this was introduced in the 3.3 branch but
> I'm not sure when exactly) - I tested on a 3.3.11:
>
> my $list = $session->dataset( 'eprint' )->search(
> filters => [
> { meta_fields => [ 'abstract' ], match => 'SET' },
> { meta_fields => [ 'title' ], value => 'Fred', match =>
> 'IN' }
> ] );
>
> print STDERR "Found ".$list->count." results\n";
>
> I personally like to nest the calls:
>
> $session->dataset( 'eprint' )->search(
> filters => [
> { meta_fields => [ 'abstract' ], match => 'SET' },
> { meta_fields => [ 'title' ], value => 'Fred', match =>
> 'IN' }
> ] )->map( sub {
>
> my( undef, undef, $eprint ) = @_;
>
> # do something with $eprint
>
> } );
>
> otherwise use $list->map( ... );
>
> Seb.
>
> On 28/05/13 15:17, Ian Stuart wrote:
>> I'm sure I ask this every 6 months.... and I keep searching the net &
>> not find anything...
>>
>> Is there any documentation on creating searches in EPrints?
>>
>> I want to find all the eprints where field A is not empty and field B
>> has the value "Fred"
>>
>
> *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
> *** Archive: http://www.eprints.org/tech.php/
> *** EPrints community wiki: http://wiki.eprints.org/
>
--
Ian Stuart.
Developer: ORI, RJ-Broker, and OpenDepot.org
Bibliographics and Multimedia Service Delivery team,
EDINA,
The University of Edinburgh.
http://edina.ac.uk/
This email was sent via the University of Edinburgh.
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
More information about the Eprints-tech
mailing list