]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search.pm
moved to server side caching of opac search results - sped up the details page by...
[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         # try to load the added content handler
33         my $conf = OpenSRF::Utils::SettingsClient->new;
34         my $implementation = $conf->config_value(                                       
35                 "apps", "open-ils.search","app_settings", "added_content", "implementation" );
36
37         $implementation = "OpenILS::Application::Search::AddedContent" unless $implementation;
38
39         $logger->debug("Attempting to load Added Content handler: $implementation");
40
41         eval "use $implementation";
42
43         if($@) {        
44                 $logger->error("Unable to load Added Content handler [$implementation]: $@"); 
45                 return; 
46         }
47
48         eval { $implementation->initialize(); };
49 }
50         
51
52
53 =head deprecated
54 __PACKAGE__->register_method(
55         method  => "check_spelling",
56         api_name        => "open-ils.search.spell_check");
57
58 sub check_spelling {
59         my( $self, $client, $phrase ) = @_;
60
61         my @resp_objects = ();
62         my $speller = Text::Aspell->new();
63         $speller->set_option('lang', 'en_US');
64         my $return_something = 0;
65
66         my $return_phrase = "";
67
68         for my $word (split(' ',$phrase) ) {
69                 if( ! $speller->check($word) ) {
70                         if( $speller->suggest($word) ) { $return_something = 1; }
71                         my $word_stuff = {};
72                         $word_stuff->{'word'} = $word;
73                         $word_stuff->{'suggestions'} = [ $speller->suggest( $word ) ];
74                         if( ! $return_phrase ) { $return_phrase = ($speller->suggest($word))[0]; }
75                         else { $return_phrase .= " " . ($speller->suggest($word))[0];}
76                         
77                 } else { 
78                         if( ! $return_phrase ) { $return_phrase = $word; }
79                         else { $return_phrase .= " $word"; }
80                 }
81         }
82
83         if( $return_something ) { return $return_phrase; }
84         return 0;
85 }
86 =cut
87
88
89
90 # ------------------------------------------------------------------
91 # Create custome dictionaries like so:
92 # aspell --lang=en create  master ./oils_authority.dict < /tmp/words
93 # where /tmp/words is a space separated list of words
94 # ------------------------------------------------------------------
95
96
97 __PACKAGE__->register_method(
98         method  => "spellcheck",
99         api_name        => "open-ils.search.spellcheck");
100
101 my $speller = Text::Aspell->new();
102
103 sub spellcheck {
104         my( $self, $client, $phrase ) = @_;
105
106         my $conf = OpenSRF::Utils::SettingsClient->new;
107
108         if( my $dict = $conf->config_value(
109                         "apps", "open-ils.search", "app_settings", "spelling_dictionary")) {
110                 $speller->set_option('master', $dict);
111                 $logger->debug("spelling dictionary set to $dict");
112         }
113
114         my @resp;
115         return \@resp unless $phrase;
116         for my $word (split(/\s+/,$phrase) ) {
117                 push( @resp, 
118                         {
119                                 word => $word, 
120                                 suggestions => ($speller->check($word)) ? undef : [$speller->suggest($word)]
121                         } 
122                 ); 
123         }
124         return \@resp;
125 }
126
127
128
129 1;