EPrints Technical Mailing List Archive

Message: #04438


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

[EP-tech] Re: Finding selected lang from configuration


I don't believe virtual fields will get searched because they aren't stored in the database.

You should add the multilang field to the search form, but I'm actually not sure how it will behave.

--
Adam Field
Business Relationship Manager and Community Lead
EPrints Services

On 2 Jul 2015, at 12:10, George Mamalakis <mamalos@eng.auth.gr> wrote:

Excellent observation skills!! :):)...and sorry for not having seen that.

One more question. With this setup (for title and abstract with two fields each), will searches work as expected? Meaning that, based on the selected language, EPrints will search the (dynamically generated) appropriate language title field for example? Because I'm trying to test it, but I'm facing some difficulties using the extended search menu, and I'm not sure if this is the problem (putting the title ). Simple search works just fine, but I assume that simple search searches all fields?

Thanks again!

George.

On 02/07/2015 01:56 μμ, Adam Field wrote:
You need square brackets around the 0, not curly ones (you're accessing an array, not a hash).

--
Adam Field
Business Relationship Manager and Community Lead
EPrints Services

On 2 Jul 2015, at 11:52, George Mamalakis <mamalos@eng.auth.gr> wrote:

Hi Adam,

I faced a problem when I performed the changes you suggested,
specifically with this line:

${$$vals[0]}{'text'} becomes $vals->[0]->{text}

After I changed this line, the program started to crash (server error).
When debugging it (by using a custom script that prints the 'title''s
value), when printing, for one of my records I received a:

Not a HASH reference at (eval 60) line 104.

error. Line 104 was the line containing:

$title = $vals->{0}->{'text'};

Trying to see why this was happening, I realised that the specific
record was missing the lang value (where el should have been present).
Meaning:

Previous value: $VAR1 = [
          {
            'text' => 'The English title',
            'lang' => 'en'
          },
          {
            'lang' => '',
            'text' => "\x{39f}
\x{395}\x{3bb}\x{3bb}\x{3b7}\x{3bd}\x{3b9}\x{3ba}\x{3cc}\x{3c2}
\x{3c4}\x{3af}\x{3c4}\x{3bb}\x{3bf}\x{3c2}"
          }
        ];

How come my previous code was handling it without a problem whereas the
one you proposed weren't? As I said I'm not well acquainted with perl,
so I'm not even sure how to debug this any further. And, to be honest,
since missing values will definitely be a case for my repository, I
cannot adopt your suggestion once it breaks; but I assume that there's
an easy work-around for this.

Thanks again!

On 01/07/2015 05:14 μμ, Field A.N. wrote:
Hi George

I wouldn't worry about performance unless you're seeing specific problems.  However, you can get it from $repository->id() I believe.  Don't assume there's be a database lookup, as its

I would also recommend the following changes in syntax for readability:

%$v1{'lang'} becomes $v1->{lang}
%$v1{'text'} becomes $v1->{text}
${$$vals[0]}{'text'} becomes $vals->[0]->{text}

Best Wishes

--
Adam Field
Business Relationship Manager and Community Lead
EPrints Services
+44 (0)23 8059 8814





On 1 Jul 2015, at 11:34, George Mamalakis wrote:

Cheers Adam,

It worked like a charm! Now please allow me to asking you one more
thing: I changed my title field to contain code that looks for my
repository_id through the $eprint variable (which is my method's
parameter), which means that the system will have to make an additional
database call each time my field is accessed for each object. There's no
easier method of having access to it, I suppose? (eg. directly, like I
have access to the configuration via $c).

PS. My new title-field code is as follows:

{
    name => 'title',
    type => 'virtualwithvalue',
    virtual => 1,

    get_value => sub
    {
        my ($eprint) = @_;
        if ($eprint->is_set('ml_title'))
        {
            my $repo = $eprint->repository;
            my $lang = $repo->get_langid;
            # if cannot find a user language setting, I'm taking the
default one
            if (!$lang)
            {
                $lang = $c->{defaultlanguage};
            }
            my $vals = $eprint->get_value('ml_title');
            my $title = '';
            # set the default lang's text as title
            foreach my $v1 (@{$vals})
            {
                if (%$v1{'lang'} eq $lang)
                {
                    $title = %$v1{'text'};
                }
            }
            # if I couldn't find a title in the user's language, get
the first object's text as title
            if ($title eq '')
            {
                $title = ${$$vals[0]}{'text'} ;
            }
            return $title;

        }
        return undef;
    }
},



On 01/07/2015 12:30 μμ, Field A.N. wrote:
It should be:

$repository->get_lang(), which will return an EPrints::Language object, or $repository->get_langid, which will return the ID of the language.

--
Adam Field
Business Relationship Manager and Community Lead
EPrints Services
+44 (0)23 8059 8814





On 30 Jun 2015, at 10:29, George Mamalakis wrote:

Hi all,

I am testing the multilang field (with virtual fields for title and
abstract) and I am trying to make my virtual field return a different
title (or abstract) based on what the user's language choice is. How can
I have access to that variable on my perl configuration file? (I've
tested the default language and works as expected, but I don't find it
usable.)

Thanks all in advance.

--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379


*** 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/
*** EPrints developers Forum: http://forum.eprints.org/
*** 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/
*** EPrints developers Forum: http://forum.eprints.org/

--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379



*** 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/
*** EPrints developers Forum: http://forum.eprints.org/

*** 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/
*** EPrints developers Forum: http://forum.eprints.org/



--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379



*** 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/
*** EPrints developers Forum: http://forum.eprints.org/



*** 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/
*** EPrints developers Forum: http://forum.eprints.org/


-- 
George Mamalakis

IT and Security Officer, 
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379


*** 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/
*** EPrints developers Forum: http://forum.eprints.org/