koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha C4/Search.pm ./search-test.pl koha-tmpl/op...


From: Chris Cormack
Subject: [Koha-cvs] koha C4/Search.pm ./search-test.pl koha-tmpl/op...
Date: Thu, 16 Feb 2006 20:51:07 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         
Changes by:     Chris Cormack <address@hidden>  06/02/16 20:51:07

Modified files:
        C4             : Search.pm 
Added files:
        .              : search-test.pl 
        koha-tmpl/opac-tmpl/npl/en: search-test.tmpl 

Log message:
        Little test set up that lets you type cql in which is passed to zebra
        install search-test.pl on your opac (or the intranet, if intranet youll 
need to put the tmpl file in the intranet too)
        
        NOT FOR PRODUCTION, purely for testing

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/koha/C4/Search.pm.diff?tr1=1.113&tr2=1.114&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/koha/koha/search-test.pl?rev=1.1
http://cvs.savannah.gnu.org/viewcvs/koha/koha/koha-tmpl/opac-tmpl/npl/en/search-test.tmpl?rev=1.1

Patches:
Index: koha/C4/Search.pm
diff -u koha/C4/Search.pm:1.113 koha/C4/Search.pm:1.114
--- koha/C4/Search.pm:1.113     Tue Feb 14 22:56:41 2006
+++ koha/C4/Search.pm   Thu Feb 16 20:51:07 2006
@@ -30,8 +30,9 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.113 $' =~ /\d+/g;
-          shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
+$VERSION = do { my @v = '$Revision: 1.114 $' =~ /\d+/g;
+    shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
+};
 
 =head1 NAME
 
@@ -52,53 +53,94 @@
 
 =cut
 
address@hidden = qw(Exporter);
address@hidden = qw(search);
address@hidden    = qw(Exporter);
address@hidden = qw(search get_record);
+
 # make all your functions, whether exported or not;
 
 sub search {
-    my ($search,$type)address@hidden;
-    my $dbh=C4::Context->dbh();
+    my ( $search, $type, $number ) = @_;
+    my $dbh = C4::Context->dbh();
     my $q;
     my $Zconn;
     my $raw;
+    eval { $Zconn = new ZOOM::Connection( C4::Context->config("zebradb") ); };
+    if ($@) {
+        warn "Error ", address@hidden>code(), ": ", address@hidden>message(), 
"\n";
+    }
+
+    if ( $type eq 'CQL' ) {
+        my $string;
+        if ( $search->{'cql'} ) {
+            $string = $search->{'cql'};
+        }
+        else {
+            foreach my $var ( keys %$search ) {
+                $string .= "$var=\"$search->{$var}\" ";
+            }
+        }
+        $Zconn->option( cqlfile => C4::Context->config("intranetdir")
+              . "/zebra/pqf.properties" );
+        $Zconn->option( preferredRecordSyntax => "xml" );
+        $q = new ZOOM::Query::CQL2RPN( $string, $Zconn );
+    }
+    my $rs;
+    my $n;
     eval {
-       $Zconn = new ZOOM::Connection(C4::Context->config("zebradb"));
+        $rs = $Zconn->search($q);
+        $n  = $rs->size();
     };
     if ($@) {
-       warn "Error ", address@hidden>code(), ": ", address@hidden>message(), 
"\n";                  
+        print "Error ", address@hidden>code(), ": ", address@hidden>message(), 
"\n";
+    }
+    my $i = 0;
+    my @results;
+    while ( $i < $n && $i < $number ) {
+        $raw = $rs->record($i)->raw();
+        my $record = MARC::Record->new_from_xml($raw);
+        my $line = MARCmarc2koha( $dbh, $record );
+        push @results, $line;
+       $i++;
     }
-    
-    if ($type eq 'CQL'){
-       my $string;
-       foreach my $var (keys %$search) {
-           $string.="$var=\"$search->{$var}\" ";
-       }           
-       $Zconn->option(cqlfile => 
C4::Context->config("intranetdir")."/zebra/pqf.properties");
-       $Zconn->option(preferredRecordSyntax => "xml");
-       $q = new ZOOM::Query::CQL2RPN( $string, $Zconn);        
-       }
+    return ( address@hidden );
+
+}
+
+sub get_record {
+
+    # pass in an id (localnumber) and get back a MARC record
+    my ($id) = @_;
+    my $q;
+    my $Zconn;
+    my $raw;
+    eval { $Zconn = new ZOOM::Connection( C4::Context->config("zebradb") ); };
+    if ($@) {
+        warn "Error ", address@hidden>code(), ": ", address@hidden>message(), 
"\n";
+    }
+    $Zconn->option( cqlfile => C4::Context->config("intranetdir")
+          . "/zebra/pqf.properties" );
+    $Zconn->option( preferredRecordSyntax => "xml" );
+    my $string = "id=$id";
+    warn $id;
+
+    #    $q = new ZOOM::Query::CQL2RPN( $string, $Zconn);
     eval {
-       my $rs = $Zconn->search($q);
-       my $n = $rs->size();
-       if ($n >0){
-           $raw=$rs->record(0)->raw();
-       }
+        my $rs = $Zconn->search_pqf("address@hidden 1=12 $id");
+        my $n  = $rs->size();
+        if ( $n > 0 ) {
+            $raw = $rs->record(0)->raw();
+        }
     };
     if ($@) {
-       print "Error ", address@hidden>code(), ": ", address@hidden>message(), 
"\n";
-    }   
-    my $record = MARC::Record->new_from_xml($raw);
-    ### $record                                                                
                                    
-    # transform it into a meaningul hash                                       
                                
-    my $line = MARCmarc2koha($dbh,$record);                                    
                                
-    ### $line                                                                  
                                    
-    my $biblionumber=$line->{biblionumber};                                    
                                
-    my $title=$line->{title};                                                  
                                
-    ### $title
-
 
+        print "Error ", address@hidden>code(), ": ", address@hidden>message(), 
"\n";
+    }
+    ###$raw
+    my $record = MARC::Record->new_from_xml($raw);
+    ###$record
+    return ($record);
 }
+
 1;
 __END__
 
@@ -109,3 +151,4 @@
 Koha Developement team <address@hidden>
 
 =cut
+ 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]