[EP-tech] Re: Creating searches in EPrints?

Ian Stuart Ian.Stuart at ed.ac.uk
Tue Dec 11 08:55:58 GMT 2012


On 10/12/12 17:07, Tim Brody wrote:
> On Fri, 2012-12-07 at 12:14 +0000, Ian Stuart wrote:
>> Is this documented anywhere? I'm not finding anything...
>>
>> If I have the following defined for an eprint dataObject:
>>
>>           {
>>               'name' => 'broker',
>>               'type' => 'compound',
>>               'multiple' => 1,
>>               'fields' => [
>>                     { sub_name => 'orgid',    'type' => 'text' },
>>                     { sub_name => 'orgname',  'type' => 'text' },
>>                     { sub_name => 'repoid',   'type' => 'text' },
>>                     { sub_name => 'reponame', 'type' => 'text' },
>>                     { sub_name => 'sword',    'type' => 'boolean' },
>>                     { sub_name => 'sent',     'type' => 'time', },
>>                     { sub_name => 'return',   'type' => 'url' },
>>                     { sub_name => 'live',     'type' => 'time', },
>>                     { sub_name => 'target',   'type' => 'url' },
>>                     { sub_name => 'note',     'type' => 'text' },
>>                     { sub_name => 'archiver', 'type' => 'boolean' },
>>                           ],
>>             },
>>
>> I should be able to create a search thus:
>>
>>     my $dso = $session->get_repository->get_dataset("archive");
>>     my $searchexp1 = EPrints::Search->new(
>>       satisfy_all => 1,
>>       session     => $session,
>>       dataset     => $dso,
>>     );
>>     $searchexp1->add_field( $dso->get_field("broker_sword"), 'TRUE' );
>>     $searchexp1->add_field( $dso->get_field("broker_sent"),  '2000-' );
>>     $searchexp1->add_field( $dso->get_field("broker_live"),  '' );
>>     my $results1 = $searchexp1->perform_search;
>>
>> As I understand it, this should list only those records where one or
>> more of the broker elements has the sub_field "sword" set true, and the
>> sub_field "sent" defined and after the year 2000, and the sub_field
>> "live" is empty
>> .... unfortunately, I'm getting records where sub_field "sword" is true,
>> but none of the broker elements have a "sent" sub_field
>>
>> Is there anything out there?
>>
>
> To help debug,
> print $searchexp1->get_conditions->describe;
>
> To see what you're getting.
>
> On more recent versions you can use '..' as the range selector, in case
> it's a problem with understanding '-' with just a year (or maybe
> "2000-01-01-" ?).

Yep - turns out to need
$searchexp1->add_field( $dso->get_field("broker_sent"), 
'2000-01-01-3000-12-31');

So I'm now getting a described query of:
AND(
   =($archive.eprint_status,"archive") ... eprint,
   =($archive.broker_sword,"TRUE") ... eprint_broker_sword,
   AndSubQuery(
        >=($archive.broker_sent,"2000-01-01") ... eprint_broker_sent,
        <=($archive.broker_sent,"3000-12-31") ... eprint_broker_sent
   )
)
.... however it seems the "AndSubQuery" is not a proper AND, more a PLUS 
- this is a returned list of broker sub-fields.... and you'll note none 
of them have a 'sent' field between the dates in the query:
  'broker' => [
               {
                  'index' => 2,
                  'reponame' => 'Edinburgh DataShare',
                  'sword' => 'FALSE',
                  'eprintid' => 185,
                  'repoid' => '12065',
                  'orgname' => 'ed.ac.uk',
                  'orgid' => '16480',
                  'archiver' => 'FALSE'
               },
               {
                  'index' => 3,
                  'reponame' => 'Edinburgh Research Archive',
                  'sword' => 'TRUE',
                  'eprintid' => 185,
                  'repoid' => '12066',
                  'orgname' => 'ed.ac.uk',
                  'orgid' => '16480',
                  'archiver' => 'FALSE'
               },
               {
                  'index' => 4,
                  'reponame' => 'Informatics at Edinburgh - Reports Series',
                  'sword' => 'FALSE',
                  'eprintid' => 185,
                  'repoid' => '12287',
                  'orgname' => 'ed.ac.uk',
                  'orgid' => '16480',
                  'archiver' => 'FALSE'
               },
               {
                  'index' => 1,
                  'reponame' => 'JorumOpen',
                  'sword' => 'FALSE',
                  'eprintid' => 185,
                  'repoid' => '13311',
                  'orgname' => 'EDINA',
                  'orgid' => '16300',
                  'archiver' => 'FALSE'
                }
              ],


-- 

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