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::Web;
14 use OpenILS::Application::Search::Biblio;
15 use OpenILS::Application::Search::Actor;
16 use OpenILS::Application::Search::Z3950;
18 use OpenILS::Application::AppUtils;
20 use Time::HiRes qw(time);
21 use OpenSRF::EX qw(:try);
23 # Houses generic search utilites
26 OpenILS::Application::SearchCache->child_init();
30 my($self, $string) = @_;
32 $string =~ s/\s+the\s+//i;
33 $string =~ s/\s+an\s+//i;
34 $string =~ s/\s+a\s+//i;
36 $string =~ s/^the\s+//i;
37 $string =~ s/^an\s+//i;
38 $string =~ s/^a\s+//i;
40 $string =~ s/\s+the$//i;
41 $string =~ s/\s+an$//i;
42 $string =~ s/\s+a$//i;
44 $string =~ s/^the$//i;
48 warn "Cleansed string to: $string\n";
54 __PACKAGE__->register_method(
55 method => "get_org_sub_tree",
56 api_name => "open-ils.search.actor.org_subtree.retrieve",
58 note => "Returns the entire org tree structure",
61 sub get_sub_org_tree {
63 my( $self, $client, $user_session ) = @_;
66 throw OpenSRF::EX::InvalidArg
67 ("No User session provided to org_subtree.retrieve");
73 OpenILS::Application::AppUtils->check_user_session( $user_session ); #throws EX on error
76 my $session = OpenSRF::AppSession->create("open-ils.storage");
77 my $request = $session->request(
78 "open-ils.storage.direct.actor.org_unit.retrieve", $user_obj->home_ou );
79 my $response = $request->recv();
82 throw OpenSRF::EX::ERROR (
83 "No response from storage for org_unit retrieve");
85 if(UNIVERSAL::isa($response,"Error")) {
86 throw $response ($response->stringify);
89 my $home_ou = $response->content;
91 # XXX grab descendants and build org tree from them
93 my $request = $session->request(
94 "open-ils.storage.actor.org_unit_descendants" );
95 my $response = $request->recv();
97 throw OpenSRF::EX::ERROR (
98 "No response from storage for org_unit retrieve");
100 if(UNIVERSAL::isa($response,"Error")) {
101 throw $response ($response->stringify);
104 my $descendants = $response->content;
108 $session->disconnect();
124 package OpenILS::Application::SearchCache;
125 use strict; use warnings;
132 my $config_client = OpenSRF::Utils::SettingsClient->new();
133 my $memcache_servers =
134 $config_client->config_value(
135 "apps","open-ils.search", "app_settings","memcache" );
137 if( !$memcache_servers ) {
138 throw OpenSRF::EX::Config ("
139 No Memcache servers specified for open-ils.search!");
142 if(!ref($memcache_servers)) {
143 $memcache_servers = [$memcache_servers];
145 $cache_handle = OpenSRF::Utils::Cache->new( "open-ils.search", 0, $memcache_servers );
146 $max_timeout = $config_client->config_value(
147 "apps", "open-ils.search", "app_settings", "max_cache_time" );
149 if(ref($max_timeout) eq "ARRAY") {
150 $max_timeout = $max_timeout->[0];
155 sub new {return bless({},shift());}
158 my($self, $key, $data, $timeout) = @_;
159 return undef unless( $key and $data );
161 $timeout ||= $max_timeout;
162 $timeout = ($timeout <= $max_timeout) ? $timeout : $max_timeout;
164 warn "putting $key into cache for $timeout seconds\n";
165 $cache_handle->put_cache( "_open-ils.search_$key", JSON->perl2JSON($data), $timeout );
169 my( $self, $key ) = @_;
170 my $json = $cache_handle->get_cache("_open-ils.search_$key");
172 warn "retrieving from cache $key\n =>>> $json";
174 return JSON->JSON2perl($json);