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