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
This commit is contained in:
parent
88d6a12e17
commit
3d5d00b463
3 changed files with 173 additions and 35 deletions
95
C4/Search.pm
95
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
|
||||
|
||||
|
@ -53,52 +54,93 @@ other databases.
|
|||
=cut
|
||||
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = qw(search);
|
||||
@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"));
|
||||
};
|
||||
eval { $Zconn = new ZOOM::Connection( C4::Context->config("zebradb") ); };
|
||||
if ($@) {
|
||||
warn "Error ", $@->code(), ": ", $@->message(), "\n";
|
||||
}
|
||||
|
||||
if ($type eq 'CQL'){
|
||||
if ( $type eq 'CQL' ) {
|
||||
my $string;
|
||||
foreach my $var (keys %$search) {
|
||||
$string.="$var=\"$search->{$var}\" ";
|
||||
if ( $search->{'cql'} ) {
|
||||
$string = $search->{'cql'};
|
||||
}
|
||||
$Zconn->option(cqlfile => C4::Context->config("intranetdir")."/zebra/pqf.properties");
|
||||
$Zconn->option(preferredRecordSyntax => "xml");
|
||||
$q = new ZOOM::Query::CQL2RPN( $string, $Zconn);
|
||||
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 {
|
||||
my $rs = $Zconn->search($q);
|
||||
my $n = $rs->size();
|
||||
if ($n >0){
|
||||
$raw=$rs->record(0)->raw();
|
||||
}
|
||||
$rs = $Zconn->search($q);
|
||||
$n = $rs->size();
|
||||
};
|
||||
if ($@) {
|
||||
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);
|
||||
### $record
|
||||
# transform it into a meaningul hash
|
||||
my $line = MARCmarc2koha($dbh,$record);
|
||||
### $line
|
||||
my $biblionumber=$line->{biblionumber};
|
||||
my $title=$line->{title};
|
||||
### $title
|
||||
|
||||
my $line = MARCmarc2koha( $dbh, $record );
|
||||
push @results, $line;
|
||||
$i++;
|
||||
}
|
||||
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_pqf("\@attr 1=12 $id");
|
||||
my $n = $rs->size();
|
||||
if ( $n > 0 ) {
|
||||
$raw = $rs->record(0)->raw();
|
||||
}
|
||||
};
|
||||
if ($@) {
|
||||
|
||||
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 <info@koha.org>
|
||||
|
||||
=cut
|
||||
|
||||
|
|
53
koha-tmpl/opac-tmpl/npl/en/search-test.tmpl
Normal file
53
koha-tmpl/opac-tmpl/npl/en/search-test.tmpl
Normal file
|
@ -0,0 +1,53 @@
|
|||
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><!-- TMPL_VAR NAME="LibraryName" --> -- Library Catalog
|
||||
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
|
||||
<!--TMPL_INCLUDE NAME="masthead.inc" -->
|
||||
<!--TMPL_INCLUDE NAME="navigation.inc" -->
|
||||
|
||||
<div id="main">
|
||||
|
||||
<div class="content-block">
|
||||
|
||||
<!-- TMPL_IF NAME="loggedinusername" -->
|
||||
<!-- TMPL_ELSE --><div id="sidebar">
|
||||
<form action="/cgi-bin/koha/opac-user.pl" method="post" name="auth" id="auth">
|
||||
<h3>Log in to Check Your Account</h3>
|
||||
<p><label for="userid">Card Number:</label><!-- Hide from NPL --><input type="text" id="userid" size="10" name="userid" /><!-- /Hide from NPL --> <!-- Display for NPL // <input type="text" id="userid" size="10" name="userid" onblur="ValidateCode();" /> //Display for NPL --></p>
|
||||
<p><label for="password">Password:</label> <input type="password" id="password" size="10" name="password" /></p>
|
||||
<p><input type="submit" value="Log In" class="submit" /></p>
|
||||
</form></div>
|
||||
<!-- /TMPL_IF -->
|
||||
|
||||
<form action="/cgi-bin/koha/search-test.pl">
|
||||
<h3>Search the Library Catalog</h3>
|
||||
<p>
|
||||
<label for="value">Enter CQL:</label>
|
||||
<textarea name="cql" cols=40 rows=5></textarea>
|
||||
<p><input type="submit" value="Search" class="submit" /></p>
|
||||
<p>
|
||||
<!-- TMPL_IF NAME="CQL"-->
|
||||
<h3> Results </h3>
|
||||
<table>
|
||||
<!-- TMPL_LOOP NAME="results"-->
|
||||
<tr><td>title</td><td><!-- TMPL_VAR NAME="title" --></td></tr>
|
||||
<!-- /TMPL_LOOP -->
|
||||
</table>
|
||||
<!-- /TMPL_IF -->
|
||||
<!-- TMPL_IF NAME="loggedinusername" -->
|
||||
<div class="content-block">
|
||||
<h3>You're logged in as <em><!-- TMPL_LOOP NAME="USER_INFO" --><!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></em> <span class="print">(<a href="/cgi-bin/koha/opac-logout.pl">Click here</a> if you're not <!-- TMPL_VAR NAME="title" --> <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" -->)</span><!-- /TMPL_LOOP --></h3>
|
||||
<p><a href="/cgi-bin/koha/opac-user.pl">my library home</a> | <!-- Hide from NPL--> <a href="/cgi-bin/koha/opac-account.pl">my fines</a> | <!-- Hide from NPL -->
|
||||
<a href="/cgi-bin/koha/opac-userdetails.pl">my personal details</a> | <a href="/cgi-bin/koha/opac-readingrecord.pl">my reading history</a> <!-- TMPL_IF name="virtualshelves" --> | <a href="/cgi-bin/koha/opac-shelves.pl" class="button">my book lists</a> <!-- /TMPL_IF --><!-- TMPL_IF name="suggestion" -->| <a href="/cgi-bin/koha/opac-suggestions.pl">purchase suggestions</a><!-- /TMPL_IF --></p>
|
||||
<!-- TMPL_IF name="textmessaging"-->
|
||||
<h3>Message from the library</h3>
|
||||
<p><!-- TMPL_VAR name="textmessaging" --></p>
|
||||
<!-- /TMPL_IF -->
|
||||
<form method="post" action="/cgi-bin/koha/opac-logout.pl">
|
||||
<p><input type="submit" class="submit" name="logout" value="Log Out" /></p>
|
||||
</form>
|
||||
</div><!-- /TMPL_IF -->
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
42
search-test.pl
Executable file
42
search-test.pl
Executable file
|
@ -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;
|
Loading…
Reference in a new issue