1 package OpenILS::Application::Search;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenILS::Utils::ModsParser;
8 use OpenSRF::Utils::SettingsClient;
9 use OpenSRF::Utils::Cache;
12 #use OpenILS::Application::Search::StaffClient;
13 use OpenILS::Application::Search::Biblio;
14 use OpenILS::Application::Search::Actor;
15 use OpenILS::Application::Search::Z3950;
17 use OpenILS::Application::AppUtils;
19 use Time::HiRes qw(time);
20 use OpenSRF::EX qw(:try);
22 # Houses generic search utilites
25 OpenILS::Application::SearchCache->child_init();
29 my($self, $str, $full) = @_;
33 $string =~ s/\s+the\s+/ /oi;
34 $string =~ s/\s+an\s+/ /oi;
35 $string =~ s/\s+a\s+/ /oi;
37 $string =~ s/^the\s+//io;
38 $string =~ s/^an\s+//io;
39 $string =~ s/^a\s+//io;
41 $string =~ s/\s+the$//io;
42 $string =~ s/\s+an$//io;
43 $string =~ s/\s+a$//io;
45 $string =~ s/^the$//io;
46 $string =~ s/^an$//io;
51 if($string =~ /^\s*$/o) {
81 push @words, "united state";
83 for my $word (@words) {
84 if($string =~ /^\s*"?\s*$word\w*\s*"?\s*$/i) {
89 warn "Cleansed string to: $string\n";
90 if($string =~ /^\s*$/o) {
101 __PACKAGE__->register_method(
102 method => "get_org_sub_tree",
103 api_name => "open-ils.search.actor.org_subtree.retrieve",
105 note => "Returns the entire org tree structure",
108 sub get_sub_org_tree {
110 my( $self, $client, $user_session ) = @_;
113 throw OpenSRF::EX::InvalidArg
114 ("No User session provided to org_subtree.retrieve");
117 if( $user_session ) {
120 OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
123 my $session = OpenSRF::AppSession->create("open-ils.storage");
124 my $request = $session->request(
125 "open-ils.storage.direct.actor.org_unit.retrieve", $user_obj->home_ou );
126 my $response = $request->recv();
129 throw OpenSRF::EX::ERROR (
130 "No response from storage for org_unit retrieve");
132 if(UNIVERSAL::isa($response,"Error")) {
133 throw $response ($response->stringify);
136 my $home_ou = $response->content;
138 # XXX grab descendants and build org tree from them
140 my $request = $session->request(
141 "open-ils.storage.actor.org_unit_descendants" );
142 my $response = $request->recv();
144 throw OpenSRF::EX::ERROR (
145 "No response from storage for org_unit retrieve");
147 if(UNIVERSAL::isa($response,"Error")) {
148 throw $response ($response->stringify);
151 my $descendants = $response->content;
155 $session->disconnect();
171 package OpenILS::Application::SearchCache;
172 use strict; use warnings;
179 my $config_client = OpenSRF::Utils::SettingsClient->new();
180 my $memcache_servers =
181 $config_client->config_value(
182 "apps","open-ils.search", "app_settings","memcache" );
184 if( !$memcache_servers ) {
185 throw OpenSRF::EX::Config ("
186 No Memcache servers specified for open-ils.search!");
189 if(!ref($memcache_servers)) {
190 $memcache_servers = [$memcache_servers];
192 $cache_handle = OpenSRF::Utils::Cache->new( "open-ils.search", 0, $memcache_servers );
193 $max_timeout = $config_client->config_value(
194 "apps", "open-ils.search", "app_settings", "max_cache_time" );
196 if(ref($max_timeout) eq "ARRAY") {
197 $max_timeout = $max_timeout->[0];
202 sub new {return bless({},shift());}
205 my($self, $key, $data, $timeout) = @_;
206 return undef unless( $key and $data );
208 $timeout ||= $max_timeout;
209 $timeout = ($timeout <= $max_timeout) ? $timeout : $max_timeout;
211 warn "putting $key into cache for $timeout seconds\n";
212 $cache_handle->put_cache( "_open-ils.search_$key", JSON->perl2JSON($data), $timeout );
216 my( $self, $key ) = @_;
217 my $json = $cache_handle->get_cache("_open-ils.search_$key");
219 warn "retrieving from cache $key\n =>>> $json";
221 return JSON->JSON2perl($json);