Bug 8726: ExplodedTerms suggestion plugin (functionality)
[koha.git] / Koha / SuggestionEngine / Base.pm
1 package Koha::SuggestionEngine::Base;
2
3 # Copyright 2012 C & P Bibliography Services
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 =head1 NAME
21
22 Koha::SuggestionEngine::Base - Base class for SuggestionEngine plugins
23
24 =head1 SYNOPSIS
25
26   use base qw(Koha::SuggestionEngine::Base);
27
28 =head1 DESCRIPTION
29
30 Base class for suggestion engine plugins. SuggestionEngines must
31 provide the following methods:
32
33 B<get_suggestions (\%param)> - get suggestions for the search described
34 in $param->{'search'}, and return them in a hashref with the suggestions
35 as keys and relevance as values.
36
37 The following variables must be defined in each filter:
38   our $NAME ='Filter';
39   our $VERSION = '1.0';
40
41 These methods may be overriden:
42
43 B<initialize (%params)> - initialize the plugin
44
45 B<destroy ()> - destroy the plugin
46
47 These methods should not be overridden unless you are very sure of what
48 you are doing:
49
50 B<new ()> - create a new plugin object
51
52 =head1 FUNCTIONS
53
54 =cut
55
56 use strict;
57 use warnings;
58
59 use base qw(Class::Accessor);
60
61 __PACKAGE__->mk_ro_accessors(qw( name version ));
62 __PACKAGE__->mk_accessors(qw( params ));
63
64 =head2 new
65
66     my $plugin = Koha::SuggestionEngine::Base->new;
67
68 Create a new filter;
69
70 =cut
71
72 sub new {
73     my $class = shift;
74
75     my $self = $class->SUPER::new( {} );    #name => $class->NAME,
76                                             #version => $class->VERSION });
77
78     bless $self, $class;
79     return $self;
80 }
81
82 =head2 initialize
83
84     $plugin->initalize(%params);
85
86 Initialize a filter using the specified parameters.
87
88 =cut
89
90 sub initialize {
91     my $self   = shift;
92     my $params = shift;
93
94     #$self->params = $params;
95
96     return $self;
97 }
98
99 =head2 destroy
100
101     $plugin->destroy();
102
103 Destroy the filter.
104
105 =cut
106
107 sub destroy {
108     my $self = shift;
109     return;
110 }
111
112 =head2 get_suggestions
113
114     my $suggestions = $plugin->get_suggestions(\%param);
115
116 Return suggestions for the specified search.
117
118 =cut
119
120 sub get_suggestions {
121     my $self  = shift;
122     my $param = shift;
123     return;
124 }
125
126 =head2 NAME
127
128     my $name = $plugin->NAME;
129
130 Getter function for plugin names.
131
132 =cut
133
134 sub NAME {
135     my $self = shift;
136     my $package = ref $self || $self;
137     return eval '$' . $package . '::NAME';
138 }
139
140 =head2 VERSION
141
142     my $version = $plugin->VERSION;
143
144 Getter function for plugin versions.
145
146 =cut
147
148 sub VERSION {
149     my $self = shift;
150     my $package = ref $self || $self;
151     return eval '$' . $package . '::VERSION';
152 }
153
154 =head2 DESCRIPTION
155
156     my $description = $plugin->DESCRIPTION;
157
158 Getter function for plugin descriptions.
159
160 =cut
161
162 sub DESCRIPTION {
163     my $self = shift;
164     my $package = ref $self || $self;
165     return eval '$' . $package . '::DESCRIPTION';
166 }
167
168 1;