@@ -, +, @@ --- C4/Context.pm | 43 ++++++++++++++++++++ installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 8 ++++ .../en/modules/admin/preferences/searching.pref | 7 +++ 4 files changed, 59 insertions(+), 0 deletions(-) --- a/C4/Context.pm +++ a/C4/Context.pm @@ -105,6 +105,7 @@ use C4::Boolean; use C4::Debug; use POSIX (); use DateTime::TimeZone; +use Module::Load::Conditional qw(can_load); =head1 NAME @@ -941,6 +942,48 @@ sub restore_dbh # return something, then this function should, too. } +=head2 queryparser + + $queryparser = C4::Context->queryparser + +Returns a handle to an initialized Koha::QueryParser::Driver::PQF object. + +=cut + +sub queryparser { + my $self = shift; + unless (defined $context->{"queryparser"}) { + $context->{"queryparser"} = &_new_queryparser(); + } + + return $context->{"queryparser"}; +} + +=head2 _new_queryparser + +Internal helper function to create a new QueryParser object. QueryParser +is loaded dynamically so as to keep the lack of the QueryParser library from +getting in anyone's way. + +=cut + +sub _new_queryparser { + my $qpmodules = { + 'OpenILS::QueryParser' => undef, + 'Koha::QueryParser::Driver::PQF' => undef + }; + if ( can_load( 'modules' => $qpmodules ) ) { + my $QParser = Koha::QueryParser::Driver::PQF->new(); + my $config_file = $context->config('queryparser_config'); + $config_file ||= '/etc/koha/searchengine/queryparser.yaml'; + if ( $QParser->load_config($config_file) ) { + # TODO: allow indexes to be configured in the database + return $QParser; + } + } + return; +} + =head2 marcfromkohafield $dbh = C4::Context->marcfromkohafield; --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -408,3 +408,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('NotesBlacklist','','List of notes fields that should not appear in the title notes/description separator of details',NULL,'free'); INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserCSS', '', NULL, 'Add CSS to be included in the SCO module in an embedded