/[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 19 by dpavlin, Wed Jan 4 23:10:48 2006 UTC revision 31 by dpavlin, Thu Jan 5 15:36:25 2006 UTC
# Line 476  sub options { Line 476  sub options {
476  }  }
477    
478    
479    package Search::Estraier::ResultDocument;
480    
481    use Carp qw/croak/;
482    
483    #use Search::Estraier;
484    #our @ISA = qw/Search::Estraier/;
485    
486    =head1 Search::Estraier::ResultDocument
487    
488    =head2 new
489    
490      my $rdoc = new Search::HyperEstraier::ResultDocument(
491            uri => 'http://localhost/document/uri/42',
492            attrs => {
493                    foo => 1,
494                    bar => 2,
495            },
496            snippet => 'this is a text of snippet'
497            keywords => 'this\tare\tkeywords'
498      );
499    
500    =cut
501    
502    sub new {
503            my $class = shift;
504            my $self = {@_};
505            bless($self, $class);
506    
507            foreach my $f (qw/uri attrs snippet keywords/) {
508                    croak "missing $f for ResultDocument" unless defined($self->{$f});
509            }
510    
511            $self ? return $self : return undef;
512    }
513    
514    =head2 uri
515    
516    Return URI of result document
517    
518      print $rdoc->uri;
519    
520    =cut
521    
522    sub uri {
523            my $self = shift;
524            return $self->{uri};
525    }
526    
527    
528    =head2 attr_names
529    
530    Returns array with attribute names from result document object.
531    
532      my @attrs = $rdoc->attr_names;
533    
534    =cut
535    
536    sub attr_names {
537            my $self = shift;
538            croak "attr_names return array, not scalar" if (! wantarray);
539            return sort keys %{ $self->{attrs} };
540    }
541    
542    =head2 attr
543    
544    Returns value of an attribute.
545    
546      my $value = $rdoc->attr( 'attribute' );
547    
548    =cut
549    
550    sub attr {
551            my $self = shift;
552            my $name = shift || return;
553            return $self->{attrs}->{ $name };
554    }
555    
556    =head2 snippet
557    
558    Return snippet from result document
559    
560      print $rdoc->snippet;
561    
562    =cut
563    
564    sub snippet {
565            my $self = shift;
566            return $self->{snippet};
567    }
568    
569    =head2 keywords
570    
571    Return keywords from result document
572    
573      print $rdoc->keywords;
574    
575    =cut
576    
577    sub keywords {
578            my $self = shift;
579            return $self->{keywords};
580    }
581    
582    
583    package Search::Estraier::NodeResult;
584    
585    use Carp qw/croak/;
586    
587    #use Search::Estraier;
588    #our @ISA = qw/Search::Estraier/;
589    
590    =head1 Search::Estraier::NodeResult
591    
592    =head2 new
593    
594      my $res = new Search::HyperEstraier::NodeResult(
595            docs => @array_of_rdocs,
596            hits => %hash_with_hints,
597      );
598    
599    =cut
600    
601    sub new {
602            my $class = shift;
603            my $self = {@_};
604            bless($self, $class);
605    
606            foreach my $f (qw/docs hints/) {
607                    croak "missing $f for ResultDocument" unless defined($self->{$f});
608            }
609    
610            $self ? return $self : return undef;
611    }
612    
613    =head2 doc_num
614    
615    Return number of documents
616    
617      print $res->doc_num;
618    
619    =cut
620    
621    sub doc_num {
622            my $self = shift;
623            return $#{$self->{docs}};
624    }
625    
626    =head2 get_doc
627    
628    Return single document
629    
630      my $doc = $res->get_doc( 42 );
631    
632    Returns undef if document doesn't exist.
633    
634    =cut
635    
636    sub get_doc {
637            my $self = shift;
638            my $num = shift;
639            croak "expect number as argument" unless ($num =~ m/^\d+$/);
640            return undef if ($num < 0 || $num > $self->{docs});
641            return $self->{docs}->[$num];
642    }
643    
644    =head2 hint
645    
646    Return specific hint from results.
647    
648      print $rec->hint( 'VERSION' );
649    
650    Possible hints are: C<VERSION>, C<NODE>, C<HIT>, C<HINT#n>, C<DOCNUM>, C<WORDNUM>,
651    C<TIME>, C<LINK#n>, C<VIEW>.
652    
653    =cut
654    
655    sub hint {
656            my $self = shift;
657            my $key = shift || return;
658            return $self->{hints}->{$key};
659    }
660    
661    
662    package Search::Estraier::Node;
663    
664    use Carp qw/croak/;
665    
666    =head1 Search::Estraier::Node
667    
668    =head2 new
669    
670      my $node = new Search::HyperEstraier::Node;
671    
672    =cut
673    
674    sub new {
675            my $class = shift;
676            my $self = {
677                    pxport => -1,
678                    timeout => -1,
679                    dnum => -1,
680                    wnum => -1,
681                    size => -1.0,
682                    wwidth => 480,
683                    hwidth => 96,
684                    awidth => 96,
685                    status => -1,
686            };
687            bless($self, $class);
688    
689            $self ? return $self : return undef;
690    }
691    
692    =head2 set_url
693    
694    Specify URL to node server
695    
696      $node->set_url('http://localhost:1978');
697    
698    =cut
699    
700    sub set_url {
701            my $self = shift;
702            $self->{url} = shift;
703    }
704    
705    =head2 set_proxy
706    
707    Specify proxy server to connect to node server
708    
709      $node->set_proxy('proxy.example.com', 8080);
710    
711    =cut
712    
713    sub set_proxy {
714            my $self = shift;
715            my ($host,$port) = @_;
716            croak "proxy port must be number" unless ($port =~ m/^\d+$/);
717            $self->{pxhost} = $host;
718            $self->{pxport} = $port;
719    }
720    
721    =head2 set_timeout
722    
723    Specify timeout of connection in seconds
724    
725      $node->set_timeout( 15 );
726    
727    =cut
728    
729    sub set_timeout {
730            my $self = shift;
731            my $sec = shift;
732            croak "timeout must be number" unless ($sec =~ m/^\d+$/);
733            $self->{timeout} = $sec;
734    }
735    
736    =head2 set_auth
737    
738    Specify name and password for authentication to node server.
739    
740      $node->set_auth('clint','eastwood');
741    
742    =cut
743    
744    sub set_auth {
745            my $self = shift;
746            my ($login,$passwd) = @_;
747            $self->{auth} = "$login:$passwd";
748    }
749    
750  package Search::Estraier::Master;  package Search::Estraier::Master;
751    
752  use Carp;  use Carp;

Legend:
Removed from v.19  
changed lines
  Added in v.31

  ViewVC Help
Powered by ViewVC 1.1.26