#!/usr/bin/perl # search-great-ideas.pl - query the great ideas against the great books # Eric Lease Morgan # August 8, 2010 - initial investigations; based on search.pl # define use constant SOLR => 'http://localhost:8983/solr/great-books'; use constant IDEAS => '/var/www/html/main/sandbox/great-books/etc/ideas.txt'; # require use strict; use WebService::Solr; use Lingua::Stem::Snowball; # initalize my $solr = WebService::Solr->new( SOLR ); my @ideas = &slurp_words( IDEAS ); my $stemmer = Lingua::Stem::Snowball->new( lang => 'en' ); # process each idea foreach my $idea ( sort @ideas ) { # search for the idea and its stem my $response_idea = $solr->search( $idea ); my $stem = $stemmer->stem( $idea ); my $response_stem = $solr->search( $stem ); # get the number of hits and display my $hit_idea = $response_idea->pager->total_entries; my $hit_stem = $response_stem->pager->total_entries; print "Your search for $idea and $stem found $hit_idea and $hit_stem document(s), respectively.\n"; } # done print "\n"; exit; sub slurp_words { my $file = shift; my @words = (); open ( S, " < $file" ) or die "Can't open $file ($!)\n"; while ( ) { chop; next if ( ! $_ ); # blank line next if ( /^#/ ); # comments push @words, $_; } close S; return @words; }