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();
30 OpenILS::Application::Search::Biblio->initialize();
32 # try to load the added content handler
33 my $conf = OpenSRF::Utils::SettingsClient->new;
34 my $implementation = $conf->config_value(
35 "apps", "open-ils.search","app_settings", "added_content", "implementation" );
37 $implementation = "OpenILS::Application::Search::AddedContent" unless $implementation;
39 $logger->debug("Attempting to load Added Content handler: $implementation");
41 eval "use $implementation";
44 $logger->error("Unable to load Added Content handler [$implementation]: $@");
48 eval { $implementation->initialize(); };
54 __PACKAGE__->register_method(
55 method => "check_spelling",
56 api_name => "open-ils.search.spell_check");
59 my( $self, $client, $phrase ) = @_;
61 my @resp_objects = ();
62 my $speller = Text::Aspell->new();
63 $speller->set_option('lang', 'en_US');
64 my $return_something = 0;
66 my $return_phrase = "";
68 for my $word (split(' ',$phrase) ) {
69 if( ! $speller->check($word) ) {
70 if( $speller->suggest($word) ) { $return_something = 1; }
72 $word_stuff->{'word'} = $word;
73 $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
74 if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
75 else { $return_phrase .= " " . ($speller->suggest($word))[0];}
78 if( ! $return_phrase ) { $return_phrase = $word; }
79 else { $return_phrase .= " $word"; }
83 if( $return_something ) { return $return_phrase; }
90 # ------------------------------------------------------------------
91 # Create custome dictionaries like so:
92 # aspell --lang=en create master ./oils_authority.dict < /tmp/words
93 # where /tmp/words is a space separated list of words
94 # ------------------------------------------------------------------
97 __PACKAGE__->register_method(
98 method => "spellcheck",
99 api_name => "open-ils.search.spellcheck");
101 my $speller = Text::Aspell->new();
104 my( $self, $client, $phrase ) = @_;
106 my $conf = OpenSRF::Utils::SettingsClient->new;
108 if( my $dict = $conf->config_value(
109 "apps", "open-ils.search", "app_settings", "spelling_dictionary")) {
110 $speller->set_option('master', $dict);
111 $logger->debug("spelling dictionary set to $dict");
115 return \@resp unless $phrase;
116 for my $word (split(/\s+/,$phrase) ) {
120 suggestions => ($speller->check($word)) ? undef : [$speller->suggest($word)]