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...
29 # Houses generic search utilites
32 OpenILS::Application::Search::Z3950->initialize();
33 OpenILS::Application::Search::Zips->initialize();
35 # try to load the added content handler
36 my $conf = OpenSRF::Utils::SettingsClient->new;
37 my $implementation = $conf->config_value(
38 "apps", "open-ils.search","app_settings", "added_content", "implementation" );
40 $implementation = "OpenILS::Application::Search::AddedContent" unless $implementation;
42 $logger->debug("Attempting to load Added Content handler: $implementation");
44 eval "use $implementation";
47 $logger->error("Unable to load Added Content handler [$implementation]: $@");
51 eval { $implementation->initialize(); };
55 my($self, $str, $full) = @_;
59 $string =~ s/\s+the\s+/ /oi;
60 $string =~ s/\s+an\s+/ /oi;
61 $string =~ s/\s+a\s+/ /oi;
63 $string =~ s/^the\s+//io;
64 $string =~ s/^an\s+//io;
65 $string =~ s/^a\s+//io;
67 $string =~ s/\s+the$//io;
68 $string =~ s/\s+an$//io;
69 $string =~ s/\s+a$//io;
71 $string =~ s/^the$//io;
72 $string =~ s/^an$//io;
77 if($string =~ /^\s*$/o) {
107 push @words, "united state";
109 for my $word (@words) {
110 if($string =~ /^\s*"?\s*$word\w*\s*"?\s*$/i) {
115 warn "Cleansed string to: $string\n";
116 if($string =~ /^\s*$/o) {
126 __PACKAGE__->register_method(
127 method => "check_spelling",
128 api_name => "open-ils.search.spell_check");
131 my( $self, $client, $phrase ) = @_;
133 my @resp_objects = ();
134 my $speller = Text::Aspell->new();
135 $speller->set_option('lang', 'en_US');
136 my $return_something = 0;
138 my $return_phrase = "";
140 for my $word (split(' ',$phrase) ) {
141 if( ! $speller->check($word) ) {
142 if( $speller->suggest($word) ) { $return_something = 1; }
143 # $return_something = 1;
145 $word_stuff->{'word'} = $word;
146 $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
147 if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
148 else { $return_phrase .= " " . ($speller->suggest($word))[0];}
151 if( ! $return_phrase ) { $return_phrase = $word; }
152 else { $return_phrase .= " $word"; }
156 if( $return_something ) { return $return_phrase; }