Merge lp:~rainct/zeitgeist/fts-sorting into lp:~zeitgeist/zeitgeist/bluebird
- fts-sorting
- Merge into bluebird
Proposed by
Siegfried Gevatter
Status: | Merged |
---|---|
Approved by: | Michal Hruby |
Approved revision: | no longer in the source branch. |
Merged at revision: | 438 |
Proposed branch: | lp:~rainct/zeitgeist/fts-sorting |
Merge into: | lp:~zeitgeist/zeitgeist/bluebird |
Diff against target: |
296 lines (+108/-51) 3 files modified
extensions/fts++/indexer.cpp (+19/-8) src/datamodel.vala (+51/-1) src/db-reader.vala (+38/-42) |
To merge this branch: | bzr merge lp:~rainct/zeitgeist/fts-sorting |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michal Hruby (community) | Approve | ||
Review via email: mp+97985@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
lp:~rainct/zeitgeist/fts-sorting
updated
- 433. By Seif Lotfy
-
Merged Trever's fixes for bug 953041
- 434. By Seif Lotfy
-
DS-Registry: fix vala 0.16 incompatiblity
- 435. By Seif Lotfy
-
Storage Monitor Extensions: fix bug lp:950983
- 436. By Seif Lotfy
-
Storage Monitor Extension: refactor the INSERT OR REPLACE statement
Revision history for this message
Michal Hruby (mhr3) wrote : | # |
But perhaps the is_asc method should be a (static?) method of ResultType.
lp:~rainct/zeitgeist/fts-sorting
updated
- 437. By Siegfried Gevatter
-
Fix typo in table-lookup comment.
- 438. By Siegfried Gevatter
-
Refactor ResultType sorting and fix FTS++'s Search() with LeastRecent*
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'extensions/fts++/indexer.cpp' |
2 | --- extensions/fts++/indexer.cpp 2012-03-16 20:03:05 +0000 |
3 | +++ extensions/fts++/indexer.cpp 2012-03-19 20:01:23 +0000 |
4 | @@ -778,7 +778,9 @@ |
5 | } |
6 | else |
7 | { |
8 | - enquire->set_sort_by_value (VALUE_TIMESTAMP, true); |
9 | + bool reversed_sort = not |
10 | + zeitgeist_result_type_is_sort_order_asc (result_type); |
11 | + enquire->set_sort_by_value (VALUE_TIMESTAMP, reversed_sort); |
12 | } |
13 | |
14 | if (result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS || |
15 | @@ -786,7 +788,20 @@ |
16 | result_type == ZEITGEIST_RESULT_TYPE_MOST_POPULAR_SUBJECTS || |
17 | result_type == ZEITGEIST_RESULT_TYPE_LEAST_POPULAR_SUBJECTS) |
18 | { |
19 | - enquire->set_collapse_key (VALUE_URI_HASH); |
20 | + enquire->set_collapse_key (VALUE_URI_HASH); |
21 | + } |
22 | + else if (result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_ORIGIN || |
23 | + result_type == ZEITGEIST_RESULT_TYPE_LEAST_RECENT_ORIGIN || |
24 | + result_type == ZEITGEIST_RESULT_TYPE_MOST_POPULAR_ORIGIN || |
25 | + result_type == ZEITGEIST_RESULT_TYPE_LEAST_POPULAR_ORIGIN) |
26 | + { |
27 | + // FIXME: not really correct but close :) |
28 | + enquire->set_collapse_key (VALUE_URI_HASH); |
29 | + } |
30 | + else if (result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS || |
31 | + result_type == ZEITGEIST_RESULT_TYPE_LEAST_RECENT_EVENTS) |
32 | + { |
33 | + enquire->set_collapse_key (VALUE_EVENT_ID); |
34 | } |
35 | |
36 | Xapian::Query q(query_parser->parse_query (query_string, QUERY_PARSER_FLAGS)); |
37 | @@ -1096,12 +1111,8 @@ |
38 | return NULL; |
39 | } |
40 | |
41 | - bool reversed_sort = |
42 | - result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS || |
43 | - result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS || |
44 | - result_type == ZEITGEIST_RESULT_TYPE_MOST_POPULAR_SUBJECTS || |
45 | - result_type == ZEITGEIST_RESULT_TYPE_MOST_RECENT_ORIGIN || |
46 | - result_type == ZEITGEIST_RESULT_TYPE_MOST_POPULAR_ORIGIN; |
47 | + bool reversed_sort = not |
48 | + zeitgeist_result_type_is_sort_order_asc (result_type); |
49 | |
50 | if (result_type == RELEVANCY_RESULT_TYPE) |
51 | { |
52 | |
53 | === modified file 'src/datamodel.vala' |
54 | --- src/datamodel.vala 2012-02-18 21:33:57 +0000 |
55 | +++ src/datamodel.vala 2012-03-19 20:01:23 +0000 |
56 | @@ -230,10 +230,60 @@ |
57 | // different origin ordered |
58 | // by the popularity of the |
59 | // origins |
60 | - LEAST_POPULAR_EVENT_ORIGIN = 30, // The last event of each |
61 | + LEAST_POPULAR_EVENT_ORIGIN = 30; // The last event of each |
62 | // different origin, ordered |
63 | // ascendingly by the |
64 | // popularity of the origin |
65 | + |
66 | + /* |
67 | + * Returns true if the results for the given result_type will be sorted |
68 | + * ascendantly by date, false if they'll be sorted descendingly. |
69 | + **/ |
70 | + public static bool is_sort_order_asc (ResultType result_type) |
71 | + { |
72 | + switch (result_type) |
73 | + { |
74 | + // FIXME: Why are LEAST_POPULAR_* using ASC? |
75 | + case ResultType.LEAST_RECENT_EVENTS: |
76 | + case ResultType.LEAST_RECENT_EVENT_ORIGIN: |
77 | + case ResultType.LEAST_POPULAR_EVENT_ORIGIN: |
78 | + case ResultType.LEAST_RECENT_SUBJECTS: |
79 | + case ResultType.LEAST_POPULAR_SUBJECTS: |
80 | + case ResultType.LEAST_RECENT_CURRENT_URI: |
81 | + case ResultType.LEAST_POPULAR_CURRENT_URI: |
82 | + case ResultType.LEAST_RECENT_ACTOR: |
83 | + case ResultType.LEAST_POPULAR_ACTOR: |
84 | + case ResultType.OLDEST_ACTOR: |
85 | + case ResultType.LEAST_RECENT_ORIGIN: |
86 | + case ResultType.LEAST_POPULAR_ORIGIN: |
87 | + case ResultType.LEAST_RECENT_SUBJECT_INTERPRETATION: |
88 | + case ResultType.LEAST_POPULAR_SUBJECT_INTERPRETATION: |
89 | + case ResultType.LEAST_RECENT_MIMETYPE: |
90 | + case ResultType.LEAST_POPULAR_MIMETYPE: |
91 | + return true; |
92 | + |
93 | + case ResultType.MOST_RECENT_EVENTS: |
94 | + case ResultType.MOST_RECENT_EVENT_ORIGIN: |
95 | + case ResultType.MOST_POPULAR_EVENT_ORIGIN: |
96 | + case ResultType.MOST_RECENT_SUBJECTS: |
97 | + case ResultType.MOST_POPULAR_SUBJECTS: |
98 | + case ResultType.MOST_RECENT_CURRENT_URI: |
99 | + case ResultType.MOST_POPULAR_CURRENT_URI: |
100 | + case ResultType.MOST_RECENT_ACTOR: |
101 | + case ResultType.MOST_POPULAR_ACTOR: |
102 | + case ResultType.MOST_RECENT_ORIGIN: |
103 | + case ResultType.MOST_POPULAR_ORIGIN: |
104 | + case ResultType.MOST_RECENT_SUBJECT_INTERPRETATION: |
105 | + case ResultType.MOST_POPULAR_SUBJECT_INTERPRETATION: |
106 | + case ResultType.MOST_RECENT_MIMETYPE: |
107 | + case ResultType.MOST_POPULAR_MIMETYPE: |
108 | + return false; |
109 | + |
110 | + default: |
111 | + warning ("Unrecognized ResultType: %u", (uint) result_type); |
112 | + return true; |
113 | + } |
114 | + } |
115 | } |
116 | |
117 | /* |
118 | |
119 | === modified file 'src/db-reader.vala' |
120 | --- src/db-reader.vala 2012-03-17 14:47:09 +0000 |
121 | +++ src/db-reader.vala 2012-03-19 20:01:23 +0000 |
122 | @@ -173,109 +173,107 @@ |
123 | switch (result_type) |
124 | { |
125 | case ResultType.MOST_RECENT_EVENTS: |
126 | - sql += where_sql + " ORDER BY timestamp DESC"; |
127 | + sql += where_sql + " ORDER BY "; |
128 | break; |
129 | case ResultType.LEAST_RECENT_EVENTS: |
130 | - sql += where_sql + " ORDER BY timestamp ASC"; |
131 | + sql += where_sql + " ORDER BY "; |
132 | break; |
133 | case ResultType.MOST_RECENT_EVENT_ORIGIN: |
134 | - sql += group_and_sort ("origin", where_sql, false); |
135 | + sql += group_and_sort ("origin", where_sql); |
136 | break; |
137 | case ResultType.LEAST_RECENT_EVENT_ORIGIN: |
138 | - sql += group_and_sort ("origin", where_sql, true); |
139 | + sql += group_and_sort ("origin", where_sql); |
140 | break; |
141 | case ResultType.MOST_POPULAR_EVENT_ORIGIN: |
142 | - sql += group_and_sort ("origin", where_sql, false, false); |
143 | + sql += group_and_sort ("origin", where_sql, false); |
144 | break; |
145 | case ResultType.LEAST_POPULAR_EVENT_ORIGIN: |
146 | - sql += group_and_sort ("origin", where_sql, true, true); |
147 | + sql += group_and_sort ("origin", where_sql, true); |
148 | break; |
149 | case ResultType.MOST_RECENT_SUBJECTS: |
150 | - sql += group_and_sort ("subj_id", where_sql, false); |
151 | + sql += group_and_sort ("subj_id", where_sql); |
152 | break; |
153 | case ResultType.LEAST_RECENT_SUBJECTS: |
154 | - sql += group_and_sort ("subj_id", where_sql, true); |
155 | + sql += group_and_sort ("subj_id", where_sql); |
156 | break; |
157 | case ResultType.MOST_POPULAR_SUBJECTS: |
158 | - sql += group_and_sort ("subj_id", where_sql, false, false); |
159 | + sql += group_and_sort ("subj_id", where_sql, false); |
160 | break; |
161 | case ResultType.LEAST_POPULAR_SUBJECTS: |
162 | - sql += group_and_sort ("subj_id", where_sql, true, true); |
163 | + sql += group_and_sort ("subj_id", where_sql, true); |
164 | break; |
165 | case ResultType.MOST_RECENT_CURRENT_URI: |
166 | - sql += group_and_sort ("subj_id_current", where_sql, false); |
167 | + sql += group_and_sort ("subj_id_current", where_sql); |
168 | break; |
169 | case ResultType.LEAST_RECENT_CURRENT_URI: |
170 | - sql += group_and_sort ("subj_id_current", where_sql, true); |
171 | + sql += group_and_sort ("subj_id_current", where_sql); |
172 | break; |
173 | case ResultType.MOST_POPULAR_CURRENT_URI: |
174 | - sql += group_and_sort ("subj_id_current", where_sql, |
175 | - false, false); |
176 | + sql += group_and_sort ("subj_id_current", where_sql, false); |
177 | break; |
178 | case ResultType.LEAST_POPULAR_CURRENT_URI: |
179 | - sql += group_and_sort ("subj_id_current", where_sql, |
180 | - true, true); |
181 | + sql += group_and_sort ("subj_id_current", where_sql, true); |
182 | break; |
183 | case ResultType.MOST_RECENT_ACTOR: |
184 | - sql += group_and_sort ("actor", where_sql, false); |
185 | + sql += group_and_sort ("actor", where_sql); |
186 | break; |
187 | case ResultType.LEAST_RECENT_ACTOR: |
188 | - sql += group_and_sort ("actor", where_sql, true); |
189 | + sql += group_and_sort ("actor", where_sql); |
190 | break; |
191 | case ResultType.MOST_POPULAR_ACTOR: |
192 | - sql += group_and_sort ("actor", where_sql, false, false); |
193 | + sql += group_and_sort ("actor", where_sql, false); |
194 | break; |
195 | case ResultType.LEAST_POPULAR_ACTOR: |
196 | - sql += group_and_sort ("actor", where_sql, true, true); |
197 | + sql += group_and_sort ("actor", where_sql, true); |
198 | break; |
199 | case ResultType.OLDEST_ACTOR: |
200 | - sql += group_and_sort ("actor", where_sql, true, null, "min"); |
201 | + sql += group_and_sort ("actor", where_sql, null, "min"); |
202 | break; |
203 | case ResultType.MOST_RECENT_ORIGIN: |
204 | - sql += group_and_sort ("subj_origin", where_sql, false); |
205 | + sql += group_and_sort ("subj_origin", where_sql); |
206 | break; |
207 | case ResultType.LEAST_RECENT_ORIGIN: |
208 | - sql += group_and_sort ("subj_origin", where_sql, true); |
209 | + sql += group_and_sort ("subj_origin", where_sql); |
210 | break; |
211 | case ResultType.MOST_POPULAR_ORIGIN: |
212 | - sql += group_and_sort ("subj_origin", where_sql, false, false); |
213 | + sql += group_and_sort ("subj_origin", where_sql, false); |
214 | break; |
215 | case ResultType.LEAST_POPULAR_ORIGIN: |
216 | - sql += group_and_sort ("subj_origin", where_sql, true, true); |
217 | + sql += group_and_sort ("subj_origin", where_sql, true); |
218 | break; |
219 | case ResultType.MOST_RECENT_SUBJECT_INTERPRETATION: |
220 | - sql += group_and_sort ("subj_interpretation", where_sql, false); |
221 | + sql += group_and_sort ("subj_interpretation", where_sql); |
222 | break; |
223 | case ResultType.LEAST_RECENT_SUBJECT_INTERPRETATION: |
224 | - sql += group_and_sort ("subj_interpretation", where_sql, true); |
225 | + sql += group_and_sort ("subj_interpretation", where_sql); |
226 | break; |
227 | case ResultType.MOST_POPULAR_SUBJECT_INTERPRETATION: |
228 | - sql += group_and_sort ("subj_interpretation", where_sql, |
229 | - false, false); |
230 | + sql += group_and_sort ("subj_interpretation", where_sql, false); |
231 | break; |
232 | case ResultType.LEAST_POPULAR_SUBJECT_INTERPRETATION: |
233 | - sql += group_and_sort ("subj_interpretation", where_sql, |
234 | - true, true); |
235 | + sql += group_and_sort ("subj_interpretation", where_sql, true); |
236 | break; |
237 | case ResultType.MOST_RECENT_MIMETYPE: |
238 | - sql += group_and_sort ("subj_mimetype", where_sql, false); |
239 | + sql += group_and_sort ("subj_mimetype", where_sql); |
240 | break; |
241 | case ResultType.LEAST_RECENT_MIMETYPE: |
242 | - sql += group_and_sort ("subj_mimetype", where_sql, true); |
243 | + sql += group_and_sort ("subj_mimetype", where_sql); |
244 | break; |
245 | case ResultType.MOST_POPULAR_MIMETYPE: |
246 | - sql += group_and_sort ("subj_mimetype", where_sql, |
247 | - false, false); |
248 | + sql += group_and_sort ("subj_mimetype", where_sql, false); |
249 | break; |
250 | case ResultType.LEAST_POPULAR_MIMETYPE: |
251 | - sql += group_and_sort ("subj_mimetype", where_sql, |
252 | - true, true); |
253 | + sql += group_and_sort ("subj_mimetype", where_sql, true); |
254 | break; |
255 | default: |
256 | string error_message = "Invalid ResultType."; |
257 | warning (error_message); |
258 | throw new EngineError.INVALID_ARGUMENT (error_message); |
259 | } |
260 | + |
261 | + // complete the sort rule |
262 | + bool time_asc = ResultType.is_sort_order_asc ((ResultType) result_type); |
263 | + sql += " timestamp %s".printf ((time_asc) ? "ASC" : "DESC"); |
264 | |
265 | int rc; |
266 | Sqlite.Statement stmt; |
267 | @@ -578,10 +576,8 @@ |
268 | |
269 | // Used by find_event_ids |
270 | private string group_and_sort (string field, string where_sql, |
271 | - bool time_asc=false, bool? count_asc=null, |
272 | - string aggregation_type="max") |
273 | + bool? count_asc=null, string aggregation_type="max") |
274 | { |
275 | - string time_sorting = (time_asc) ? "ASC" : "DESC"; |
276 | string aggregation_sql = ""; |
277 | string order_sql = ""; |
278 | |
279 | @@ -599,7 +595,7 @@ |
280 | FROM event_view %s |
281 | GROUP BY %s) |
282 | GROUP BY %s |
283 | - ORDER BY %s timestamp %s |
284 | + ORDER BY %s |
285 | """.printf ( |
286 | field, |
287 | aggregation_type, |
288 | @@ -607,7 +603,7 @@ |
289 | where_sql, |
290 | field, |
291 | field, |
292 | - order_sql, time_sorting); |
293 | + order_sql); |
294 | } |
295 | |
296 | // Used by find_event_ids |
Looks fine.