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/;
#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}} )) {
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;
--- /dev/null
+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 ');
--- /dev/null
+-- 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;