(chris, read carefully)
[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 use MARC::Record;
25 use MARC::File::XML;
26 use C4::Biblio;
27
28 require Exporter;
29
30 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31
32 # set the version for version checking
33 $VERSION = do { my @v = '$Revision$' =~ /\d+/g;
34           shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
35
36 =head1 NAME
37
38 C4::Search - Functions for searching the Koha catalog and other databases
39
40 =head1 SYNOPSIS
41
42   use C4::Search;
43
44 =head1 DESCRIPTION
45
46 This module provides the searching facilities for the Koha catalog and
47 other databases.
48
49 =head1 FUNCTIONS
50
51 =over 2
52
53 =cut
54
55 @ISA = qw(Exporter);
56 @EXPORT = qw(search);
57 # make all your functions, whether exported or not;
58
59 sub search {
60     my ($search,$type)=@_;
61     my $dbh=C4::Context->dbh();
62     my $q;
63     my $Zconn;
64     my $raw;
65     eval {
66         $Zconn = new ZOOM::Connection(C4::Context->config("zebradb"));
67     };
68     if ($@) {
69         warn "Error ", $@->code(), ": ", $@->message(), "\n";                  
70     }
71     
72     if ($type eq 'CQL'){
73         my $string;
74         foreach my $var (keys %$search) {
75             $string.="$var=\"$search->{$var}\" ";
76         }           
77         $Zconn->option(cqlfile => C4::Context->config("intranetdir")."/zebra/pqf.properties");
78         $Zconn->option(preferredRecordSyntax => "usmarc");
79         $q = new ZOOM::Query::CQL2RPN( $string, $Zconn);        
80         }
81     eval {
82         my $rs = $Zconn->search($q);
83         my $n = $rs->size();
84         if ($n >0){
85             $raw=$rs->record(0)->raw();
86         }
87 #       print "here is $n";
88 #       $raw=$rs->record(0)->raw();
89         print $raw;
90
91
92     };
93     if ($@) {
94         print "Error ", $@->code(), ": ", $@->message(), "\n";
95     }   
96     my $record = MARC::Record->new_from_usmarc($raw);
97     ### $record                                                                                                    
98     # transform it into a meaningul hash                                                                       
99     my $line = MARCmarc2koha($dbh,$record);                                                                    
100     ### $line                                                                                                      
101     my $biblionumber=$line->{biblionumber};                                                                    
102     my $title=$line->{title};                                                                                  
103
104
105 }
106 1;
107 __END__
108
109 =back
110
111 =head1 AUTHOR
112
113 Koha Developement team <info@koha.org>
114
115 =cut