5 # http://wiki.apache.org/couchdb/ExternalProcesses
7 # curl 'http://localhost:5984/drzb2011/_kinosearch?q=a&include_docs=true'
9 use KinoSearch::Search::IndexSearcher;
11 use Data::Dump qw(dump);
15 our $json = Mojo::JSON->new;
17 open(my $log, '>>', '/tmp/couchdb-external-kinosearch.log');
21 my $request = $json->decode($_);
22 print $log "<<< $_\n";
29 if ( my $q = $request->{query}->{q} ) {
31 my $searcher = KinoSearch::Search::IndexSearcher->new(
32 index => '/tmp/kinosearch.' . $request->{info}->{db_name},
35 my $hits = $searcher->hits( query => $q );
37 $response->{json}->{total_hits} = $hits->total_hits;
39 while ( my $hit = $hits->next ) {
43 score => $hit->get_score,
45 $r->{doc} = $json->decode( $hit->{doc} ) if exists $request->{query}->{include_docs};
46 push @{ $response->{json}->{hits} }, $r;
50 $response->{json}->{error} = "no query found";
53 my $send = $json->encode($response);
55 print $log ">>> $send\n";
60 ; insert following into /etc/couchdb/local.ini:
66 kinosearch = /srv/angular-mojolicious/couchdb-external-kinosearch.pl
69 _kinosearch = {couch_httpd_external, handle_external_req, <<"kinosearch">>}