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;
17 use OpenILS::Application::Search::AddedContent;
19 use OpenILS::Application::AppUtils;
21 use Time::HiRes qw(time);
22 use OpenSRF::EX qw(:try);
24 use Text::Aspell; # spell checking...
27 # Houses generic search utilites
30 OpenILS::Application::Search::Z3950->initialize();
31 OpenILS::Application::Search::AddedContent->initialize();
35 my($self, $str, $full) = @_;
39 $string =~ s/\s+the\s+/ /oi;
40 $string =~ s/\s+an\s+/ /oi;
41 $string =~ s/\s+a\s+/ /oi;
43 $string =~ s/^the\s+//io;
44 $string =~ s/^an\s+//io;
45 $string =~ s/^a\s+//io;
47 $string =~ s/\s+the$//io;
48 $string =~ s/\s+an$//io;
49 $string =~ s/\s+a$//io;
51 $string =~ s/^the$//io;
52 $string =~ s/^an$//io;
57 if($string =~ /^\s*$/o) {
87 push @words, "united state";
89 for my $word (@words) {
90 if($string =~ /^\s*"?\s*$word\w*\s*"?\s*$/i) {
95 warn "Cleansed string to: $string\n";
96 if($string =~ /^\s*$/o) {
106 __PACKAGE__->register_method(
107 method => "check_spelling",
108 api_name => "open-ils.search.spell_check");
111 my( $self, $client, $phrase ) = @_;
113 my @resp_objects = ();
114 my $speller = Text::Aspell->new();
115 $speller->set_option('lang', 'en_US');
116 my $return_something = 0;
118 my $return_phrase = "";
120 for my $word (split(' ',$phrase) ) {
121 if( ! $speller->check($word) ) {
122 if( $speller->suggest($word) ) { $return_something = 1; }
123 # $return_something = 1;
125 $word_stuff->{'word'} = $word;
126 $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
127 if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
128 else { $return_phrase .= " " . ($speller->suggest($word))[0];}
131 if( ! $return_phrase ) { $return_phrase = $word; }
132 else { $return_phrase .= " $word"; }
136 if( $return_something ) { return $return_phrase; }