运用link query特性query自己的Scope中department或其它scope中的department

来源:互联网 发布:淘宝家具沙发 编辑:程序博客网 时间:2024/05/01 16:04

最近我看了一篇关于在Scope中link query的文章.坦率地说,不是特别理解,如果没有具体的例程也不知道它的作用.简单地说,就是在我们的Scope设计中,我们可以点击一个Object,他可以让我们发起另外一个不同的query.

首先,我们可以下载我们已经设计好的例程:

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

在query.cpp中,

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());    }}

我们加入了如下的语句:

        cat = reply->register_category( "Linking queries", "Linking queries" ,                                         "", sc::CategoryRenderer(CAT_RENDERER1) );        // The link icon's index is 8        pushResult( reply, &cat, 8, true);

在下面的函数中:

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() );    }   ...}

当linkquery为真时,我们把它重新定向为发起另外一个叫做com.canonical.scopes.news_unity-scope-news Scope中的dept-finance department.

运行我们的Scope:

 


当我们点击link queries下面的图片时,在news中的dept-finance将被自动query并显示结果.





0 0
原创粉丝点击