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;
12 use OpenILS::Application::Search::Biblio;
13 use OpenILS::Application::Search::Authority;
14 use OpenILS::Application::Search::Z3950;
15 use OpenILS::Application::Search::Zips;
18 use OpenILS::Application::AppUtils;
20 use Time::HiRes qw(time);
21 use OpenSRF::EX qw(:try);
25 # Houses generic search utilites
28 OpenILS::Application::Search::Z3950->initialize();
29 OpenILS::Application::Search::Zips->initialize();
31 # try to load the added content handler
32 my $conf = OpenSRF::Utils::SettingsClient->new;
33 my $implementation = $conf->config_value(
34 "apps", "open-ils.search","app_settings", "added_content", "implementation" );
36 $implementation = "OpenILS::Application::Search::AddedContent" unless $implementation;
38 $logger->debug("Attempting to load Added Content handler: $implementation");
40 eval "use $implementation";
43 $logger->error("Unable to load Added Content handler [$implementation]: $@");
47 eval { $implementation->initialize(); };
53 __PACKAGE__->register_method(
54 method => "check_spelling",
55 api_name => "open-ils.search.spell_check");
58 my( $self, $client, $phrase ) = @_;
60 my @resp_objects = ();
61 my $speller = Text::Aspell->new();
62 $speller->set_option('lang', 'en_US');
63 my $return_something = 0;
65 my $return_phrase = "";
67 for my $word (split(' ',$phrase) ) {
68 if( ! $speller->check($word) ) {
69 if( $speller->suggest($word) ) { $return_something = 1; }
71 $word_stuff->{'word'} = $word;
72 $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
73 if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
74 else { $return_phrase .= " " . ($speller->suggest($word))[0];}
77 if( ! $return_phrase ) { $return_phrase = $word; }
78 else { $return_phrase .= " $word"; }
82 if( $return_something ) { return $return_phrase; }
89 # ------------------------------------------------------------------
90 # Create custome dictionaries like so:
91 # aspell --lang=en create master ./oils_authority.dict < /tmp/words
92 # where /tmp/words is a space separated list of words
93 # ------------------------------------------------------------------
96 __PACKAGE__->register_method(
97 method => "spellcheck",
98 api_name => "open-ils.search.spellcheck");
100 my $speller = Text::Aspell->new();
103 my( $self, $client, $phrase ) = @_;
105 my $conf = OpenSRF::Utils::SettingsClient->new;
107 if( my $dict = $conf->config_value(
108 "apps", "open-ils.search", "app_settings", "spelling_dictionary")) {
109 $speller->set_option('master', $dict);
110 $logger->debug("spelling dictionary set to $dict");
114 return \@resp unless $phrase;
115 for my $word (split(/\s+/,$phrase) ) {
119 suggestions => ($speller->check($word)) ? undef : [$speller->suggest($word)]