[open-ils-commits] r15962 - in trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage: Driver/Pg Publisher (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Mar 24 16:18:56 EDT 2010
Author: miker
Date: 2010-03-24 16:18:50 -0400 (Wed, 24 Mar 2010)
New Revision: 15962
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm
Log:
plan stability through casting for plpgsql; improve preferred language support
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm 2010-03-24 19:58:28 UTC (rev 15961)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm 2010-03-24 20:18:50 UTC (rev 15962)
@@ -397,10 +397,11 @@
}
if (($filters{preferred_language} || $self->QueryParser->default_preferred_language) && ($filters{preferred_language_multiplier} || $self->QueryParser->default_preferred_language_multiplier)) {
- $rel = "($rel) * CASE WHEN mrd.lang = ". $self->QueryParser->quote_value( $filters{preferred_language} ? $filters{preferred_language} : $self->QueryParser->default_preferred_language ) . " THEN ";
+ $rel = "($rel * CASE WHEN FIRST(mrd.item_lang) = ". $self->QueryParser->quote_value( $filters{preferred_language} ? $filters{preferred_language} : $self->QueryParser->default_preferred_language ) . " THEN ";
$rel .= $filters{preferred_language_multiplier} ? $filters{preferred_language_multiplier} : $self->QueryParser->default_preferred_language_multiplier;
- $rel .= " ELSE 1 END";
+ $rel .= " ELSE 1 END)";
}
+ $rel .= "::NUMERIC";
for my $f ( qw/audience vr_format item_type item_form lit_form language bib_level/ ) {
my $col = $f;
@@ -436,20 +437,20 @@
my $default = $desc eq 'DESC' ? ' ' : 'zzzzzz';
$rank = <<" SQL";
( COALESCE( FIRST ((
- SELECT LTRIM(SUBSTR( frt.value, COALESCE(SUBSTRING(frt.ind2 FROM E'\\\\d+'),'0')::INT + 1 ))
+ SELECT frt.value
FROM metabib.full_rec frt
WHERE frt.record = m.source
AND frt.tag = 'tnf'
AND frt.subfield = 'a'
LIMIT 1
- )),'$default'))
+ )),'$default'))::TEXT
SQL
} elsif ($sort_filter eq 'pubdate') {
$rank = "COALESCE( FIRST(NULLIF(REGEXP_REPLACE(mrd.date1, E'\\\\D+', '0', 'g'),'')), '0' )::INT";
} elsif ($sort_filter eq 'create_date') {
- $rank = "( FIRST (( SELECT create_date FROM biblio.record_entry rbr WHERE rbr.id = m.source)) )";
+ $rank = "( FIRST (( SELECT create_date FROM biblio.record_entry rbr WHERE rbr.id = m.source)) )::TIMESTAMPTZ";
} elsif ($sort_filter eq 'edit_date') {
- $rank = "( FIRST (( SELECT edit_date FROM biblio.record_entry rbr WHERE rbr.id = m.source)) )";
+ $rank = "( FIRST (( SELECT edit_date FROM biblio.record_entry rbr WHERE rbr.id = m.source)) )::TIMESTAMPTZ";
} elsif ($sort_filter eq 'author') {
my $default = $desc eq 'DESC' ? ' ' : 'zzzzzz';
$rank = <<" SQL"
@@ -461,7 +462,7 @@
AND fra.subfield = 'a'
ORDER BY fra.tag::text::int
LIMIT 1
- )),'$default'))
+ )),'$default'))::TEXT
SQL
} else {
# default to rel ranking
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm 2010-03-24 19:58:28 UTC (rev 15961)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm 2010-03-24 20:18:50 UTC (rev 15962)
@@ -2802,30 +2802,6 @@
}
-
- # set the locale-based default prefered location
- $parser->default_preferred_language( $args{preferred_language} );
- if (!$parser->default_preferred_language) {
- my $ses_locale = $client->session ? $client->session->session_locale : '';
- $parser->default_preferred_language( $locale_map{ $ses_locale } );
- }
- $parser->default_preferred_language(
- OpenSRF::Utils::SettingsClient->new->config_value(
- apps => 'open-ils.storage' => app_settings => 'default_preferred_language'
- )
- ) if (!$parser->default_preferred_language);
-
-
- # set the global default language multiplier
- $parser->default_preferred_language_multiplier($args{preferred_language_weight});
- $parser->default_preferred_language_multiplier($args{preferred_language_multiplier});
- $parser->default_preferred_language_multiplier(
- OpenSRF::Utils::SettingsClient->new->config_value(
- apps => 'open-ils.storage' => app_settings => 'default_preferred_language_weight'
- )
- ) if (!$parser->default_preferred_language_multiplier);
-
-
# I hope we have a query!
if (! $args{query} ) {
die "No query was passed to ".$self->api_name;
@@ -2843,6 +2819,33 @@
# we expect, and make use of, query, superpage, superpage_size, debug and core_limit args
my $query = $parser->new( %args )->parse;
+
+ # set the locale-based default prefered location
+ if (!$query->parse_tree->find_filter('preferred_language')) {
+ $parser->default_preferred_language( $args{preferred_language} );
+ if (!$parser->default_preferred_language) {
+ my $ses_locale = $client->session ? $client->session->session_locale : '';
+ $parser->default_preferred_language( $locale_map{ $ses_locale } );
+ }
+ $parser->default_preferred_language(
+ OpenSRF::Utils::SettingsClient->new->config_value(
+ apps => 'open-ils.storage' => app_settings => 'default_preferred_language'
+ )
+ ) if (!$parser->default_preferred_language);
+ }
+
+
+ # set the global default language multiplier
+ if (!$query->parse_tree->find_filter('preferred_language_weight') and !$query->parse_tree->find_filter('preferred_language_multiplier')) {
+ $parser->default_preferred_language_multiplier($args{preferred_language_weight});
+ $parser->default_preferred_language_multiplier($args{preferred_language_multiplier});
+ $parser->default_preferred_language_multiplier(
+ OpenSRF::Utils::SettingsClient->new->config_value(
+ apps => 'open-ils.storage' => app_settings => 'default_preferred_language_weight'
+ )
+ ) if (!$parser->default_preferred_language_multiplier);
+ }
+
# gather the site, if one is specified, defaulting to the in-query version
my $ou = $args{org_unit};
if (my ($filter) = $query->parse_tree->find_filter('site')) {
@@ -3055,9 +3058,10 @@
}
+ my $base_plan = $parser->new( query => $base_query )->parse;
- $query = "preferred_language($args{preferred_language}) $query" if ($args{preferred_language});
- $query = "preferred_language_weight($args{preferred_language_weight}) $query" if ($args{preferred_language_weight});
+ $query = "preferred_language($args{preferred_language}) $query" if ($args{preferred_language} and !$base_plan->parse_tree->find_filter('preferred_language'));
+ $query = "preferred_language_weight($args{preferred_language_weight}) $query" if ($args{preferred_language_weight} and !$base_plan->parse_tree->find_filter('preferred_language_weight') and !$base_plan->parse_tree->find_filter('preferred_language_multiplier'));
$query = "estimation_strategy($args{estimation_strategy}) $query" if ($args{estimation_strategy});
$query = "site($args{org_unit}) $query" if ($args{org_unit});
$query = "limit($args{limit}) $query" if ($args{limit});
More information about the open-ils-commits
mailing list