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::Authority;
15 use OpenILS::Application::Search::Actor;
16 use OpenILS::Application::Search::Z3950;
18 use OpenILS::Application::AppUtils;
20 use Time::HiRes qw(time);
21 use OpenSRF::EX qw(:try);
23 use Text::Aspell; # spell checking...
26 # Houses generic search utilites
29 OpenILS::Application::Search::Z3950->initialize();
33 my($self, $str, $full) = @_;
37 $string =~ s/\s+the\s+/ /oi;
38 $string =~ s/\s+an\s+/ /oi;
39 $string =~ s/\s+a\s+/ /oi;
41 $string =~ s/^the\s+//io;
42 $string =~ s/^an\s+//io;
43 $string =~ s/^a\s+//io;
45 $string =~ s/\s+the$//io;
46 $string =~ s/\s+an$//io;
47 $string =~ s/\s+a$//io;
49 $string =~ s/^the$//io;
50 $string =~ s/^an$//io;
55 if($string =~ /^\s*$/o) {
85 push @words, "united state";
87 for my $word (@words) {
88 if($string =~ /^\s*"?\s*$word\w*\s*"?\s*$/i) {
93 warn "Cleansed string to: $string\n";
94 if($string =~ /^\s*$/o) {
104 __PACKAGE__->register_method(
105 method => "check_spelling",
106 api_name => "open-ils.search.spell_check");
109 my( $self, $client, $phrase ) = @_;
111 my @resp_objects = ();
112 my $speller = Text::Aspell->new();
113 $speller->set_option('lang', 'en_US');
114 my $return_something = 0;
116 my $return_phrase = "";
118 for my $word (split(' ',$phrase) ) {
119 if( ! $speller->check($word) ) {
120 if( $speller->suggest($word) ) { $return_something = 1; }
121 # $return_something = 1;
123 $word_stuff->{'word'} = $word;
124 $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
125 if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
126 else { $return_phrase .= " " . ($speller->suggest($word))[0];}
129 if( ! $return_phrase ) { $return_phrase = $word; }
130 else { $return_phrase .= " $word"; }
134 if( $return_something ) { return $return_phrase; }