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::Biblio;
14 use OpenILS::Application::Search::Actor;
15 use OpenILS::Application::Search::Z3950;
17 use OpenILS::Application::AppUtils;
19 use Time::HiRes qw(time);
20 use OpenSRF::EX qw(:try);
22 use Text::Aspell; # spell checking...
25 # Houses generic search utilites
28 OpenILS::Application::Search::Z3950->initialize();
32 my($self, $str, $full) = @_;
36 $string =~ s/\s+the\s+/ /oi;
37 $string =~ s/\s+an\s+/ /oi;
38 $string =~ s/\s+a\s+/ /oi;
40 $string =~ s/^the\s+//io;
41 $string =~ s/^an\s+//io;
42 $string =~ s/^a\s+//io;
44 $string =~ s/\s+the$//io;
45 $string =~ s/\s+an$//io;
46 $string =~ s/\s+a$//io;
48 $string =~ s/^the$//io;
49 $string =~ s/^an$//io;
54 if($string =~ /^\s*$/o) {
84 push @words, "united state";
86 for my $word (@words) {
87 if($string =~ /^\s*"?\s*$word\w*\s*"?\s*$/i) {
92 warn "Cleansed string to: $string\n";
93 if($string =~ /^\s*$/o) {
103 __PACKAGE__->register_method(
104 method => "check_spelling",
105 api_name => "open-ils.search.spell_check");
108 my( $self, $client, $phrase ) = @_;
110 my @resp_objects = ();
111 my $speller = Text::Aspell->new();
112 $speller->set_option('lang', 'en_US');
113 my $return_something = 0;
115 my $return_phrase = "";
117 for my $word (split(' ',$phrase) ) {
118 if( ! $speller->check($word) ) {
119 if( $speller->suggest($word) ) { $return_something = 1; }
120 $return_something = 1;
122 $word_stuff->{'word'} = $word;
123 $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
124 if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
125 else { $return_phrase .= " " . ($speller->suggest($word))[0];}
128 if( ! $return_phrase ) { $return_phrase = $word; }
129 else { $return_phrase .= " $word"; }
133 if( $return_something ) { return $return_phrase; }