[EP-tech] Searching for null/unset values
Alan.Stiles
alan.stiles at open.ac.uk
Wed Jul 4 16:43:10 BST 2018
I concur - having tried this in a script against some test data:
my $ds = $session->dataset("buffer");
my $searchexp = $ds->prepare_search();
$searchexp->add_field( $ds->get_field("date"), undef, "EX" );
my $list = $searchexp->perform_search();
print STDERR $list->count;
Gives me the same number as running the SQL statement
SELECT eprintid, date_year FROM eprint WHERE eprint_status = "buffer" AND date_year IS NULL;
And replacing the undef with a number (e.g. 2018) gives the same results as ending the SQL with
... AND date_year = 2018;
Good spot and definitely something that could be clearer in the wiki.
Cheers,
Alan
From: eprints-tech-bounces at ecs.soton.ac.uk [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of John Salter
Sent: 04 July 2018 14:49
To: 'eprints-tech at ecs.soton.ac.uk' <eprints-tech at ecs.soton.ac.uk>
Subject: [EP-tech] Searching for null/unset values
Hi All,
Can anyone validate this for me?
On this page: https://wiki.eprints.org/w/API:EPrints/Search#add_field (generated from perldoc in EPrints::Search), the following statement is made for the value:
"value - value to match against (for EX matches, NULL = is_null!)"
This has always seemed very cryptic/unhelpful to me - but I've never needed to get a null search working - until now.
Experimentation has led to the following which seems to work (example: searching buffer for items with no date):
my $ds = $session->dataset( "buffer" );
my $searchexp = $ds->prepare_search();
$searchexp->add_field(
fields => [
$ds->field( 'date' ),
],
value => undef,
match => "EX",
);
-the 'value => undef,' being the critical piece.
Before I add this to the Wiki, can anyone else confirm this is correct?
Cheers,
John
-- The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). The Open University is authorised and regulated by the Financial Conduct Authority in relation to its secondary activity of credit broking.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/eprints-tech/attachments/20180704/6217adeb/attachment.html
More information about the Eprints-tech
mailing list