/[Search-Estraier]/trunk/lib/Search/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/lib/Search/Estraier.pm

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

revision 140 by dpavlin, Wed May 10 14:08:34 2006 UTC revision 160 by dpavlin, Sat Jun 24 15:34:42 2006 UTC
# Line 4  use 5.008; Line 4  use 5.008;
4  use strict;  use strict;
5  use warnings;  use warnings;
6    
7  our $VERSION = '0.06_1';  our $VERSION = '0.07_2';
8    
9  =head1 NAME  =head1 NAME
10    
# Line 1053  Add a document Line 1053  Add a document
1053    
1054    $node->put_doc( $document_draft ) or die "can't add document";    $node->put_doc( $document_draft ) or die "can't add document";
1055    
1056  Return true on success or false on failture.  Return true on success or false on failure.
1057    
1058  =cut  =cut
1059    
# Line 1061  sub put_doc { Line 1061  sub put_doc {
1061          my $self = shift;          my $self = shift;
1062          my $doc = shift || return;          my $doc = shift || return;
1063          return unless ($self->{url} && $doc->isa('Search::Estraier::Document'));          return unless ($self->{url} && $doc->isa('Search::Estraier::Document'));
1064          $self->shuttle_url( $self->{url} . '/put_doc',          if ($self->shuttle_url( $self->{url} . '/put_doc',
1065                  'text/x-estraier-draft',                  'text/x-estraier-draft',
1066                  $doc->dump_draft,                  $doc->dump_draft,
1067                  undef                  undef
1068          ) == 200;          ) == 200) {
1069                    $self->_clear_info;
1070                    return 1;
1071            }
1072            return undef;
1073  }  }
1074    
1075    
# Line 1084  sub out_doc { Line 1088  sub out_doc {
1088          my $id = shift || return;          my $id = shift || return;
1089          return unless ($self->{url});          return unless ($self->{url});
1090          croak "id must be number, not '$id'" unless ($id =~ m/^\d+$/);          croak "id must be number, not '$id'" unless ($id =~ m/^\d+$/);
1091          $self->shuttle_url( $self->{url} . '/out_doc',          if ($self->shuttle_url( $self->{url} . '/out_doc',
1092                  'application/x-www-form-urlencoded',                  'application/x-www-form-urlencoded',
1093                  "id=$id",                  "id=$id",
1094                  undef                  undef
1095          ) == 200;          ) == 200) {
1096                    $self->_clear_info;
1097                    return 1;
1098            }
1099            return undef;
1100  }  }
1101    
1102    
# Line 1106  sub out_doc_by_uri { Line 1114  sub out_doc_by_uri {
1114          my $self = shift;          my $self = shift;
1115          my $uri = shift || return;          my $uri = shift || return;
1116          return unless ($self->{url});          return unless ($self->{url});
1117          $self->shuttle_url( $self->{url} . '/out_doc',          if ($self->shuttle_url( $self->{url} . '/out_doc',
1118                  'application/x-www-form-urlencoded',                  'application/x-www-form-urlencoded',
1119                  "uri=" . uri_escape($uri),                  "uri=" . uri_escape($uri),
1120                  undef                  undef
1121          ) == 200;          ) == 200) {
1122                    $self->_clear_info;
1123                    return 1;
1124            }
1125            return undef;
1126  }  }
1127    
1128    
# Line 1128  sub edit_doc { Line 1140  sub edit_doc {
1140          my $self = shift;          my $self = shift;
1141          my $doc = shift || return;          my $doc = shift || return;
1142          return unless ($self->{url} && $doc->isa('Search::Estraier::Document'));          return unless ($self->{url} && $doc->isa('Search::Estraier::Document'));
1143          $self->shuttle_url( $self->{url} . '/edit_doc',          if ($self->shuttle_url( $self->{url} . '/edit_doc',
1144                  'text/x-estraier-draft',                  'text/x-estraier-draft',
1145                  $doc->dump_draft,                  $doc->dump_draft,
1146                  undef                  undef
1147          ) == 200;          ) == 200) {
1148                    $self->_clear_info;
1149                    return 1;
1150            }
1151            return undef;
1152  }  }
1153    
1154    
# Line 1499  sub cond_to_query { Line 1515  sub cond_to_query {
1515          push @args, 'wwidth=' . $self->{wwidth};          push @args, 'wwidth=' . $self->{wwidth};
1516          push @args, 'hwidth=' . $self->{hwidth};          push @args, 'hwidth=' . $self->{hwidth};
1517          push @args, 'awidth=' . $self->{awidth};          push @args, 'awidth=' . $self->{awidth};
1518          push @args, 'skip=' . $self->{skip} if ($self->{skip});          push @args, 'skip=' . $cond->{skip} if ($cond->{skip});
1519    
1520          return join('&', @args);          return join('&', @args);
1521  }  }
# Line 1646  sub set_user { Line 1662  sub set_user {
1662          croak "mode must be number, not '$mode'" unless ($mode =~ m/^\d+$/);          croak "mode must be number, not '$mode'" unless ($mode =~ m/^\d+$/);
1663    
1664          $self->shuttle_url( $self->{url} . '/_set_user',          $self->shuttle_url( $self->{url} . '/_set_user',
1665                  'text/plain',                  'application/x-www-form-urlencoded',
1666                  'name=' . uri_escape($name) . '&mode=' . $mode,                  'name=' . uri_escape($name) . '&mode=' . $mode,
1667                  undef                  undef
1668          ) == 200;          ) == 200;
# Line 1679  sub set_link { Line 1695  sub set_link {
1695                  undef                  undef
1696          ) == 200) {          ) == 200) {
1697                  # refresh node info after adding link                  # refresh node info after adding link
1698                  $self->_set_info;                  $self->_clear_info;
1699                  return 1;                  return 1;
1700          }          }
1701            return undef;
1702  }  }
1703    
1704  =head2 admins  =head2 admins
# Line 1726  sub links { Line 1743  sub links {
1743          return $self->{inform}->{links};          return $self->{inform}->{links};
1744  }  }
1745    
1746    =head2 cacheusage
1747    
1748    Return cache usage for a node
1749    
1750      my $cache = $node->cacheusage;
1751    
1752    =cut
1753    
1754    sub cacheusage {
1755            my $self = shift;
1756    
1757            return unless ($self->{url});
1758    
1759            my $resbody;
1760            my $rv = $self->shuttle_url( $self->{url} . '/cacheusage',
1761                    'text/plain',
1762                    undef,
1763                    \$resbody,
1764            );
1765    
1766            return if ($rv != 200 || !$resbody);
1767    
1768            return $resbody;
1769    }
1770    
1771  =head2 master  =head2 master
1772    
1773  Set actions on Hyper Estraier node master (C<estmaster> process)  Set actions on Hyper Estraier node master (C<estmaster> process)
# Line 1828  sub master { Line 1870  sub master {
1870          ) or confess "shuttle_url failed";          ) or confess "shuttle_url failed";
1871    
1872          if ($status == $rest->{status}) {          if ($status == $rest->{status}) {
1873    
1874                    # refresh node info after sync
1875                    $self->_clear_info if ($action eq 'sync' || $action =~ m/^node(?:add|del|clr)$/);
1876    
1877                  if ($rest->{returns} && wantarray) {                  if ($rest->{returns} && wantarray) {
1878    
1879                          my @results;                          my @results;
# Line 1885  sub _set_info { Line 1931  sub _set_info {
1931    
1932          my @lines = split(/[\r\n]/,$resbody);          my @lines = split(/[\r\n]/,$resbody);
1933    
1934          $self->{inform} = {};          $self->_clear_info;
1935    
1936          ( $self->{inform}->{name}, $self->{inform}->{label}, $self->{inform}->{dnum},          ( $self->{inform}->{name}, $self->{inform}->{label}, $self->{inform}->{dnum},
1937                  $self->{inform}->{wnum}, $self->{inform}->{size} ) = split(/\t/, shift @lines, 5);                  $self->{inform}->{wnum}, $self->{inform}->{size} ) = split(/\t/, shift @lines, 5);
# Line 1910  sub _set_info { Line 1956  sub _set_info {
1956    
1957  }  }
1958    
1959    =head2 _clear_info
1960    
1961    Clear information for node
1962    
1963      $node->_clear_info;
1964    
1965    On next call to C<name>, C<label>, C<doc_num>, C<word_num> or C<size> node
1966    info will be fetch again from Hyper Estraier.
1967    
1968    =cut
1969    sub _clear_info {
1970            my $self = shift;
1971            $self->{inform} = {
1972                    dnum => -1,
1973                    wnum => -1,
1974                    size => -1.0,
1975            };
1976    }
1977    
1978  ###  ###
1979    
1980  =head1 EXPORT  =head1 EXPORT

Legend:
Removed from v.140  
changed lines
  Added in v.160

  ViewVC Help
Powered by ViewVC 1.1.26