#!/usr/bin/perl # search.pl - query a solr/lucene index of great books content # Eric Lease Morgan # May 30, 2010 - first investigations # define use constant SOLR => 'http://localhost:210/solr/great-books'; use constant ROWS => 10; # require use strict; use WebService::Solr; # initalize my $solr = WebService::Solr->new( SOLR ); # sanity check my $query = $ARGV[ 0 ]; if ( ! $query ) { print "Usage: $0 \n"; exit; } # search my $response = $solr->search( $query, { 'rows' => ROWS }); # get the number of hits, and start display my $hit_count = $response->pager->total_entries; print "Your search ($query) found $hit_count document(s).\n\n"; # display each hit my $index = 0; foreach my $doc ( $response->docs ) { # slurp my $id = $doc->value_for( 'id' ); my $creator = $doc->value_for( 'creator' ); my $title = $doc->value_for( 'title' ); my $url = $doc->value_for( 'url' ); # increment $index++; # echo print " record: $index\n"; print " id: $id\n"; print " creator: $creator\n"; print " title: $title\n"; print " url: $url\n"; print "\n"; } # done exit;