Merge lp:~gary-wzl77/scope-aggregator/fix_1521528 into lp:scope-aggregator

Proposed by Gary.Wang
Status: Merged
Approved by: Kyle Nitzsche
Approved revision: 157
Merged at revision: 156
Proposed branch: lp:~gary-wzl77/scope-aggregator/fix_1521528
Merge into: lp:scope-aggregator
Diff against target: 153 lines (+100/-2)
4 files modified
CMakeLists.txt (+1/-1)
README.md (+33/-1)
include/query.h (+1/-0)
src/utils.cpp (+65/-0)
To merge this branch: bzr merge lp:~gary-wzl77/scope-aggregator/fix_1521528
Reviewer Review Type Date Requested Status
Kyle Nitzsche (community) Approve
Review via email: mp+279084@code.launchpad.net

Commit message

Add display_order field to enable developer to set child scopes display order for keyword scope.

Merge branch that fixes bug lp:1521528 in scope-agg.

Description of the change

Add display_order field to enable developer to set child scopes display order for keyword scope.

To post a comment you must log in.
Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

General Comment

This is an interesting feature. One of the advantages of keywords is that you do not know what scopes may be installed. Yet this feature allows you to set the order inside a keyword by scope ID. Clearly, this allows order control with keyword aggregation. Nice.

It raises the question: why not just declare them as "scope" json objects and thereby set the order absolutely. And the answer is: because keywords move the logic of what results to provide to the child scope and simplifies the aggregation. So I like it!

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

Line 31: I am unclear from this text what the display order will be when there are installed scopes listed in display_order and there are other installed scopes included through the keyword. My expectation is that scopes in display_order will always come first (if installed) and then other scopes in random order. Is that correct?

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

A question: should we also implement this for "category" > "keywords"? Note I just had to add a feature for keyword that was working in category > keywords, so maybe we should try to keep the keyword support unified in both cases.

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

So, while I love this feature and will approve, for now I'll mark as Needs Fixing to get your answers and the typo fix mentioned below.

review: Needs Fixing
Revision history for this message
Gary.Wang (gary-wzl77) wrote :

1...the answer is: because keywords move the logic of what results to provide to the child scope and simplifies the aggregation. So I like it!
A: Hah, That's also my general idea to implement this MR. :)

2.My expectation is that scopes in display_order will always come first (if installed) and then other scopes in random order. Is that correct?
A: Yes, that's correct. The testing aggreagtor can be found here. Please have a try

   bzr branch lp:~hanloon-team/hanloon/test-display-order

   Note: The "display_order" rule is only applied to children scopes in "keyword", which doesn't impact "category" or "scope" field.
   E.g. In testing bollywood aggregator, I put cinema scope at first declaration, so scope aggregator will display all children scopes of "keyword" according to display_order *under* cinema scope. If I put cinema scope declaration under "keyword", all children scopes of "keyword" will come first, then cinema scope display below "keyword".

3. A question: should we also implement this for "category" > "keywords" to keep the keyword support unified in both cases.
A: Yes, we should. Can we do it in another MR?

157. By Gary.Wang

Typo fixed.

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

looks good. Except for one doc comment. line 31 below says this:

"display_order allows developer to set child scopes display order of keyword scope. You can specify multiple scope id in the display_order and scope aggregator will display child scopes according to the order you defined in display_order. If supported child scopes are not defined in display_order, scope aggregator will display them randomly"

That ^ does not quite state clearly that: Installed keyword child scopes that are not listed in display_order are displayed after installed display_order scopes and in a indeterminate order.

Two key points: 1) state clearly that they are AFTER. 2) Please use "indeterminate" instead of any variant of "random". You can use my exact sentence if you want.

Great feature!

review: Approve
Revision history for this message
Gary.Wang (gary-wzl77) wrote :

