/[Search-Estraier]/trunk/Estraier.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Estraier.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 98 by dpavlin, Sat Jan 28 19:18:13 2006 UTC revision 102 by dpavlin, Sat Jan 28 19:46:20 2006 UTC
# Line 17  Search::Estraier - pure perl module to u Line 17  Search::Estraier - pure perl module to u
17          use Search::Estraier;          use Search::Estraier;
18    
19          # create and configure node          # create and configure node
20          my $node = new Search::Estraier::Node;          my $node = new Search::Estraier::Node(
21          $node->set_url("http://localhost:1978/node/test");                  url => 'http://localhost:1978/node/test',
22          $node->set_auth("admin","admin");                  user => 'admin',
23                    passwd => 'admin'
24            );
25    
26          # create document          # create document
27          my $doc = new Search::Estraier::Document;          my $doc = new Search::Estraier::Document;
# Line 32  Search::Estraier - pure perl module to u Line 34  Search::Estraier - pure perl module to u
34          $doc->add_text("Somewhere over the rainbow.  Way up high.");          $doc->add_text("Somewhere over the rainbow.  Way up high.");
35          $doc->add_text("There's a land that I heard of once in a lullaby.");          $doc->add_text("There's a land that I heard of once in a lullaby.");
36    
37          die "error: ", $node->status,"\n" unless ($node->put_doc($doc));          die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) });
38    
39  =head2 Simple searcher  =head2 Simple searcher
40    
41          use Search::Estraier;          use Search::Estraier;
42    
43          # create and configure node          # create and configure node
44          my $node = new Search::Estraier::Node;          my $node = new Search::Estraier::Node(
45          $node->set_url("http://localhost:1978/node/test");                  url => 'http://localhost:1978/node/test',
46          $node->set_auth("admin","admin");                  user => 'admin',
47                    passwd => 'admin',
48                    croak_on_error => 1,
49            );
50    
51          # create condition          # create condition
52          my $cond = new Search::Estraier::Condition;          my $cond = new Search::Estraier::Condition;
# Line 50  Search::Estraier - pure perl module to u Line 55  Search::Estraier - pure perl module to u
55          $cond->set_phrase("rainbow AND lullaby");          $cond->set_phrase("rainbow AND lullaby");
56    
57          my $nres = $node->search($cond, 0);          my $nres = $node->search($cond, 0);
58    
59          if (defined($nres)) {          if (defined($nres)) {
60                    print "Got ", $nres->hits, " results\n";
61    
62                  # for each document in results                  # for each document in results
63                  for my $i ( 0 ... $nres->doc_num - 1 ) {                  for my $i ( 0 ... $nres->doc_num - 1 ) {
64                          # get result document                          # get result document
# Line 734  Return number of documents Line 742  Return number of documents
742    
743    print $res->doc_num;    print $res->doc_num;
744    
745    This will return real number of documents (limited by C<max>).
746    If you want to get total number of hits, see C<hits>.
747    
748  =cut  =cut
749    
750  sub doc_num {  sub doc_num {
# Line 765  sub get_doc { Line 776  sub get_doc {
776    
777  Return specific hint from results.  Return specific hint from results.
778    
779    print $rec->hint( 'VERSION' );    print $res->hint( 'VERSION' );
780    
781  Possible hints are: C<VERSION>, C<NODE>, C<HIT>, C<HINT#n>, C<DOCNUM>, C<WORDNUM>,  Possible hints are: C<VERSION>, C<NODE>, C<HIT>, C<HINT#n>, C<DOCNUM>, C<WORDNUM>,
782  C<TIME>, C<LINK#n>, C<VIEW>.  C<TIME>, C<LINK#n>, C<VIEW>.
# Line 778  sub hint { Line 789  sub hint {
789          return $self->{hints}->{$key};          return $self->{hints}->{$key};
790  }  }
791    
792  =head2 hints  =head2 hits
793    
794  More perlish version of C<hint>. This one returns hash.  More perlish version of C<hint>. This one returns hash.
795    
796    my %hints = $rec->hints;    my %hints = $res->hints;
797    
798  =cut  =cut
799    
# Line 791  sub hints { Line 802  sub hints {
802          return $self->{hints};          return $self->{hints};
803  }  }
804    
805    =head2 hits
806    
807    Syntaxtic sugar for total number of hits for this query
808    
809      print $res->hits;
810    
811    It's same as
812    
813      print $res->hint('HIT');
814    
815    but shorter.
816    
817    =cut
818    
819    sub hits {
820            my $self = shift;
821            return $self->{hints}->{'HIT'} || 0;
822    }
823    
824  package Search::Estraier::Node;  package Search::Estraier::Node;
825    
826  use Carp qw/carp croak confess/;  use Carp qw/carp croak confess/;

Legend:
Removed from v.98  
changed lines
  Added in v.102

  ViewVC Help
Powered by ViewVC 1.1.26