/[couchdb]/lib/CouchDB/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 /lib/CouchDB/Estraier.pm

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

revision 12 by dpavlin, Sat Aug 9 16:10:05 2008 UTC revision 13 by dpavlin, Sat Aug 9 23:40:19 2008 UTC
# Line 37  GetOptions($c, qw/node_url=s debug+ estu Line 37  GetOptions($c, qw/node_url=s debug+ estu
37  #my $log = IO::Handle->new;  #my $log = IO::Handle->new;
38  #my $log = IO::Handle->new_from_fd(\*STDERR, 'w');  #my $log = IO::Handle->new_from_fd(\*STDERR, 'w');
39    
40  $log = IO::File->new( "> $log" ) || die "can't open $log: $!";  $log = IO::File->new( ">> $log" ) || die "can't open $log: $!";
41    
42  $log->autoflush( 1 );  $log->autoflush( 1 );
43  $log->print("c: ", dump($c), "\n" ); # if $c->{debug};  $log->print("c: ", dump($c), "\n" ); # if $c->{debug};
# Line 46  my $in = IO::Handle->new_from_fd(\*STDIN Line 46  my $in = IO::Handle->new_from_fd(\*STDIN
46  my $out = IO::Handle->new_from_fd(\*STDOUT, 'w');  my $out = IO::Handle->new_from_fd(\*STDOUT, 'w');
47  $out->autoflush( 1 );  $out->autoflush( 1 );
48    
49  =head2 run_search  =head2 run_query
50    
51  Process command line options and start helper  Process command line options and start helper
52    
# Line 54  Process command line options and start h Line 54  Process command line options and start h
54    
55  =cut  =cut
56    
57  sub run_search {  sub run_query {
58          while ( 1 ) {          while ( 1 ) {
59                  $log->print("search ready\n");  #               $log->print("query ready\n");
60                  my $json = $in->getline;                  my $json = $in->getline;
61                  die unless defined $json;                  die unless defined $json;
62                  $log->print( "run_search $json\n" );                  $log->print( "run_query $json\n" );
63                  $out->print(                  query( decode_json( $json ) )
                         encode_json(  
                                 search( decode_json( $json ) )  
                         ) ,"\n"  
                 );  
64          }          }
65  }  }
66    
67  sub run_update {  sub run_update {
68          while ( 1 ) {          while ( 1 ) {
69                  $log->print("update ready\n");  #               $log->print("update ready\n");
70                  my $json = $in->getline;                  my $json = $in->getline;
71                  die unless defined $json;                  die unless defined $json;
72                  $log->print( "run_update $json\n" );                  $log->print( "run_update $json\n" );
# Line 87  sub run_update { Line 83  sub run_update {
83    
84  sub update {  sub update {
85          my $args = shift or die "no args";          my $args = shift or die "no args";
86          $log->print( "add ",dump( $args ),"\n" );          $log->print( "update ",dump( $args ),"\n" );
87    
88          my $ret = {          my $ret = {
89                  code => 200,                  code => 200,
# Line 139  sub update { Line 135  sub update {
135          return $ret;          return $ret;
136  }  }
137    
138    =head2 query
139    
140    Implementation spec: L<http://wiki.apache.org/couchdb/ViewServer>
141    
142    =cut
143    
144    sub query {
145            my $args = shift or die "no args";
146    #       $log->print( "query ",dump( $args ),"\n" );
147    
148            sub _json {
149                    $out->print( encode_json( shift @_ ),"\n" );
150            }
151    
152            my ( $op, $doc ) = @$args;
153    
154            if ( $op eq 'add_fun' ) {
155                    $out->print( "true\n" );
156                    _json({ log => "$op $doc" });
157            } elsif ( $op eq 'reset' ) {
158                    $out->print( "true\n" );
159            } elsif ( $op eq 'map_doc' ) {
160                    $out->print( encode_json( [[[ $doc->{_id}, 'indexed' ]]] ),"\n" );
161    #               _log( dump( $args ) );
162            } else {
163                    $log->print("ERROR ",dump( $op, $doc ) );
164                    _json({ error => $op, reason => dump( $doc ) });
165            }
166    }
167    
168  =head2 search  =head2 search
169    
170  Implementation specification: L<http://wiki.apache.org/couchdb/FullTextSearch>  Implementation specification: L<http://wiki.apache.org/couchdb/FullTextSearch>
# Line 150  Implementation specification: L<http://w Line 176  Implementation specification: L<http://w
176  sub search {  sub search {
177          my $args = shift or die "no args";          my $args = shift or die "no args";
178          $log->print( "search ",dump( $args ),"\n" );          $log->print( "search ",dump( $args ),"\n" );
179    
180          my $database = $args->{db} or die "no db in ",dump( $args );          my $database = $args->{db} or die "no db in ",dump( $args );
181          my $query = $args->{query} or die "no query in ",dump( $args );          my $query = $args->{query} or die "no query in ",dump( $args );
182    

Legend:
Removed from v.12  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.26