1616
1717#include < cstdint>
1818
19+ #include " client_v2/coordinator.h"
1920#include " client_v2/pretty.h"
2021#include " common/helper.h"
2122#include " fmt/format.h"
2223
24+ const int kBatchSize = 3 ;
25+
2326namespace client_v2 {
2427
2528void SetUpDocumentIndexSubCommands (CLI::App& app) {
@@ -28,6 +31,7 @@ void SetUpDocumentIndexSubCommands(CLI::App& app) {
2831 SetUpDocumentBatchAdd (app);
2932 SetUpDocumentDelete (app);
3033 SetUpDocumentSearch (app);
34+ SetUpDocumentSearchAll (app);
3135 SetUpDocumentBatchQuery (app);
3236 SetUpDocumentScanQuery (app);
3337 SetUpDocumentGetMaxId (app);
@@ -324,6 +328,69 @@ void SendDocumentSearch(DocumentSearchOptions const& opt) {
324328 Pretty::Show (response);
325329}
326330
331+ void SendDocumentSearchAll (DocumentSearchOptions const & opt) {
332+ // dingodb::pb::document::DocumentSearchRequest request;
333+ // dingodb::pb::document::DocumentSearchResponse response;
334+
335+ if (opt.query_string .empty ()) {
336+ std::cout << " query_string is empty" << std::endl;
337+ return ;
338+ }
339+
340+ auto response = SendSearchAllByStreamMode (opt);
341+ std::cout << " search all documents response:" << response.DebugString () << std::endl;
342+ Pretty::Show (response);
343+ }
344+
345+ dingodb::pb::document::DocumentSearchAllResponse SendSearchAllByStreamMode (DocumentSearchOptions const & opt) {
346+ dingodb::pb::document::DocumentSearchAllRequest request;
347+ dingodb::pb::document::DocumentSearchAllResponse response;
348+ auto * parameter = request.mutable_parameter ();
349+ parameter->set_query_string (opt.query_string );
350+ parameter->set_without_scalar_data (opt.without_scalar );
351+ parameter->set_query_unlimited (true );
352+ request.mutable_stream_meta ()->set_limit (kBatchSize );
353+ if (opt.doc_id > 0 ) {
354+ parameter->add_document_ids (opt.doc_id );
355+ }
356+ *(request.mutable_context ()) = RegionRouter::GetInstance ().GenConext (opt.region_id );
357+
358+ for (;;) {
359+ dingodb::pb::document::DocumentSearchAllResponse sub_response;
360+ // maybe current store interaction is not store node, so need reset.
361+ InteractionManager::GetInstance ().ResetStoreInteraction ();
362+ auto status = InteractionManager::GetInstance ().SendRequestWithContext (" DocumentService" , " DocumentSearchAll" ,
363+ request, sub_response);
364+ std::cout << " search all request: " << request.DebugString () << " , sub_response: " << sub_response.DebugString ()
365+ << std::endl;
366+ if (!status.ok ()) {
367+ response.mutable_error ()->set_errcode (dingodb::pb::error::Errno (status.error_code ()));
368+ response.mutable_error ()->set_errmsg (status.error_str ());
369+ break ;
370+ }
371+
372+ if (sub_response.error ().errcode () != dingodb::pb::error::OK) {
373+ *response.mutable_error () = sub_response.error ();
374+ break ;
375+ }
376+
377+ // set request stream id
378+ if (!sub_response.stream_meta ().stream_id ().empty ()) {
379+ request.mutable_stream_meta ()->set_stream_id (sub_response.stream_meta ().stream_id ());
380+ }
381+
382+ // copy data
383+ for (int i = 0 ; i < sub_response.document_with_scores_size (); ++i) {
384+ response.add_document_with_scores ()->Swap (&sub_response.mutable_document_with_scores ()->at (i));
385+ }
386+ if (!sub_response.stream_meta ().has_more ()) {
387+ break ;
388+ }
389+ }
390+
391+ return response;
392+ }
393+
327394void SendDocumentBatchQuery (DocumentBatchQueryOptions const & opt) {
328395 dingodb::pb::document::DocumentBatchQueryRequest request;
329396 dingodb::pb::document::DocumentBatchQueryResponse response;
@@ -645,6 +712,26 @@ void RunDocumentSearch(DocumentSearchOptions const& opt) {
645712 client_v2::SendDocumentSearch (opt);
646713}
647714
715+ void SetUpDocumentSearchAll (CLI::App& app) {
716+ auto opt = std::make_shared<DocumentSearchOptions>();
717+ auto * cmd = app.add_subcommand (" DocumentSearchAll" , " Document search all documents" )->group (" Document Commands" );
718+ cmd->add_option (" --coor_url" , opt->coor_url , " Coordinator url, default:file://./coor_list" );
719+ cmd->add_option (" --region_id" , opt->region_id , " Request parameter region id" )->required ();
720+ cmd->add_option (" --query_string" , opt->query_string , " Request parameter query_string" )->required ();
721+ cmd->add_option (" --without_scalar" , opt->without_scalar , " Request parameter without_scalar" )
722+ ->default_val (false )
723+ ->default_str (" false" );
724+ cmd->add_option (" --doc_id" , opt->doc_id , " Request parameter alive id" );
725+ cmd->callback ([opt]() { RunDocumentSearchAll (*opt); });
726+ }
727+
728+ void RunDocumentSearchAll (DocumentSearchOptions const & opt) {
729+ if (!SetUpStore (opt.coor_url , {}, opt.region_id )) {
730+ exit (-1 );
731+ }
732+ client_v2::SendDocumentSearchAll (opt);
733+ }
734+
648735void SetUpDocumentBatchQuery (CLI::App& app) {
649736 auto opt = std::make_shared<DocumentBatchQueryOptions>();
650737 auto * cmd = app.add_subcommand (" DocumentBatchQuery" , " Document batch query" )->group (" Document Commands" );
0 commit comments