From 45092421733eeb8e799669ae2b7849301818bff0 Mon Sep 17 00:00:00 2001 From: miker Date: Tue, 29 Jul 2008 04:45:42 +0000 Subject: [PATCH] Adding date filtering support and automatic/configurable default preferred language code git-svn-id: svn://svn.open-ils.org/ILS/trunk@10170 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/fm_IDL.xml | 2 + .../backend/catalog/biblio_descriptor.js | 2 + .../perlmods/OpenILS/Application/Ingest.pm | 8 +++ .../Application/Storage/CDBI/config.pm | 14 +++++ .../Application/Storage/CDBI/metabib.pm | 2 +- .../Application/Storage/Driver/Pg/dbi.pm | 11 ++++ .../Application/Storage/Publisher/metabib.pm | 62 ++++++++++++++++++- .../src/sql/Pg/300.schema.staged_search.sql | 42 +++++++------ 8 files changed, 120 insertions(+), 23 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index b7dea82a66..e32377689b 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -1513,6 +1513,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + + diff --git a/Open-ILS/src/javascript/backend/catalog/biblio_descriptor.js b/Open-ILS/src/javascript/backend/catalog/biblio_descriptor.js index 492882d27d..1c1d195229 100644 --- a/Open-ILS/src/javascript/backend/catalog/biblio_descriptor.js +++ b/Open-ILS/src/javascript/backend/catalog/biblio_descriptor.js @@ -22,6 +22,8 @@ environment.result.type_mat( extractFixedField( marcdoc, 'TMat' ) ); environment.result.cat_form( extractFixedField( marcdoc, 'Desc' ) ); environment.result.pub_status( extractFixedField( marcdoc, 'DtSt' ) ); environment.result.item_lang( extractFixedField( marcdoc, 'Lang' ) ); +environment.result.date1( extractFixedField( marcdoc, 'Date1' ) ); +environment.result.date2( extractFixedField( marcdoc, 'Date2' ) ); environment.result.vr_format( videorecordingFormatCode( marcdoc ) ); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm b/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm index 61694be438..9cf011ecea 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Ingest.pm @@ -1088,6 +1088,14 @@ sub biblio_descriptor { my $res = $rd_script->run || ($log->error( "Descriptor script died! $@" ) && return undef); $log->debug("Script for biblio descriptor extraction completed successfully"); + if ($res->{date1} ne ' ') { + $res->{date1} =~ tr/ux/00/; + } + + if ($res->{date2} ne ' ') { + $res->{date2} =~ tr/ux/99/; + } + return $res; } __PACKAGE__->register_method( diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm index d497585caf..b8195f0bfb 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/config.pm @@ -118,6 +118,20 @@ __PACKAGE__->columns(Primary => 'code'); __PACKAGE__->columns(Essential => qw/value/); #------------------------------------------------------------------------------- +package config::i18n_locale; +use base qw/config/; +__PACKAGE__->table('config_i18n_locale'); +__PACKAGE__->columns(Primary => 'code'); +__PACKAGE__->columns(Essential => qw/marc_code name description/); +#------------------------------------------------------------------------------- + +package config::i18n_core; +use base qw/config/; +__PACKAGE__->table('config_i18n_core'); +__PACKAGE__->columns(Primary => 'id'); +__PACKAGE__->columns(Essential => qw/fq_field identity_value translation string/); +#------------------------------------------------------------------------------- + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/metabib.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/metabib.pm index 29577a4aba..bba4a400db 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/metabib.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/metabib.pm @@ -80,7 +80,7 @@ metabib::record_descriptor->table( 'metabib_rec_descriptor' ); metabib::record_descriptor->columns( Primary => qw/id/ ); metabib::record_descriptor->columns( Essential => qw/record item_type item_form bib_level control_type char_encoding enc_level lit_form vr_format - cat_form pub_status item_lang audience type_mat/ ); + cat_form pub_status item_lang audience type_mat date1 date2/ ); #------------------------------------------------------------------------------- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm index 058fc86a63..3bb16d944a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm @@ -672,6 +672,17 @@ #------------------------------------------------------------------------------- + package config::i18n_locale; + config::i18n_locale->table('config.i18n_locale'); + + #------------------------------------------------------------------------------- + + package config::i18n_core; + config::i18n_core->sequence( 'config.i18n_core_id_seq' ); + config::i18n_core->table('config.i18n_core'); + + #------------------------------------------------------------------------------- + package config::item_form_map; config::item_form_map->table('config.item_form_map'); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm index 859bd09174..b89e1f54ea 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm @@ -2328,12 +2328,47 @@ __PACKAGE__->register_method( cachable => 1, ); + +my %locale_map; +my $default_preferred_language; +my $default_preferred_language_weight; + # XXX factored most of the PG dependant stuff out of here... need to find a way to do "dependants". sub staged_fts { my $self = shift; my $client = shift; my %args = @_; - + + if (!$locale_map{COMPLETE}) { + + my @locales = config::i18n_locale->search_where({ code => { '<>' => '' } }); + for my $locale ( @locales ) { + $locale_map{$locale->code} = $locale->marc_code; + } + $locale_map{COMPLETE} = 1; + + } + + if (!$default_preferred_language) { + + $default_preferred_language = OpenSRF::Utils::SettingsClient + ->new + ->config_value( + apps => 'open-ils.storage' => app_settings => 'default_preferred_language' + ); + + } + + if (!$default_preferred_language_weight) { + + $default_preferred_language_weight = OpenSRF::Utils::SettingsClient + ->new + ->config_value( + apps => 'open-ils.storage' => app_settings => 'default_preferred_language_weight' + ); + + } + my $ou = $args{org_unit}; my $limit = $args{limit} || 10; my $offset = $args{offset} || 0; @@ -2346,7 +2381,16 @@ sub staged_fts { die "No search arguments were passed to ".$self->api_name; } - my (@statuses,@locations,@types,@forms,@lang,@aud,@lit_form,@vformats,@bib_level); + my (@between,@statuses,@locations,@types,@forms,@lang,@aud,@lit_form,@vformats,@bib_level); + + if (!defined($args{preferred_language})) { + $args{preferred_language} = + $locale_map{ $self->session->session_locale || $default_preferred_language } || 'eng'; + } + + if (!defined($args{preferred_language_weight})) { + $args{preferred_language_weight} = $default_preferred_language_weight || 2; + } if ($args{available}) { @statuses = (0,7,12); @@ -2357,6 +2401,12 @@ sub staged_fts { @locations = @$s; } + if (my $b = $args{between}) { + if (ref($b) && @$b == 2) { + @between = @$b; + } + } + if (my $s = $args{statuses}) { $s = [$s] if (!ref($s)); @statuses = @$s; @@ -2457,6 +2507,10 @@ sub staged_fts { my $param_forms = '$${' . join(',', map { s/\$//go; "\"$_\""} @forms) . '}$$'; my $param_vformats = '$${' . join(',', map { s/\$//go; "\"$_\"" } @vformats) . '}$$'; my $param_bib_level = '$${' . join(',', map { s/\$//go; "\"$_\"" } @bib_level) . '}$$'; + my $param_before = $args{before}; $param_before = 'NULL' unless (defined($param_before) and length($param_before) > 0 ); + my $param_after = $args{after}; $param_after = 'NULL' unless (defined($param_after) and length($param_after) > 0 ); + my $param_during = $args{during}; $param_during = 'NULL' unless (defined($param_during) and length($param_during) > 0 ); + my $param_between = '$${"' . join('","', map { int($_) } @between) . '"}$$'; my $param_pref_lang = $args{preferred_language}; $param_pref_lang =~ s/\$//go; $param_pref_lang = '$$'.$param_pref_lang.'$$'; my $param_pref_lang_multiplier = $args{preferred_language_weight}; $param_pref_lang_multiplier ||= 'NULL'; my $param_sort = $args{'sort'}; $param_sort =~ s/\$//go; $param_sort = '$$'.$param_sort.'$$'; @@ -2482,6 +2536,10 @@ sub staged_fts { $param_forms\:\:TEXT[], $param_vformats\:\:TEXT[], $param_bib_level\:\:TEXT[], + $param_before\:\:TEXT, + $param_after\:\:TEXT, + $param_during\:\:TEXT, + $param_between\:\:TEXT[], $param_pref_lang\:\:TEXT, $param_pref_lang_multiplier\:\:REAL, $param_sort\:\:TEXT, diff --git a/Open-ILS/src/sql/Pg/300.schema.staged_search.sql b/Open-ILS/src/sql/Pg/300.schema.staged_search.sql index b8498d873f..7506d792eb 100644 --- a/Open-ILS/src/sql/Pg/300.schema.staged_search.sql +++ b/Open-ILS/src/sql/Pg/300.schema.staged_search.sql @@ -57,6 +57,10 @@ CREATE OR REPLACE FUNCTION search.staged_fts ( param_forms TEXT[], param_vformats TEXT[], param_bib_level TEXT[], + param_before TEXT, + param_after TEXT, + param_during TEXT, + param_between TEXT[], param_pref_lang TEXT, param_pref_lang_multiplier REAL, param_sort TEXT, @@ -241,7 +245,7 @@ BEGIN current_rank := ' CASE WHEN mrd.item_lang = ' || quote_literal( param_pref_lang ) || ' THEN ' || param_pref_lang_multiplier || '::REAL ELSE 1.0 END '; - --ranks := array_append( ranks, current_rank ); + -- ranks := array_append( ranks, current_rank ); END IF; current_rank := ' AVG( ( (' || array_to_string( ranks, ') + (' ) || ') ) * ' || current_rank || ' ) '; @@ -254,16 +258,7 @@ BEGIN tmp_text := '999999'; IF param_sort_desc THEN tmp_text := '0'; END IF; - current_rank := $$ - ( COALESCE( FIRST (( - SELECT SUBSTRING(frp.value FROM E'\\d{4}') - FROM metabib.full_rec frp - WHERE frp.record = m.source - AND frp.tag = '260' - AND frp.subfield = 'c' - LIMIT 1 - )), $$ || quote_literal(tmp_text) || $$ )::INT ) - $$; + current_rank := $$ COALESCE( mrd.date1, $$ || quote_literal(tmp_text) || $$ )::INT ) $$; ELSIF param_sort = 'title' THEN @@ -337,6 +332,22 @@ BEGIN where_clause = where_clause || $$ AND mrd.bib_level IN ('$$ || array_to_string(param_bib_level, $$','$$) || $$') $$; END IF; + IF param_before IS NOT NULL AND param_before <> '' THEN + where_clause = where_clause || $$ AND mrd.date1 <= $$ || quote_literal(param_before) || ' '; + END IF; + + IF param_after IS NOT NULL AND param_after <> '' THEN + where_clause = where_clause || $$ AND mrd.date1 >= $$ || quote_literal(param_after) || ' '; + END IF; + + IF param_during IS NOT NULL AND param_during <> '' THEN + where_clause = where_clause || $$ AND $$ || quote_literal(param_during) || $$ BETWEEN mrd.date1 AND mrd.date2 $$; + END IF; + + IF param_between IS NOT NULL AND array_upper(param_between, 1) > 0 THEN + where_clause = where_clause || $$ AND mrd.date1 BETWEEN $$ || array_to_string(param_bib_level, $$' AND '$$) || ' '; + END IF; + core_rel_query := select_clause || from_clause || where_clause || ' GROUP BY 1 ORDER BY 4' || CASE WHEN sort_desc THEN ' DESC' ELSE ' ASC' END || ';'; --RAISE NOTICE 'Base Query: %', core_rel_query; @@ -546,15 +557,6 @@ BEGIN END; $func$ LANGUAGE PLPGSQL; -/* - param_statuses INT[], - param_audience TEXT[], x - param_language TEXT[], x - param_lit_form TEXT[], x - param_types TEXT[], x - param_forms TEXT[], x - param_vformats TEXT[], x -*/ CREATE OR REPLACE FUNCTION search.explode_array(anyarray) RETURNS SETOF anyelement AS $BODY$ SELECT ($1)[s] FROM generate_series(1, array_upper($1, 1)) AS s; -- 2.43.2