--- lib/CouchDB/Estraier.pm 2008/08/09 16:10:05 12 +++ lib/CouchDB/Estraier.pm 2008/08/09 23:40:19 13 @@ -37,7 +37,7 @@ #my $log = IO::Handle->new; #my $log = IO::Handle->new_from_fd(\*STDERR, 'w'); -$log = IO::File->new( "> $log" ) || die "can't open $log: $!"; +$log = IO::File->new( ">> $log" ) || die "can't open $log: $!"; $log->autoflush( 1 ); $log->print("c: ", dump($c), "\n" ); # if $c->{debug}; @@ -46,7 +46,7 @@ my $out = IO::Handle->new_from_fd(\*STDOUT, 'w'); $out->autoflush( 1 ); -=head2 run_search +=head2 run_query Process command line options and start helper @@ -54,23 +54,19 @@ =cut -sub run_search { +sub run_query { while ( 1 ) { - $log->print("search ready\n"); +# $log->print("query ready\n"); my $json = $in->getline; die unless defined $json; - $log->print( "run_search $json\n" ); - $out->print( - encode_json( - search( decode_json( $json ) ) - ) ,"\n" - ); + $log->print( "run_query $json\n" ); + query( decode_json( $json ) ) } } sub run_update { while ( 1 ) { - $log->print("update ready\n"); +# $log->print("update ready\n"); my $json = $in->getline; die unless defined $json; $log->print( "run_update $json\n" ); @@ -87,7 +83,7 @@ sub update { my $args = shift or die "no args"; - $log->print( "add ",dump( $args ),"\n" ); + $log->print( "update ",dump( $args ),"\n" ); my $ret = { code => 200, @@ -139,6 +135,36 @@ return $ret; } +=head2 query + +Implementation spec: L + +=cut + +sub query { + my $args = shift or die "no args"; +# $log->print( "query ",dump( $args ),"\n" ); + + sub _json { + $out->print( encode_json( shift @_ ),"\n" ); + } + + my ( $op, $doc ) = @$args; + + if ( $op eq 'add_fun' ) { + $out->print( "true\n" ); + _json({ log => "$op $doc" }); + } elsif ( $op eq 'reset' ) { + $out->print( "true\n" ); + } elsif ( $op eq 'map_doc' ) { + $out->print( encode_json( [[[ $doc->{_id}, 'indexed' ]]] ),"\n" ); +# _log( dump( $args ) ); + } else { + $log->print("ERROR ",dump( $op, $doc ) ); + _json({ error => $op, reason => dump( $doc ) }); + } +} + =head2 search Implementation specification: L @@ -150,6 +176,7 @@ sub search { my $args = shift or die "no args"; $log->print( "search ",dump( $args ),"\n" ); + my $database = $args->{db} or die "no db in ",dump( $args ); my $query = $args->{query} or die "no query in ",dump( $args );