Start of the complete rewrite of Search.pm
[koha.git] / C4 / Search.pm
1 package C4::Search;
2
3 # Copyright 2000-2006 Katipo Communications
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use ZOOM;
22 use Smart::Comments;
23 use C4::Context;
24
25 require Exporter;
26
27 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
28
29 # set the version for version checking
30 $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
31           shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
32
33 =head1 NAME
34
35 C4::Search - Functions for searching the Koha catalog and other databases
36
37 =head1 SYNOPSIS
38
39   use C4::Search;
40
41 =head1 DESCRIPTION
42
43 This module provides the searching facilities for the Koha catalog and
44 other databases.
45
46 =head1 FUNCTIONS
47
48 =over 2
49
50 =cut
51
52 @ISA = qw(Exporter);
53 @EXPORT = qw(search);
54 # make all your functions, whether exported or not;
55
56 sub search {
57     my ($search,$type)=@_;
58     my $q;
59     my $host=C4::Context->config("zebraserver");
60     my $port=C4::Context->config("zebraport");
61     my $intranetdir=C4::Context->config("intranetdir");
62     my $Zconn;
63     eval {
64         $Zconn = new ZOOM::Connection($host,$port);
65     };
66     if ($@) {
67         warn "Error ", $@->code(), ": ", $@->message(), "\n";                  
68     }
69     
70     if ($type eq 'CQL'){
71         my $string;
72         foreach my $var (keys %$search) {
73             $string.="$var=\"$search->{$var}\" ";
74         }           
75         $Zconn->option(cqlfile => "$intranetdir/zebra/pqf.properties");
76         $Zconn->option(preferredRecordSyntax => "xml");
77         $q = new ZOOM::Query::CQL2RPN( $string, $Zconn);        
78         }
79     eval {
80         my $rs = $Zconn->search($q);
81         my $n = $rs->size();
82         ###$rs->record(0)->render();
83     };
84     if ($@) {
85         print "Error ", $@->code(), ": ", $@->message(), "\n";
86     }   
87 }
88 1;
89 __END__
90
91 =back
92
93 =head1 AUTHOR
94
95 Koha Developement team <info@koha.org>
96
97 =cut