Bug 17600: Standardize our EXPORT_OK
[srvgit] / Koha / SearchEngine / Zebra / Search.pm
1 package Koha::SearchEngine::Zebra::Search;
2
3 # This file is part of Koha.
4 #
5 # Copyright 2012 BibLibre
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use base qw(Class::Accessor);
23
24 use C4::Search qw( getRecords ); # :(
25 use C4::AuthoritiesMarc;
26 use Koha::SearchEngine::Search;
27
28 =head1 NAME
29
30 Koha::SearchEngine::Zebra::Search - Search implementation for Zebra
31
32 =head1 METHODS
33
34 =head2 search
35
36 =cut
37
38 sub search {
39     my ($self,$query_string) = @_;
40
41      my $query = Data::SearchEngine::Query->new(
42        count => 10,
43        page => 1,
44        query => $query_string,
45      );
46
47     my $results = $self->searchengine->search($query);
48
49     foreach my $item (@{ $results->items }) {
50         my $title = $item->get_value('ste_title');
51         #utf8::encode($title);
52         print "$title\n";
53     }
54 }
55
56 =head2 search_compat
57
58 This passes straight through to C4::Search::getRecords.
59
60 =cut
61
62 sub search_compat {
63     shift; # get rid of $self
64
65     return C4::Search::getRecords(@_);
66 }
67
68 =head2 simple_search_compat
69
70 This passes straight through to C4::Search::SimpleSearch.
71
72 =cut
73
74
75 sub simple_search_compat {
76     shift;
77     return C4::Search::SimpleSearch(@_);
78 }
79
80 =head2 extract_biblionumber
81
82     my $biblionumber = $searcher->extract_biblionumber( $searchresult );
83
84 $searchresult comes from simple_search_compat.
85
86 Returns the biblionumber from the search result record.
87
88 =cut
89
90 sub extract_biblionumber {
91     my ( $self, $searchresultrecord ) = @_;
92     my $record = C4::Search::new_record_from_zebra( 'biblioserver', $searchresultrecord );
93     return Koha::SearchEngine::Search::extract_biblionumber( $record );
94 }
95
96 =head2 search_auth_compat
97
98 This passes the search query on to C4::AuthoritiesMarc::SearchAuthorities
99
100 =cut
101
102 sub search_auth_compat {
103     my ( $self, $q, $startfrom, $resperpage, $skipmetadata ) = @_;
104
105     my @params = (
106         @{$q}{ 'marclist', 'and_or', 'excluding', 'operator', 'value' },
107         $startfrom - 1,
108         $resperpage, @{$q}{ 'authtypecode', 'orderby' }, $skipmetadata
109     );
110     C4::AuthoritiesMarc::SearchAuthorities(@params);
111 }
112
113 =head2 max_result_window
114
115 Returns the maximum number of results that can be fetched
116
117 Zebra does not have such a limit, so it always returns undef
118
119 =cut
120
121 sub max_result_window { undef }
122
123 1;