--- zoom.sql	2007/04/26 21:33:46	7
+++ zoom.sql	2007/04/26 22:19:40	9
@@ -3,14 +3,15 @@
 	host	text not null,
 	port	int not null default 210,
 	database text default 'Default',
+	maxres	int not null default 100,
 	primary key(name)
 );
 
 -- insert sample
-insert into servers values ( 'nsk', '161.53.240.27', 8090, 'voyager' );
-insert into servers values ( 'nsk-en', '161.53.240.27', 8190, 'voyager' );
-insert into servers values ( 'loc', 'z3950.loc.gov', 7090, 'Voyager' );
-insert into servers values ( 'ucs', 'library.usc.edu', 2200, 'unicorn' );
+insert into servers values ( 'nsk', '161.53.240.27', 8090, 'voyager', 0 );
+insert into servers values ( 'nsk-en', '161.53.240.27', 8190, 'voyager', 300 );
+insert into servers values ( 'loc', 'z3950.loc.gov', 7090, 'Voyager', 300 );
+insert into servers values ( 'ucs', 'library.usc.edu', 2200, 'unicorn', 100 );
 --insert into servers values ( '', '', , '' );
 
 create type item as (
@@ -25,21 +26,23 @@
 language plperlu
 as $$
 
+use strict;
+
 my $debug = 0;
-my $max_res = 100;
 
 my ( $server, $query ) = @_;
 
 my $rv = spi_exec_query(qq{
-	select host,port,database from servers where name ilike '$server'
+	select host,port,database,maxres from servers where name ilike '$server'
 },1);
 
 die "can't find server $server in table servers\n" unless ( $rv->{processed} == 1 );
 
-my ( $host, $port, $database ) = (
+my ( $host, $port, $database, $max_res ) = (
 	$rv->{rows}[0]->{host},
 	$rv->{rows}[0]->{port},
 	$rv->{rows}[0]->{database},
+	$rv->{rows}[0]->{maxres},
 );
 
 use ZOOM;
@@ -68,9 +71,18 @@
 
 $conn->option(preferredRecordSyntax => "usmarc");
 
-my $cqf = q2cqf( $query );
+my $rs;
+
+my $notice;
 
-my $rs = $conn->search_pqf( $cqf );
+if ( $query =~ m/[\s="]|(and|or|not)/ ) {
+	$rs = $conn->search( new ZOOM::Query::CQL( $query ) );
+	$notice = 'CQL';
+} else {
+	my $cqf = q2cqf( $query );
+	$notice = "CQF: $cqf";
+	$rs = $conn->search_pqf( $cqf );
+}
 
 my $n = $rs->size();
 if ( $n > $max_res ) {
@@ -80,7 +92,7 @@
 # fetch all results
 $rs->records(0, $n - 1, 0);
 
-warn "$n results for '$query' [$cqf]\n";
+warn "$n results for '$query' $notice\n";
 
 sub strip_non_digit {
 	my $d = shift;
@@ -134,4 +146,8 @@
 --select * from search('nsk','grada');
 --select * from search('nsk-en','restrictions');
 
-select * from search('ucs','human');
+--select * from search('ucs','human');
+
+SELECT date,count(date)
+FROM search('loc','human and computer and interaction')
+GROUP BY date
