From 3d5d00b4635cff18fd99c2b151e56cdd871eb1b7 Mon Sep 17 00:00:00 2001 From: rangi Date: Thu, 16 Feb 2006 20:51:07 +0000 Subject: [PATCH] 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 --- C4/Search.pm | 109 ++++++++++++++------ koha-tmpl/opac-tmpl/npl/en/search-test.tmpl | 53 ++++++++++ search-test.pl | 42 ++++++++ 3 files changed, 171 insertions(+), 33 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/npl/en/search-test.tmpl create mode 100755 search-test.pl diff --git a/C4/Search.pm b/C4/Search.pm index 460a2dcf2a..8a13d1150f 100755 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -31,7 +31,8 @@ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); # set the version for version checking $VERSION = do { my @v = '$Revision$' =~ /\d+/g; - shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); }; + shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); +}; =head1 NAME @@ -52,53 +53,94 @@ other databases. =cut -@ISA = qw(Exporter); -@EXPORT = qw(search); +@ISA = qw(Exporter); +@EXPORT = qw(search get_record); + # make all your functions, whether exported or not; sub search { - my ($search,$type)=@_; - 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 ", $@->code(), ": ", $@->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 ", $@->code(), ": ", $@->message(), "\n"; + print "Error ", $@->code(), ": ", $@->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 ( \@results ); + +} + +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 ", $@->code(), ": ", $@->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("\@attr 1=12 $id"); + my $n = $rs->size(); + if ( $n > 0 ) { + $raw = $rs->record(0)->raw(); + } }; if ($@) { - print "Error ", $@->code(), ": ", $@->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 ", $@->code(), ": ", $@->message(), "\n"; + } + ###$raw + my $record = MARC::Record->new_from_xml($raw); + ###$record + return ($record); } + 1; __END__ @@ -109,3 +151,4 @@ __END__ Koha Developement team =cut + diff --git a/koha-tmpl/opac-tmpl/npl/en/search-test.tmpl b/koha-tmpl/opac-tmpl/npl/en/search-test.tmpl new file mode 100644 index 0000000000..b47ffb7a79 --- /dev/null +++ b/koha-tmpl/opac-tmpl/npl/en/search-test.tmpl @@ -0,0 +1,53 @@ + -- Library Catalog + + + + +
+ +
+ + + + + +
+

Search the Library Catalog

+

+ + +

+

+ +

Results

+ + + + +
title
+ + +
+

You're logged in as (Click here if you're not )

+

my library home | my fines | + my personal details | my reading history | my book lists | purchase suggestions

+ +

Message from the library

+

+ + +

+ +
+ + +
+ + + diff --git a/search-test.pl b/search-test.pl new file mode 100755 index 0000000000..83768aa516 --- /dev/null +++ b/search-test.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +# simple script to test cql searching +# written by chris@katipo.co.nz 17/2/06 + +use C4::Search; +use C4::Auth; +use C4::Interface::CGI::Output; + +use CGI; +use Smart::Comments; +use strict; +use warnings; + +my $input = new CGI; + +my ( $template, $borrowernumber, $cookie ) = get_template_and_user( + { + template_name => "search-test.tmpl", + type => "opac", + query => $input, + authnotrequired => 1, + flagsrequired => { borrow => 1 }, + } +); + +my $cql=$input->param('cql'); +if ($cql){ + my %search; + $search{'cql'} = $cql; + my $results = search( \%search, 'CQL' , 10); + $template->param(CQL => 'yes' + ); + $template->param(results => $results); +} +#my $record = get_record($result); + + + + + +output_html_with_http_headers $input, $cookie, $template->output; -- 2.39.5