From: Fredric T Parks Date: Thu, 13 Feb 2014 00:04:28 +0000 (-0800) Subject: Boolean Search forign translation functionality X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5077b6748f3a6fdc3122634c38e8aa4173c574f7;p=working%2FEvergreen.git Boolean Search forign translation functionality sql scripts should be run in the following order: XXXX.schema.boolean_keyword_table.sql XXXX.function.retrieve_keywords_by_locale.sql XXXX.data.seed_boolean_keyword_table.sql Signed-off-by: Fredric T Parks modified: Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm modified: Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm new file: Open-ILS/src/sql/Pg/upgrade/XXXX.data.seed_boolean_keyword_table.sql new file: Open-ILS/src/sql/Pg/upgrade/XXXX.function.retrieve_keywords_by_locale.sql new file: Open-ILS/src/sql/Pg/upgrade/XXXX.schema.boolean_keyword_table.sql --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm index 1089cae3ad..0e482cb148 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm @@ -7,6 +7,7 @@ use OpenILS::Utils::Fieldmapper; use OpenSRF::Utils::Logger qw/:level/; use OpenSRF::Utils::Cache; use OpenSRF::Utils::JSON; +use OpenILS::Utils::CStoreEditor qw/:funcs/; use Data::Dumper; use Digest::MD5 qw/md5_hex/; @@ -3206,10 +3207,12 @@ sub query_parser_fts_wrapper { #If this is a boolean search set the human readable operators #XXX hard coded to just use english for now. Needs to be able to take forign keywords - if($args{"_boolean"} == "true") { - $parser->operator("and", " and "); - $parser->operator("or", " or "); - $parser->operator("disallowed", " not "); + if(exists $args{"_boolean"}) { + $operators = retreave_boolean_keywords($args{"_boolean"}); + + foreach my $op (keys %{$operators}){ + $parser->operator($op, $operators->{$op}); + } } if (! scalar( keys %{$args{searches}} )) { @@ -3325,6 +3328,40 @@ __PACKAGE__->register_method( cachable => 1, ); +sub retreave_boolean_keywords { + my $cache = OpenSRF::Utils::Cache->new; + my $locale = shift; + my $operators; + + #Reformat locale abreveation [en_us -> en-US] + $locale =~ s/(\w\w)_(\w\w)/$1\-\U$2\E/g; + + #Check cache for localization valuse for the current locale + $operators = $cache->get_cache("boolsearchlocale.${locale}"); + + #unless there is a cached set of values load from disk and add to cache + unless (defined($operators)){ + #there are no operators in the cache so load from the DB + $operators = {}; + my $editor = new_editor; + my $results = $editor->json_query({from => ["config.retrieve_keywords_by_locale", $locale]}); + + foreach my $result (@{$results}){ + $operators->{$result->{operator}} = $result->{keyword}; + } + + $cache->put_cache("boolsearchlocale.${locale}", $operators); + } + + #if operators is still empty default to basic english keywords + if (!defined($operators)){ + $operators->{"and"} = " and "; + $operators->{"or"} = " or "; + $operators->{"disallowed"} = " not "; + } + + return $operators; +} 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index 2a8dfd1391..c19e570892 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -400,7 +400,7 @@ sub load_rresults { #if this is a boolean search add flag so operators can be set later if($cgi->param("_boolean")) { - $args->{"_boolean"} = "true"; + $args->{"_boolean"} = $ctx->{locale}; } if ($tag_circs) { diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.seed_boolean_keyword_table.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.seed_boolean_keyword_table.sql new file mode 100644 index 0000000000..17af847132 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.seed_boolean_keyword_table.sql @@ -0,0 +1,7 @@ +INSERT INTO config.boolean_keyword (translation, operator, keyword) + VALUES ( 'en-US', 'and', ' and '), + ( 'en-US', 'or', ' or '), + ( 'en-US', 'disallowed', ' not '), + ( 'fr-CA', 'and', ' et '), + ( 'fr-CA', 'or', ' ou '), + ( 'fr-CA', 'disallowed', ' pas '); diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.retrieve_keywords_by_locale.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.retrieve_keywords_by_locale.sql new file mode 100644 index 0000000000..36df9a3710 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.retrieve_keywords_by_locale.sql @@ -0,0 +1,11 @@ +CREATE OR REPLACE FUNCTION config.retrieve_keywords_by_locale(locale text) + RETURNS TABLE( operator text, keyword text ) AS +$BODY$ +BEGIN + + RETURN QUERY + SELECT bk.operator, bk.keyword FROM config.boolean_keyword bk WHERE translation = locale; + RETURN; +END; +$BODY$ +LANGUAGE plpgsql; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.boolean_keyword_table.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.boolean_keyword_table.sql new file mode 100644 index 0000000000..479cf9361a --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.boolean_keyword_table.sql @@ -0,0 +1,18 @@ +-- DROP TABLE config.boolean_keyword; + +CREATE TABLE config.boolean_keyword +( + id serial NOT NULL, + translation text, + operator text, + keyword text, + CONSTRAINT boolean_keyword_pk PRIMARY KEY (id), + CONSTRAINT boolean_keyword_fk FOREIGN KEY (translation) + REFERENCES config.i18n_locale (code) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +) +WITH ( + OIDS=FALSE +); +ALTER TABLE config.boolean_keyword + OWNER TO evergreen;