1 package OpenILS::Application::Search;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
5 use OpenSRF::Utils::Logger qw(:logger);
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Utils::ModsParser;
9 use OpenSRF::Utils::SettingsClient;
10 use OpenSRF::Utils::Cache;
13 #use OpenILS::Application::Search::StaffClient;
14 use OpenILS::Application::Search::Biblio;
15 use OpenILS::Application::Search::Authority;
16 #use OpenILS::Application::Search::Actor;
17 use OpenILS::Application::Search::Z3950;
18 use OpenILS::Application::Search::Zips;
21 use OpenILS::Application::AppUtils;
23 use Time::HiRes qw(time);
24 use OpenSRF::EX qw(:try);
26 use Text::Aspell; # spell checking...
28 # Houses generic search utilites
31 OpenILS::Application::Search::Z3950->initialize();
32 OpenILS::Application::Search::Zips->initialize();
34 # try to load the added content handler
35 my $conf = OpenSRF::Utils::SettingsClient->new;
36 my $implementation = $conf->config_value(
37 "apps", "open-ils.search","app_settings", "added_content", "implementation" );
39 $implementation = "OpenILS::Application::Search::AddedContent" unless $implementation;
41 $logger->debug("Attempting to load Added Content handler: $implementation");
43 eval "use $implementation";
46 $logger->error("Unable to load Added Content handler [$implementation]: $@");
50 eval { $implementation->initialize(); };
55 __PACKAGE__->register_method(
56 method => "check_spelling",
57 api_name => "open-ils.search.spell_check");
60 my( $self, $client, $phrase ) = @_;
62 my @resp_objects = ();
63 my $speller = Text::Aspell->new();
64 $speller->set_option('lang', 'en_US');
65 my $return_something = 0;
67 my $return_phrase = "";
69 for my $word (split(' ',$phrase) ) {
70 if( ! $speller->check($word) ) {
71 if( $speller->suggest($word) ) { $return_something = 1; }
73 $word_stuff->{'word'} = $word;
74 $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
75 if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
76 else { $return_phrase .= " " . ($speller->suggest($word))[0];}
79 if( ! $return_phrase ) { $return_phrase = $word; }
80 else { $return_phrase .= " $word"; }
84 if( $return_something ) { return $return_phrase; }
91 __PACKAGE__->register_method(
92 method => "spellcheck",
93 api_name => "open-ils.search.spellcheck");
95 my $speller = Text::Aspell->new();
96 $speller->set_option('lang', 'en_US'); # default
99 my( $self, $client, $phrase ) = @_;
101 return \@resp unless $phrase;
102 for my $word (split(/\s+/,$phrase) ) {
106 suggestions => ($speller->check($word)) ? undef : [$speller->suggest($word)]