Work in progress still, committing for testing
[koha-ffzg.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 $host=C4::Context->config("zebraserver");
64     my $port=C4::Context->config("zebraport");
65     my $intranetdir=C4::Context->config("intranetdir");
66     my $database="koha3";
67     my $Zconn;
68     my $raw;
69     eval {
70         $Zconn = new ZOOM::Connection("$host:$port/$database");
71     };
72     if ($@) {
73         warn "Error ", $@->code(), ": ", $@->message(), "\n";                  
74     }
75     
76     if ($type eq 'CQL'){
77         my $string;
78         foreach my $var (keys %$search) {
79             $string.="$var=\"$search->{$var}\" ";
80         }           
81         $Zconn->option(cqlfile => "$intranetdir/zebra/pqf.properties");
82         $Zconn->option(preferredRecordSyntax => "usmarc");
83         $q = new ZOOM::Query::CQL2RPN( $string, $Zconn);        
84         }
85     eval {
86         my $rs = $Zconn->search($q);
87         my $n = $rs->size();
88         if ($n >0){
89             $raw=$rs->record(0)->raw();
90         }
91 #       print "here is $n";
92 #       $raw=$rs->record(0)->raw();
93         print $raw;
94
95
96     };
97     if ($@) {
98         print "Error ", $@->code(), ": ", $@->message(), "\n";
99     }   
100     my $record = MARC::Record->new_from_usmarc($raw);
101     ### $record                                                                                                    
102     # transform it into a meaningul hash                                                                       
103     my $line = MARCmarc2koha($dbh,$record);                                                                    
104     ### $line                                                                                                      
105     my $biblionumber=$line->{biblionumber};                                                                    
106     my $title=$line->{title};                                                                                  
107
108
109 }
110 1;
111 __END__
112
113 =back
114
115 =head1 AUTHOR
116
117 Koha Developement team <info@koha.org>
118
119 =cut