Oh,Yes.
That's more clear. I use your sentence to explain the usage.
Thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-11-30 17:08:54 +0000
3+++ CMakeLists.txt 2015-12-02 03:32:24 +0000
4@@ -1,4 +1,4 @@
5-set(VERSION "4.1")
6+set(VERSION "4.2")
7
8 # Supress qDebug() output
9 ADD_DEFINITIONS( -DQT_NO_DEBUG_OUTPUT )
10
11=== modified file 'README.md'
12--- README.md 2015-09-14 02:37:51 +0000
13+++ README.md 2015-12-02 03:32:24 +0000
14@@ -765,7 +765,7 @@
15
16 Value: json list of objects.
17
18-Suppose you want some scopes which supports one certain keywords not to display results, you can specify scope id in the exclude_scopes and scope aggregator will not displays results of specified scopes.
19+Suppose you want some scopes which supports one certain keywords not to display results, you can specify scope id in the exclude_scopes and scope aggregator will not display results of specified scopes.
20
21 Note:This key is only supposed to be declared in a `keywords` json object, which doesn't not use a shared category.
22 e.g. amazon supports 'books' keyword, but in most cases it returns something unrelated to 'books' keyword. we can get rid of its results in the way as following.
23@@ -786,3 +786,35 @@
24 ]
25
26
27+#### `display_order` key (optional)
28+
29+Value: json list of objects.
30+
31+display_order allows developer to set child scopes display order of keyword scope. You can specify multiple scope id in the display_order and scope aggregator will display child scopes according to the order you defined in display_order. If supported child scopes are not defined in display_order, scope aggregator will display them randomly.
32+
33+Note: `display_order` must be a direct child of a `keyword`.
34+e.g. the following scopes support 'bollywood.movie' keyword,
35+ 1.Shemaroo
36+ 2.Eros
37+ 3.ZeeTV
38+ 4.Star-plus
39+
40+if we define display_order as following, shemaroo scope will be shown in the first place, then eros at 2nd place.And zeeTV and star-plus will be shown randomly
41+ "order":
42+ [
43+ {
44+ "keyword":
45+ {
46+ "keyword": "bollywood.movie",
47+ "link_to_child" : "true",
48+ "display_order" :[
49+ {
50+ "id": "com.canonical.scopes.shemaroo_shemaroo"
51+ },
52+ {
53+ "id": "com.canonical.scopes.eros_eros"
54+ }
55+ ]
56+ }
57+ }
58+ ]
59
60=== modified file 'include/query.h'
61--- include/query.h 2015-09-14 02:37:51 +0000
62+++ include/query.h 2015-12-02 03:32:24 +0000
63@@ -155,6 +155,7 @@
64 std::string dept_title_msgid;
65 bool link_to_child = false;
66 std::vector<std::string> exclude_scopes; // id of exclude scopes
67+ std::vector<std::string> display_order; // id of display order scopes
68 };
69 std::vector<std::shared_ptr<keyword>> keywords;// pulled from child_sccopes.json
70 std::map<std::string, std::shared_ptr<keyword>> id_keyword_map;//keyword id (the keyword string) to keyword instance
71
72=== modified file 'src/utils.cpp'
73--- src/utils.cpp 2015-11-20 22:22:35 +0000
74+++ src/utils.cpp 2015-12-02 03:32:24 +0000
75@@ -664,6 +664,17 @@
76 keyword_.exclude_scopes.emplace_back(id);
77 }
78 }
79+ if (keyword_o.contains("display_order"))
80+ {
81+ QJsonArray scope_a = keyword_o["display_order"].toArray();
82+
83+ for (const auto item : scope_a)
84+ {
85+ QJsonObject scope_o = item.toObject();
86+ std::string id = scope_o["id"].toString().toStdString();
87+ keyword_.display_order.emplace_back(id);
88+ }
89+ }
90
91 std::shared_ptr<keyword> kw_ptr = std::make_shared<keyword>(keyword_);
92 keywords.emplace_back(kw_ptr);
93@@ -683,6 +694,60 @@
94 {
95 if (pr.first == id)
96 {
97+ bool foundKeywod = false;
98+ for (auto kwv : keywords)
99+ {
100+ if (id == kwv->id)
101+ {
102+ foundKeywod = true;
103+
104+ int lastDisplayOrder = -1;
105+ std::vector<std::string>::iterator orderIter;
106+ std::vector<std::string> order_keyscopes;
107+ std::vector<std::string> unorder_keyscopes;
108+ for (std::string scope_id : pr.second)
109+ {
110+ bool foundScope = false;
111+ for (int i = 0; i < kwv->display_order.size() ; i++)
112+ {
113+ if ((kwv->display_order[i] +":"+ kwv->id) == scope_id)
114+ {
115+ if ( lastDisplayOrder < 0)
116+ {
117+ orderIter = order_keyscopes.insert(order_keyscopes.begin(), scope_id);
118+ }
119+ else if (i < lastDisplayOrder)
120+ {
121+ if (i < (orderIter - order_keyscopes.begin()))
122+ {
123+ orderIter = order_keyscopes.insert(order_keyscopes.begin(), scope_id);
124+ }
125+ else
126+ {
127+ orderIter = order_keyscopes.insert(orderIter, scope_id);
128+ }
129+ }
130+ else
131+ {
132+ orderIter = order_keyscopes.insert(orderIter + 1, scope_id);
133+ }
134+
135+ foundScope = true;
136+ lastDisplayOrder = i;
137+ break;
138+ }
139+ }
140+
141+ if (!foundScope) {
142+ unorder_keyscopes.emplace_back(scope_id);
143+ }
144+ }
145+
146+ scopes_ordered.insert(scopes_ordered.end(), order_keyscopes.begin(), order_keyscopes.end());
147+ scopes_ordered.insert(scopes_ordered.end(), unorder_keyscopes.begin(), unorder_keyscopes.end());
148+ }
149+ }
150+
151 for (std::string id_ : pr.second)
152 {
153 scopes_ordered.emplace_back(id_);

Subscribers

People subscribed via source and target branches

to all changes: