--- trunk/Estraier.pm 2006/01/07 01:21:28 61 +++ trunk/Estraier.pm 2006/01/08 16:49:53 69 @@ -4,7 +4,7 @@ use strict; use warnings; -our $VERSION = '0.01'; +our $VERSION = '0.03_1'; =head1 NAME @@ -12,8 +12,57 @@ =head1 SYNOPSIS - use Search::Estraier; - my $est = new Search::Estraier(); +=head2 Simple indexer + + use Search::Estraier; + + # create and configure node + my $node = new Search::Estraier::Node; + $node->set_url("http://localhost:1978/node/test"); + $node->set_auth("admin","admin"); + + # create document + my $doc = new Search::Estraier::Document; + + # add attributes + $doc->add_attr('@uri', "http://estraier.gov/example.txt"); + $doc->add_attr('@title', "Over the Rainbow"); + + # add body text to document + $doc->add_text("Somewhere over the rainbow. Way up high."); + $doc->add_text("There's a land that I heard of once in a lullaby."); + + die "error: ", $node->status,"\n" unless ($node->put_doc($doc)); + +=head2 Simple searcher + + use Search::Estraier; + + # create and configure node + my $node = new Search::Estraier::Node; + $node->set_url("http://localhost:1978/node/test"); + $node->set_auth("admin","admin"); + + # create condition + my $cond = new Search::Estraier::Condition; + + # set search phrase + $cond->set_phrase("rainbow AND lullaby"); + + my $nres = $node->search($cond, 0); + if (defined($nres)) { + # for each document in results + for my $i ( 0 ... $nres->doc_num - 1 ) { + # get result document + my $rdoc = $nres->get_doc($i); + # display attribte + print "URI: ", $rdoc->attr('@uri'),"\n"; + print "Title: ", $rdoc->attr('@title'),"\n"; + print $rdoc->snippet,"\n"; + } + } else { + die "error: ", $node->status,"\n"; + } =head1 DESCRIPTION @@ -25,6 +74,8 @@ It is implemented as multiple packages which closly resamble Ruby implementation. It also includes methods to manage nodes. +There are few examples in C directory of this distribution. + =cut =head1 Inheritable common methods @@ -525,9 +576,7 @@ my $self = {@_}; bless($self, $class); - foreach my $f (qw/uri attrs snippet keywords/) { - croak "missing $f for ResultDocument" unless defined($self->{$f}); - } + croak "missing uri for ResultDocument" unless defined($self->{uri}); $self ? return $self : return undef; } @@ -701,6 +750,10 @@ my $node = new Search::HyperEstraier::Node; +or optionally with C as parametar + + my $node = new Search::HyperEstraier::Node( 'http://localhost:1978/node/test' ); + =cut sub new { @@ -718,10 +771,14 @@ }; bless($self, $class); - my $args = {@_}; + if ($#_ == 0) { + $self->{url} = shift; + } else { + my $args = {@_}; - $self->{debug} = $args->{debug}; - warn "## Node debug on\n" if ($self->{debug}); + $self->{debug} = $args->{debug}; + warn "## Node debug on\n" if ($self->{debug}); + } $self ? return $self : return undef; } @@ -1290,7 +1347,7 @@ if (my @attrs = $cond->attrs) { for my $i ( 0 .. $#attrs ) { - push @args,'attr' . ($i+1) . '=' . uri_escape( $attrs[$i] ); + push @args,'attr' . ($i+1) . '=' . uri_escape( $attrs[$i] ) if ($attrs[$i]); } } @@ -1319,7 +1376,7 @@ =head2 shuttle_url -This is method which uses C to communicate with Hyper Estraier node +This is method which uses C to communicate with Hyper Estraier node master. my $rv = shuttle_url( $url, $content_type, $req_body, \$resbody );