I recently read an article about link Query in Scope. Frankly, I don’t really understand it, and I don’t know what it does without a specific routine. To put it simply, in our Scope design, we can click on an Object, which allows us to initiate a different Query.

First, we can download the routines we have designed:

$ git clone https://github.com/liu-xiao-guo/scopetemplates_release
Copy the code

CPP, in the query.

void Query::run(sc::SearchReplyProxy const& reply) { try { // The default is vertical pushResult(reply, CAT_RENDERER1, 1); pushResult(reply, CAT_RENDERER101, 101); pushResult(reply, CAT_RENDERER2, 2); pushResult(reply, CAT_RENDERER3, 3); pushResult(reply, CAT_RENDERER4, 4); pushResult(reply, CAT_RENDERER5, 5); pushResult(reply, CAT_RENDERER6, 6); pushResult(reply, CAT_RENDERER7, 7); pushResult(reply, CAT_RENDERER10, 10); pushResult(reply, CAT_RENDERER11, 11); int count = images_.count(); auto cat = reply->register_category( "Grid", "Grid" , "", sc::CategoryRenderer(CAT_RENDERER8) ); for ( int i = 0; i < count/2; i ++ ) { pushResult( reply, &cat, i); } cat = reply->register_category( "Carousel", "Carousel" , "", sc::CategoryRenderer(CAT_RENDERER9) ); for ( int i = 0; i < count; i ++ ) { pushResult( reply, &cat, i); } cat = reply->register_category( "vertical-journal", "vertical-journal" , "", sc::CategoryRenderer(CAT_RENDERER12) ); for ( int i = 0; i < count; i ++ ) { pushResult( reply, &cat, i); } cat = reply->register_category( "horizontal-list", "horizontal-list" , "", sc::CategoryRenderer(CAT_RENDERER13) ); for ( int i = 0; i < count; i ++ ) { pushResult( reply, &cat, i); } cat = reply->register_category( "Linking queries", "Linking queries" , "", sc::CategoryRenderer(CAT_RENDERER1) ); // The link icon's index is 8 pushResult( reply, &cat, 8, true); pushResult(reply, CR_CAROUSEL, 12); } catch (domain_error &e) { // Handle exceptions being thrown by the client API cerr << e.what() << endl; reply->error(current_exception()); }}Copy the code

We added the following statement:

        cat = reply->register_category( "Linking queries", "Linking queries" ,
                                         "", sc::CategoryRenderer(CAT_RENDERER1) );

        // The link icon's index is 8
        pushResult( reply, &cat, 8, true);
Copy the code

In the following function:

void Query::pushResult(sc::SearchReplyProxy const& reply,
                       const std::shared_ptr<const Category>*cat, int i, bool linkquery) { stringstream ss; ss << i; string str = ss.str(); sc::CategorisedResult r(*cat); // If linkquery is true, we need to redirect it to another scope or // a scope department id locally in this scope if ( linkquery ) { sc::CannedQuery second_query("com.canonical.scopes.news_unity-scope-news"); second_query.set_department_id("dept-finance"); r.set_uri(second_query.to_uri()); } else { r.set_uri( URI.toStdString() ); }... }Copy the code

When linkquery is true, we call it redirected to launch another com. Canonical. Scopes. News_unity – scope – news, the scope of the dept – finance department.

Run our Scope:

 \

\

When we click on the image below link Queries, dept-Finance in news will be automatically queried and the results displayed.

\

\

\

\