virtual void GetSong(const proto::GetSongRequest& request,
                      rpcz::reply<proto::GetSongResponse> reply) {
   cout << "Got request for '" << request.id() << "'" << endl;
   proto::GetSongResponse response;
   response.set_title("result1 for ");
   reply.send(response);
 }
 virtual void FindSongs(const proto::FindSongsRequest& request, rpcz::reply<proto::FindSongsResponse> reply) {
   cout << "FindSongs with query: " << request.query() << endl;
   proto::FindSongsResponse response;
   searchSongs(request, &response);
   cout << "Rcvd " << response.song_size() << " songs" << endl;
   reply.send(response);
 }
Exemple #3
0
void IndexSearch::wordQuery(const WordQuery& request, rpcz::reply<QueryResult> reply)
{
    implementation& impl = **this;
    try {
        if (!impl.store)
            BOOST_THROW_EXCEPTION(common_exception()
                << errinfo_rpc_code(::rpc_error::INVALID_STORE)
                << errinfo_message("Store is not open"));

        std::cout << "Searching for '" << request.word() << "', k=" << request.maxcorrections() << std::endl;
        auto index = impl.store->index();
        auto db = impl.store->db();
        ::indexer::index::results_t results;
        index->search(request.word(), request.maxcorrections(), true, results);
        bool keys_only = request.options().keysonly();
        QueryResult pb_results;
        pb_results.set_exact_total(results.size());
        for (std::string const& result : results) {
            IndexRecord* record = pb_results.add_values();
            std::cout << "  result: " << result << std::endl;
            record->set_key(result);
            if (!keys_only) {
                std::string const& s = db->get(result);
                record->mutable_value()->ParseFromString(s);
            } else {
                record->mutable_value()->Clear();
            }
        }
        reply.send(pb_results);
    } RPC_REPORT_EXCEPTIONS(reply)
}