]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search.pm
removing some unused code
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search.pm
1 package OpenILS::Application::Search;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4 use JSON;
5 use OpenSRF::Utils::Logger qw(:logger);
6
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Utils::ModsParser;
9 use OpenSRF::Utils::SettingsClient;
10 use OpenSRF::Utils::Cache;
11
12 use OpenILS::Application::Search::Biblio;
13 use OpenILS::Application::Search::Authority;
14 use OpenILS::Application::Search::Z3950;
15 use OpenILS::Application::Search::Zips;
16
17
18 use OpenILS::Application::AppUtils;
19
20 use Time::HiRes qw(time);
21 use OpenSRF::EX qw(:try);
22
23 use Text::Aspell; 
24
25 # Houses generic search utilites 
26
27 sub initialize {
28         OpenILS::Application::Search::Z3950->initialize();
29         OpenILS::Application::Search::Zips->initialize();
30
31         # try to load the added content handler
32         my $conf = OpenSRF::Utils::SettingsClient->new;
33         my $implementation = $conf->config_value(                                       
34                 "apps", "open-ils.search","app_settings", "added_content", "implementation" );
35
36         $implementation = "OpenILS::Application::Search::AddedContent" unless $implementation;
37
38         $logger->debug("Attempting to load Added Content handler: $implementation");
39
40         eval "use $implementation";
41
42         if($@) {        
43                 $logger->error("Unable to load Added Content handler [$implementation]: $@"); 
44                 return; 
45         }
46
47         eval { $implementation->initialize(); };
48 }
49         
50
51
52 =head deprecated
53 __PACKAGE__->register_method(
54         method  => "check_spelling",
55         api_name        => "open-ils.search.spell_check");
56
57 sub check_spelling {
58         my( $self, $client, $phrase ) = @_;
59
60         my @resp_objects = ();
61         my $speller = Text::Aspell->new();
62         $speller->set_option('lang', 'en_US');
63         my $return_something = 0;
64
65         my $return_phrase = "";
66
67         for my $word (split(' ',$phrase) ) {
68                 if( ! $speller->check($word) ) {
69                         if( $speller->suggest($word) ) { $return_something = 1; }
70                         my $word_stuff = {};
71                         $word_stuff->{'word'} = $word;
72                         $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
73                         if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
74                         else { $return_phrase .= " " . ($speller->suggest($word))[0];}
75                         
76                 } else { 
77                         if( ! $return_phrase ) { $return_phrase = $word; }
78                         else { $return_phrase .= " $word"; }
79                 }
80         }
81
82         if( $return_something ) { return $return_phrase; }
83         return 0;
84 }
85 =cut
86
87
88
89 # ------------------------------------------------------------------
90 # Create custome dictionaries like so:
91 # aspell --lang=en create  master ./oils_authority.dict < /tmp/words
92 # where /tmp/words is a space separated list of words
93 # ------------------------------------------------------------------
94
95
96 __PACKAGE__->register_method(
97         method  => "spellcheck",
98         api_name        => "open-ils.search.spellcheck");
99
100 my $speller = Text::Aspell->new();
101
102 sub spellcheck {
103         my( $self, $client, $phrase ) = @_;
104
105         my $conf = OpenSRF::Utils::SettingsClient->new;
106
107         if( my $dict = $conf->config_value(
108                         "apps", "open-ils.search", "app_settings", "spelling_dictionary")) {
109                 $speller->set_option('master', $dict);
110                 $logger->debug("spelling dictionary set to $dict");
111         }
112
113         my @resp;
114         return \@resp unless $phrase;
115         for my $word (split(/\s+/,$phrase) ) {
116                 push( @resp, 
117                         {
118                                 word => $word, 
119                                 suggestions => ($speller->check($word)) ? undef : [$speller->suggest($word)]
120                         } 
121                 ); 
122         }
123         return \@resp;
124 }
125
126
127
128 1;