]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search.pm
removing old 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         OpenILS::Application::Search::Biblio->initialize();
31 }
32         
33
34
35 # ------------------------------------------------------------------
36 # Create custome dictionaries like so:
37 # aspell --lang=en create  master ./oils_authority.dict < /tmp/words
38 # where /tmp/words is a space separated list of words
39 # ------------------------------------------------------------------
40
41 __PACKAGE__->register_method(
42         method  => "spellcheck",
43         api_name        => "open-ils.search.spellcheck");
44
45 my $speller = Text::Aspell->new();
46
47 sub spellcheck {
48         my( $self, $client, $phrase ) = @_;
49
50         my $conf = OpenSRF::Utils::SettingsClient->new;
51
52         if( my $dict = $conf->config_value(
53                         "apps", "open-ils.search", "app_settings", "spelling_dictionary")) {
54                 $speller->set_option('master', $dict);
55                 $logger->debug("spelling dictionary set to $dict");
56         }
57
58         my @resp;
59         return \@resp unless $phrase;
60         for my $word (split(/\s+/,$phrase) ) {
61                 push( @resp, 
62                         {
63                                 word => $word, 
64                                 suggestions => ($speller->check($word)) ? undef : [$speller->suggest($word)]
65                         } 
66                 ); 
67         }
68         return \@resp;
69 }
70
71
72
73 1;