EPrints Technical Mailing List Archive

See the EPrints wiki for instructions on how to join this mailing list and related information.

Message: #06442


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Virtual Field derived by SQL query or code and available for searching.


All,

 

I've delved into testing Adam Fields excellent video on Virtual fields (http://www.youtube.com/watch?v=GjeWcewJA5o) which works perfectly for creating a derived "display" only value visible within the abstract page, however when adding the newly created Virtualwithvalue type field into the advanced search form and searching against it returns zero results (at least on our system here).  I expect that there is some tweak needed or some additional voodoo needed to get that to work correctly which I think I've only seen the tip of the iceberg at this point.

 

What I've been asked to investigate is adding a field to the advanced search that would indicate if the Eprint has full text or not (to allow for searching of only full text items) as we have both metadata only and full text items in our IR and the wish is to only search items that contain full text.

 

I've been able to create a virtual field as follows:

 

In my zz_local_fields.pl file I've created the get_value and set_value properties as follows base upon Adam's video and some code:

    name => 'fulltext',

    type => 'virtualwithvalue',

    virtual => 1,

    get_value => sub

    {

        my ($eprint) = @_;

        my $val = '';

        if ( $eprint->get_all_documents == 0 )

        {

           $val = "FALSE";

           return $val;

        } else {

           $val = "TRUE";

           return $val;

        }

    },

    set_value => sub

    {

        my ($eprint, $value) = @_;

        if ( $eprint->get_all_documents == 0 )

        {

            $eprint->set_value('fulltext',"FALSE");

        } else {

            $eprint->set_value('fulltext',"TRUE");

        }

    }

 

This "derived" field works perfectly within the abstract view.  The definition of an Eprint containing full text or not seems to be if $eprint->get_all_documents == 0 or not.  I expect we could create an SQL query to extract this or use some code.  Obviously we could create a regular field and populate it with the use of eprint_automatic_fields.pl but the value "TRUE"|"FALSE" could be easily derived using code or SQL query instead. 

 

We'd like to extend this virtual field a bit so that the same field can also be searched against in the advanced search.  Has anyone implemented something along those lines?  Or am I missing something that is maybe too obvious for me to see?

 

A discussion with a colleague of mine resulted in his suggestion that we may need to create a type of Virtualfromsql.pm where we create a virtual field which is derived from an SQL search, has anyone tried or had any experience with this kind of approach?

 

-Thanks,

Brian.

 

Brian D. Gregg

Solutions Architect

University of Pittsburgh | University Library System

Address: 7500 Thomas Blvd.  Room 129 Pittsburgh, PA 15208

Tel: (412) 648-3264 | Email: bdgregg@pitt.edu | Fax: (412) 648-3585

https://orcid.org/0000-0001-6541-4544