Net-Z3950-SimpleServer

 view release on metacpan or  search on metacpan

ztest.pl  view on Meta::CPAN

sub my_scan_handler {
	my $args = shift;
	my $term = $args->{TERM};
	my $entries = [
				{	TERM		=>	'Number 1',
					DISPLAY_TERM    =>      'Number .1',
					OCCURRENCE	=>	10 },
				{	TERM		=>	'Number 2',
					OCCURRENCE	=>	8 },
				{	TERM		=>	'Number 3',
					OCCURRENCE	=>	8 },
				{	TERM		=>	'Number 4',
					OCCURRENCE	=>	8 },
				{	TERM		=>	'Number 5',
					OCCURRENCE	=>	8 },
				{	TERM		=>	'Number 6',
					OCCURRENCE	=>	8 },
				{	TERM		=>	'Number 7',
					OCCURRENCE	=>	8 },
				{	TERM		=>	'Number 8',
					OCCURRENCE	=>	8 },
				{	TERM		=>	'Number 9',
					OCCURRENCE	=>	8 },
				{	TERM		=>	'Number 10',
					OCCURRENCE	=>	4 },
			];
	$args->{NUMBER} = 10;
	$args->{ENTRIES} = $entries;
	$args->{STATUS} = Net::Z3950::SimpleServer::ScanPartial;
	print "Welcome to scan....\n";
	$args->{EXTRA_RESPONSE_DATA} = '<scanextra>b</scanextra>';
	print "You scanned for term '$term'\n";
}


my $_fail_frequency = 0;
my $_counter = 0;

sub my_search_handler {
	my $args = shift;

	my $data = [{
			name		=>	"Peter Dornan",
			title		=>	"Spokesman",
			collaboration	=>	"ATLAS"
	    	    }, {
			name		=>	"Jorn Dines Hansen",
			title		=>	"Professor",
			collaboration	=>	"HERA-B"
	    	    }, {
			name		=>	"Alain Blondel",
			title		=>	"Head of coll.",
			collaboration	=>	"ALEPH"
	   	    }];

	my $session = $args->{HANDLE};
	my $set_id = $args->{SETNAME};
	my $rpn = $args->{RPN};
	my @database_list = @{ $args->{DATABASES} };
	my $query = $args->{QUERY};
	my $facets = my_facets_response($args->{INPUTFACETS});
	my $hits = 3;

	print "------------------------------------------------------------\n";
	print "Processing query : $query\n";
	printf("Database set     : %s\n", join(" ", @database_list));
	print "Setname          : $set_id\n";
	print " inputfacets:\n";
	print Dumper($facets);
        print " extra args:\n";
        print Dumper($args->{EXTRA_ARGS});
	print "------------------------------------------------------------\n";

	$args->{OUTPUTFACETS} = $facets;

	$args->{EXTRA_RESPONSE_DATA} = '<searchextra>b</searchextra>';
	$args->{HITS} = $hits;
	$session->{$set_id} = $data;
	$session->{__HITS} = $hits;
	if ($_fail_frequency != 0 && ++$_counter % $_fail_frequency == 0) {
	    print "Exiting to be nasty to client\n";
	    exit(1);
	}
}

sub my_facets_response {
	my $inputfacets = shift;
	if (!$inputfacets) {
		# no facets requested: generate default input facets
		$inputfacets = [
			{ attributes => [
				  { attributeType => 1,
				    attributeValue => 'author'
				  },
				  { attributeType => 2,
				    attributeValue => 0
				  },
				  { attributeType => 3,
				    attributeValue => 5
				  },
				  { attributeType => 4,
				    attributeValue => 1
				  }
			      ]
			},
			{ attributes => [
				  { attributeType => 1,
				    attributeValue => 'title'
				  },
				  { attributeType => 2,
				    attributeValue => 0
				  },
				  { attributeType => 3,
				    attributeValue => 5
				  },
				  { attributeType => 4,
				    attributeValue => 1
				  }
			      ]
			}
		    ];
	}
	# generate facets response. we use inputfacets as basis
	my $zfacetlist = [];
	bless $zfacetlist, 'Net::Z3950::FacetList';
	my $i = 0;
	foreach my $x (@$inputfacets) {
		my $facetname = "unknown";
		my $sortorder = 0;
		my $count = 5;
		my $offset = 1;
		foreach my $attr (@{$x->{'attributes'}}) {
			my $type = $attr->{'attributeType'};
			my $value = $attr->{'attributeValue'};



( run in 1.996 second using v1.01-cache-2.11-cpan-39bf76dae61 )