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