Merge lp:~rainct/zeitgeist/fts-current-uri into lp:~zeitgeist/zeitgeist/bluebird
- fts-current-uri
- Merge into bluebird
Proposed by
Siegfried Gevatter
Status: | Merged |
---|---|
Approved by: | Michal Hruby |
Approved revision: | 431 |
Merged at revision: | 431 |
Proposed branch: | lp:~rainct/zeitgeist/fts-current-uri |
Merge into: | lp:~zeitgeist/zeitgeist/bluebird |
Diff against target: |
859 lines (+317/-244) 3 files modified
extensions/fts++/indexer.cpp (+16/-6) extensions/fts++/test/test-indexer.cpp (+300/-237) test/dbus/engine-test.py (+1/-1) |
To merge this branch: | bzr merge lp:~rainct/zeitgeist/fts-current-uri |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michal Hruby (community) | Approve | ||
Review via email: mp+97655@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote : | # |
Revision history for this message
Michal Hruby (mhr3) wrote : | # |
The boolean terms we're adding to the document should also use current_uri. As for CompileEventFil
review:
Needs Fixing
- 429. By Siegfried Gevatter
-
FTS++: Change to current_uri in some more places. Add random test cases.
- 430. By Siegfried Gevatter
-
FTS++: some more test cases and add a couple utility functions
- 431. By Siegfried Gevatter
-
FTS++: more test stuff (add more asserts, extend {Most,Least}Recent tests,
introduce new helper function)
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-14 12:31:51 +0000 |
3 | +++ extensions/fts++/indexer.cpp 2012-03-16 18:46:19 +0000 |
4 | @@ -262,7 +262,10 @@ |
5 | for (unsigned j = 0; j < subjects->len; j++) |
6 | { |
7 | ZeitgeistSubject *subject = (ZeitgeistSubject*) g_ptr_array_index (subjects, j); |
8 | + // For backwards compatibility, we still check URI |
9 | val = zeitgeist_subject_get_uri (subject); |
10 | + if (!val || val[0] == '\0') |
11 | + val = zeitgeist_subject_get_current_uri (subject); |
12 | if (val && val[0] != '\0') |
13 | tmpl.push_back ("zgsu:" + StringUtils::MangleUri (val)); |
14 | |
15 | @@ -344,7 +347,7 @@ |
16 | for (unsigned j = 0; j < subjects->len; j++) |
17 | { |
18 | ZeitgeistSubject *subject = (ZeitgeistSubject*) g_ptr_array_index (subjects, j); |
19 | - val = zeitgeist_subject_get_uri (subject); |
20 | + val = zeitgeist_subject_get_current_uri (subject); |
21 | if (val && val[0] != '\0') |
22 | doc.add_boolean_term (StringUtils::Truncate (FILTER_PREFIX_SUBJECT_URI + StringUtils::MangleUri (val))); |
23 | |
24 | @@ -928,12 +931,13 @@ |
25 | if (subjects == NULL) continue; |
26 | for (unsigned j = 0; j < subjects->len; j++) |
27 | { |
28 | - const gchar *subj_uri = zeitgeist_subject_get_uri ((ZeitgeistSubject*) subjects->pdata[j]); |
29 | + const gchar *subj_uri = zeitgeist_subject_get_current_uri ( |
30 | + (ZeitgeistSubject*) subjects->pdata[j]); |
31 | if (subj_uri == NULL) continue; |
32 | remapper[subj_uri] = event_id; |
33 | ZeitgeistEvent *event = zeitgeist_event_new (); |
34 | ZeitgeistSubject *subject = zeitgeist_subject_new (); |
35 | - zeitgeist_subject_set_uri (subject, subj_uri); |
36 | + zeitgeist_subject_set_current_uri (subject, subj_uri); |
37 | zeitgeist_event_add_subject (event, subject); // FIXME: leaks? |
38 | g_ptr_array_add (event_templates, event); |
39 | } |
40 | @@ -976,7 +980,8 @@ |
41 | if (subjects == NULL) continue; |
42 | for (unsigned j = 0; j < subjects->len; j++) |
43 | { |
44 | - const gchar *subj_uri = zeitgeist_subject_get_uri ((ZeitgeistSubject*) subjects->pdata[j]); |
45 | + const gchar *subj_uri = zeitgeist_subject_get_current_uri ( |
46 | + (ZeitgeistSubject*) subjects->pdata[j]); |
47 | if (subj_uri == NULL) continue; |
48 | relevancy_map[event_id] = relevancy_map[remapper[subj_uri]]; |
49 | } |
50 | @@ -1259,7 +1264,6 @@ |
51 | { |
52 | try |
53 | { |
54 | - // FIXME: we need to special case MOVE_EVENTs |
55 | const gchar *val; |
56 | guint event_id = zeitgeist_event_get_id (event); |
57 | g_return_if_fail (event_id > 0); |
58 | @@ -1288,7 +1292,13 @@ |
59 | ZeitgeistSubject *subject; |
60 | subject = (ZeitgeistSubject*) g_ptr_array_index (subjects, i); |
61 | |
62 | - val = zeitgeist_subject_get_uri (subject); |
63 | + // We use current_uri (vs. uri) where since we care about real stuff, |
64 | + // not whatever happened some time ago. |
65 | + // |
66 | + // This will most likely still be the same as URI (unless something |
67 | + // triggers a reindexation of the DB), but at least MOVE_EVENTS |
68 | + // will have the updated URI. |
69 | + val = zeitgeist_subject_get_current_uri (subject); |
70 | if (val == NULL || val[0] == '\0') continue; |
71 | |
72 | std::string uri(val); |
73 | |
74 | === modified file 'extensions/fts++/test/test-indexer.cpp' |
75 | --- extensions/fts++/test/test-indexer.cpp 2012-03-14 15:47:20 +0000 |
76 | +++ extensions/fts++/test/test-indexer.cpp 2012-03-16 18:46:19 +0000 |
77 | @@ -62,6 +62,30 @@ |
78 | g_object_unref (fix->db); |
79 | } |
80 | |
81 | +static void |
82 | +assert_nth_result_has_id (GPtrArray* results, guint n, guint32 event_id) |
83 | +{ |
84 | + g_assert_cmpuint (n, <, results->len); |
85 | + ZeitgeistEvent *event = (ZeitgeistEvent*) results->pdata[n]; |
86 | + g_assert (event); |
87 | + g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
88 | +} |
89 | + |
90 | +// This function only supports events with a single subject, |
91 | +// since that's enough for the tests in this file. |
92 | +static void |
93 | +assert_nth_result_has_text (GPtrArray* results, int n, const char *text) |
94 | +{ |
95 | + g_assert_cmpuint (n, <, results->len); |
96 | + ZeitgeistEvent *event = (ZeitgeistEvent*) results->pdata[n]; |
97 | + g_assert (event); |
98 | + g_assert_cmpint (zeitgeist_event_num_subjects (event), ==, 1); |
99 | + ZeitgeistSubject *subject = (ZeitgeistSubject*) |
100 | + g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); |
101 | + g_assert (subject); |
102 | + g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, text); |
103 | +} |
104 | + |
105 | static ZeitgeistEvent* create_test_event1 (void) |
106 | { |
107 | ZeitgeistEvent *event = zeitgeist_event_new (); |
108 | @@ -131,7 +155,7 @@ |
109 | zeitgeist_subject_set_interpretation (subject, ZEITGEIST_NFO_PRESENTATION); |
110 | zeitgeist_subject_set_manifestation (subject, ZEITGEIST_NFO_FILE_DATA_OBJECT); |
111 | zeitgeist_subject_set_uri (subject, "file:///home/username/Documents/my_fabulous_presentation.pdf"); |
112 | - zeitgeist_subject_set_text (subject, NULL); |
113 | + zeitgeist_subject_set_text (subject, "test texts"); |
114 | zeitgeist_subject_set_mimetype (subject, "application/pdf"); |
115 | |
116 | zeitgeist_event_set_interpretation (event, ZEITGEIST_ZG_MODIFY_EVENT); |
117 | @@ -191,7 +215,7 @@ |
118 | zeitgeist_subject_set_interpretation (subject, ZEITGEIST_NFO_PRESENTATION); |
119 | zeitgeist_subject_set_manifestation (subject, ZEITGEIST_NFO_FILE_DATA_OBJECT); |
120 | zeitgeist_subject_set_uri (subject, "file:///home/username/directory-with-dashes/and.dot/%C4%8C%20some-intl/CamelCasePresentation.pdf"); |
121 | - zeitgeist_subject_set_text (subject, NULL); |
122 | + zeitgeist_subject_set_text (subject, "some more texts"); |
123 | zeitgeist_subject_set_mimetype (subject, "application/pdf"); |
124 | |
125 | zeitgeist_event_set_interpretation (event, ZEITGEIST_ZG_MODIFY_EVENT); |
126 | @@ -203,6 +227,27 @@ |
127 | return event; |
128 | } |
129 | |
130 | +static ZeitgeistEvent* create_test_event8 (void) |
131 | +{ |
132 | + ZeitgeistEvent *event = zeitgeist_event_new (); |
133 | + ZeitgeistSubject *subject = zeitgeist_subject_new (); |
134 | + |
135 | + zeitgeist_subject_set_interpretation (subject, ZEITGEIST_NFO_PRESENTATION); |
136 | + zeitgeist_subject_set_manifestation (subject, ZEITGEIST_NFO_FILE_DATA_OBJECT); |
137 | + zeitgeist_subject_set_uri (subject, "file:///home/username/Documents/my_fabulous_presentation.pdf"); |
138 | + zeitgeist_subject_set_current_uri (subject, "file:///home/username/Awesome.pdf"); |
139 | + zeitgeist_subject_set_text (subject, "some more textt about a presentation or something"); |
140 | + zeitgeist_subject_set_mimetype (subject, "application/pdf"); |
141 | + |
142 | + zeitgeist_event_set_interpretation (event, ZEITGEIST_ZG_MOVE_EVENT); |
143 | + zeitgeist_event_set_manifestation (event, ZEITGEIST_ZG_USER_ACTIVITY); |
144 | + zeitgeist_event_set_actor (event, "application://nautilus.desktop"); |
145 | + zeitgeist_event_add_subject (event, subject); |
146 | + |
147 | + g_object_unref (subject); |
148 | + return event; |
149 | +} |
150 | + |
151 | // Steals the event, ref it if you want to keep it |
152 | static guint |
153 | index_event (Fixture *fix, ZeitgeistEvent *event) |
154 | @@ -236,6 +281,42 @@ |
155 | return event_id; |
156 | } |
157 | |
158 | +static GPtrArray* |
159 | +search_simple (Fixture *fix, const char *text, GPtrArray *templates, |
160 | + ZeitgeistResultType result_type, guint *matches) |
161 | +{ |
162 | + if (!templates) templates = g_ptr_array_new (); |
163 | + return zeitgeist_indexer_search (fix->indexer, |
164 | + text, |
165 | + zeitgeist_time_range_new_anytime (), |
166 | + templates, |
167 | + 0, // offset |
168 | + 10, // count |
169 | + result_type, |
170 | + matches, |
171 | + NULL); |
172 | +} |
173 | + |
174 | +static GPtrArray* |
175 | +search_with_relevancies_simple (Fixture *fix, const char *text, |
176 | + GPtrArray *templates, ZeitgeistResultType result_type, |
177 | + gdouble **relevancies, gint *relevancies_size, guint *matches) |
178 | +{ |
179 | + if (!templates) templates = g_ptr_array_new (); |
180 | + return zeitgeist_indexer_search_with_relevancies (fix->indexer, |
181 | + text, |
182 | + zeitgeist_time_range_new_anytime (), |
183 | + templates, |
184 | + ZEITGEIST_STORAGE_STATE_ANY, |
185 | + 0, // offset |
186 | + 10, // count |
187 | + result_type, |
188 | + relevancies, |
189 | + relevancies_size, |
190 | + matches, |
191 | + NULL); |
192 | +} |
193 | + |
194 | static void |
195 | test_simple_query (Fixture *fix, gconstpointer data) |
196 | { |
197 | @@ -249,33 +330,44 @@ |
198 | index_event (fix, create_test_event3 ()); |
199 | index_event (fix, create_test_event4 ()); |
200 | |
201 | - GPtrArray *results = |
202 | - zeitgeist_indexer_search (fix->indexer, |
203 | - "text", |
204 | - zeitgeist_time_range_new_anytime (), |
205 | - g_ptr_array_new (), |
206 | - 0, |
207 | - 10, |
208 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
209 | - &matches, |
210 | - NULL); |
211 | + GPtrArray *results = search_simple (fix, "text", NULL, |
212 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
213 | |
214 | g_assert_cmpuint (matches, >, 0); |
215 | g_assert_cmpuint (results->len, ==, 1); |
216 | - |
217 | - event = (ZeitgeistEvent*) results->pdata[0]; |
218 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
219 | - |
220 | - ZeitgeistSubject *subject = (ZeitgeistSubject*) |
221 | - g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); |
222 | - g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, "text"); |
223 | + assert_nth_result_has_id (results, 0, event_id); |
224 | + assert_nth_result_has_text (results, 0, "text"); |
225 | +} |
226 | + |
227 | +static void |
228 | +test_simple_query_empty_database (Fixture *fix, gconstpointer data) |
229 | +{ |
230 | + guint matches; |
231 | + |
232 | + GPtrArray *results = search_simple (fix, |
233 | + "NothingWillEverMatchThisMwhahahaha", NULL, |
234 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
235 | + |
236 | + g_assert_cmpuint (matches, ==, 0); |
237 | + g_assert_cmpuint (results->len, ==, 0); |
238 | +} |
239 | + |
240 | +static void |
241 | +test_simple_query_no_results (Fixture *fix, gconstpointer data) |
242 | +{ |
243 | + // add test events to DBs |
244 | + index_event (fix, create_test_event1 ()); |
245 | + index_event (fix, create_test_event2 ()); |
246 | + index_event (fix, create_test_event3 ()); |
247 | + index_event (fix, create_test_event4 ()); |
248 | + |
249 | + test_simple_query_empty_database (fix, data); |
250 | } |
251 | |
252 | static void |
253 | test_simple_with_filter (Fixture *fix, gconstpointer data) |
254 | { |
255 | guint matches; |
256 | - guint event_id; |
257 | ZeitgeistEvent* event; |
258 | |
259 | // add test events to DBs |
260 | @@ -287,16 +379,8 @@ |
261 | zeitgeist_event_set_interpretation (event, ZEITGEIST_NFO_DOCUMENT); |
262 | g_ptr_array_add (filters, event); // steals ref |
263 | |
264 | - GPtrArray *results = |
265 | - zeitgeist_indexer_search (fix->indexer, |
266 | - "text", |
267 | - zeitgeist_time_range_new_anytime (), |
268 | - filters, |
269 | - 0, |
270 | - 10, |
271 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
272 | - &matches, |
273 | - NULL); |
274 | + GPtrArray *results = search_simple (fix, "text", filters, |
275 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
276 | |
277 | g_assert_cmpuint (results->len, ==, 0); |
278 | g_assert_cmpuint (matches, ==, 0); |
279 | @@ -321,38 +405,24 @@ |
280 | zeitgeist_event_add_subject (event, subject); |
281 | g_ptr_array_add (filters, event); // steals ref |
282 | |
283 | - GPtrArray *results = |
284 | - zeitgeist_indexer_search (fix->indexer, |
285 | - "text", |
286 | - zeitgeist_time_range_new_anytime (), |
287 | - filters, |
288 | - 0, |
289 | - 10, |
290 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
291 | - &matches, |
292 | - NULL); |
293 | + GPtrArray *results = search_simple (fix, "text", filters, |
294 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
295 | |
296 | g_assert_cmpuint (matches, >, 0); |
297 | g_assert_cmpuint (results->len, ==, 1); |
298 | - |
299 | - event = (ZeitgeistEvent*) results->pdata[0]; |
300 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
301 | - |
302 | - subject = (ZeitgeistSubject*) |
303 | - g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); |
304 | - g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, "text"); |
305 | + assert_nth_result_has_id (results, 0, event_id); |
306 | + assert_nth_result_has_text (results, 0, "text"); |
307 | } |
308 | |
309 | static void |
310 | test_simple_negation (Fixture *fix, gconstpointer data) |
311 | { |
312 | guint matches; |
313 | - guint event_id; |
314 | ZeitgeistEvent* event; |
315 | ZeitgeistSubject *subject; |
316 | |
317 | // add test events to DBs |
318 | - event_id = index_event (fix, create_test_event1 ()); |
319 | + index_event (fix, create_test_event1 ()); |
320 | index_event (fix, create_test_event2 ()); |
321 | |
322 | GPtrArray *filters = g_ptr_array_new_with_free_func (g_object_unref); |
323 | @@ -362,16 +432,8 @@ |
324 | zeitgeist_event_add_subject (event, subject); |
325 | g_ptr_array_add (filters, event); // steals ref |
326 | |
327 | - GPtrArray *results = |
328 | - zeitgeist_indexer_search (fix->indexer, |
329 | - "text", |
330 | - zeitgeist_time_range_new_anytime (), |
331 | - filters, |
332 | - 0, |
333 | - 10, |
334 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
335 | - &matches, |
336 | - NULL); |
337 | + GPtrArray *results = search_simple (fix, "text", filters, |
338 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
339 | |
340 | g_assert_cmpuint (matches, ==, 0); |
341 | g_assert_cmpuint (results->len, ==, 0); |
342 | @@ -381,12 +443,11 @@ |
343 | test_simple_noexpand (Fixture *fix, gconstpointer data) |
344 | { |
345 | guint matches; |
346 | - guint event_id; |
347 | ZeitgeistEvent* event; |
348 | ZeitgeistSubject *subject; |
349 | |
350 | // add test events to DBs |
351 | - event_id = index_event (fix, create_test_event1 ()); |
352 | + index_event (fix, create_test_event1 ()); |
353 | index_event (fix, create_test_event2 ()); |
354 | |
355 | GPtrArray *filters = g_ptr_array_new_with_free_func (g_object_unref); |
356 | @@ -396,16 +457,8 @@ |
357 | zeitgeist_event_add_subject (event, subject); |
358 | g_ptr_array_add (filters, event); // steals ref |
359 | |
360 | - GPtrArray *results = |
361 | - zeitgeist_indexer_search (fix->indexer, |
362 | - "text", |
363 | - zeitgeist_time_range_new_anytime (), |
364 | - filters, |
365 | - 0, |
366 | - 10, |
367 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
368 | - &matches, |
369 | - NULL); |
370 | + GPtrArray *results = search_simple (fix, "text", filters, |
371 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
372 | |
373 | g_assert_cmpuint (matches, ==, 0); |
374 | g_assert_cmpuint (results->len, ==, 0); |
375 | @@ -430,26 +483,13 @@ |
376 | zeitgeist_event_add_subject (event, subject); |
377 | g_ptr_array_add (filters, event); // steals ref |
378 | |
379 | - GPtrArray *results = |
380 | - zeitgeist_indexer_search (fix->indexer, |
381 | - "text", |
382 | - zeitgeist_time_range_new_anytime (), |
383 | - filters, |
384 | - 0, |
385 | - 10, |
386 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
387 | - &matches, |
388 | - NULL); |
389 | + GPtrArray *results = search_simple (fix, "text", filters, |
390 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
391 | |
392 | g_assert_cmpuint (matches, >, 0); |
393 | g_assert_cmpuint (results->len, ==, 1); |
394 | - |
395 | - event = (ZeitgeistEvent*) results->pdata[0]; |
396 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
397 | - |
398 | - subject = (ZeitgeistSubject*) |
399 | - g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); |
400 | - g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, "text"); |
401 | + assert_nth_result_has_id (results, 0, event_id); |
402 | + assert_nth_result_has_text (results, 0, "text"); |
403 | } |
404 | |
405 | static void |
406 | @@ -471,26 +511,14 @@ |
407 | zeitgeist_event_add_subject (event, subject); |
408 | g_ptr_array_add (filters, event); // steals ref |
409 | |
410 | - GPtrArray *results = |
411 | - zeitgeist_indexer_search (fix->indexer, |
412 | - "love", |
413 | - zeitgeist_time_range_new_anytime (), |
414 | - filters, |
415 | - 0, |
416 | - 10, |
417 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
418 | - &matches, |
419 | - NULL); |
420 | + GPtrArray *results = search_simple (fix, "love", filters, |
421 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
422 | |
423 | g_assert_cmpuint (matches, >, 0); |
424 | g_assert_cmpuint (results->len, ==, 1); |
425 | - |
426 | - event = (ZeitgeistEvent*) results->pdata[0]; |
427 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
428 | - |
429 | - subject = (ZeitgeistSubject*) |
430 | - g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); |
431 | - g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, "Example.com Wiki Page. Kanji is awesome 漢字"); |
432 | + assert_nth_result_has_id (results, 0, event_id); |
433 | + assert_nth_result_has_text (results, 0, |
434 | + "Example.com Wiki Page. Kanji is awesome 漢字"); |
435 | } |
436 | |
437 | static void |
438 | @@ -507,22 +535,12 @@ |
439 | index_event (fix, create_test_event3 ()); |
440 | event_id = index_event (fix, create_test_event4 ()); |
441 | |
442 | - GPtrArray *results = |
443 | - zeitgeist_indexer_search (fix->indexer, |
444 | - "fabulo*", |
445 | - zeitgeist_time_range_new_anytime (), |
446 | - g_ptr_array_new (), |
447 | - 0, |
448 | - 10, |
449 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
450 | - &matches, |
451 | - NULL); |
452 | + GPtrArray *results = search_simple (fix, "fabulo*", NULL, |
453 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
454 | |
455 | g_assert_cmpuint (matches, >, 0); |
456 | g_assert_cmpuint (results->len, ==, 1); |
457 | - |
458 | - event = (ZeitgeistEvent*) results->pdata[0]; |
459 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
460 | + assert_nth_result_has_id (results, 0, event_id); |
461 | } |
462 | |
463 | static void |
464 | @@ -540,22 +558,12 @@ |
465 | index_event (fix, create_test_event4 ()); |
466 | event_id = index_event (fix, create_test_event5 ()); |
467 | |
468 | - GPtrArray *results = |
469 | - zeitgeist_indexer_search (fix->indexer, |
470 | - "signal", |
471 | - zeitgeist_time_range_new_anytime (), |
472 | - g_ptr_array_new (), |
473 | - 0, |
474 | - 10, |
475 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
476 | - &matches, |
477 | - NULL); |
478 | + GPtrArray *results = search_simple (fix, "signal", NULL, |
479 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
480 | |
481 | g_assert_cmpuint (matches, >, 0); |
482 | g_assert_cmpuint (results->len, ==, 1); |
483 | - |
484 | - event = (ZeitgeistEvent*) results->pdata[0]; |
485 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
486 | + assert_nth_result_has_id (results, 0, event_id); |
487 | } |
488 | |
489 | static void |
490 | @@ -583,22 +591,12 @@ |
491 | zeitgeist_event_add_subject (event, subject); |
492 | g_ptr_array_add (event_template, event); |
493 | |
494 | - GPtrArray *results = |
495 | - zeitgeist_indexer_search (fix->indexer, |
496 | - "pdf", |
497 | - zeitgeist_time_range_new_anytime (), |
498 | - event_template, |
499 | - 0, |
500 | - 10, |
501 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
502 | - &matches, |
503 | - NULL); |
504 | + GPtrArray *results = search_simple (fix, "pdf", event_template, |
505 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
506 | |
507 | g_assert_cmpuint (matches, >, 0); |
508 | g_assert_cmpuint (results->len, ==, 1); |
509 | - |
510 | - event = (ZeitgeistEvent*) results->pdata[0]; |
511 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
512 | + assert_nth_result_has_id (results, 0, event_id); |
513 | } |
514 | |
515 | static void |
516 | @@ -626,22 +624,12 @@ |
517 | zeitgeist_event_add_subject (event, subject); |
518 | g_ptr_array_add (event_template, event); |
519 | |
520 | - GPtrArray *results = |
521 | - zeitgeist_indexer_search (fix->indexer, |
522 | - "pdf", |
523 | - zeitgeist_time_range_new_anytime (), |
524 | - event_template, |
525 | - 0, |
526 | - 10, |
527 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
528 | - &matches, |
529 | - NULL); |
530 | + GPtrArray *results = search_simple (fix, "pdf", event_template, |
531 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
532 | |
533 | g_assert_cmpuint (matches, >, 0); |
534 | g_assert_cmpuint (results->len, ==, 1); |
535 | - |
536 | - event = (ZeitgeistEvent*) results->pdata[0]; |
537 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
538 | + assert_nth_result_has_id (results, 0, event_id); |
539 | } |
540 | |
541 | static void |
542 | @@ -669,22 +657,12 @@ |
543 | zeitgeist_event_add_subject (event, subject); |
544 | g_ptr_array_add (event_template, event); |
545 | |
546 | - GPtrArray *results = |
547 | - zeitgeist_indexer_search (fix->indexer, |
548 | - "pdf", |
549 | - zeitgeist_time_range_new_anytime (), |
550 | - event_template, |
551 | - 0, |
552 | - 10, |
553 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
554 | - &matches, |
555 | - NULL); |
556 | + GPtrArray *results = search_simple (fix, "pdf", event_template, |
557 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
558 | |
559 | g_assert_cmpuint (matches, >, 0); |
560 | g_assert_cmpuint (results->len, ==, 1); |
561 | - |
562 | - event = (ZeitgeistEvent*) results->pdata[0]; |
563 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
564 | + assert_nth_result_has_id (results, 0, event_id); |
565 | } |
566 | |
567 | static void |
568 | @@ -699,26 +677,14 @@ |
569 | index_event (fix, create_test_event1 ()); |
570 | event_id = index_event (fix, create_test_event2 ()); |
571 | |
572 | - GPtrArray *results = |
573 | - zeitgeist_indexer_search (fix->indexer, |
574 | - "漢*", |
575 | - zeitgeist_time_range_new_anytime (), |
576 | - g_ptr_array_new (), |
577 | - 0, |
578 | - 10, |
579 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
580 | - &matches, |
581 | - NULL); |
582 | + GPtrArray *results = search_simple (fix, "漢*", NULL, |
583 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
584 | |
585 | g_assert_cmpuint (matches, >, 0); |
586 | g_assert_cmpuint (results->len, ==, 1); |
587 | - |
588 | - event = (ZeitgeistEvent*) results->pdata[0]; |
589 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
590 | - |
591 | - subject = (ZeitgeistSubject*) |
592 | - g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); |
593 | - g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, "Example.com Wiki Page. Kanji is awesome 漢字"); |
594 | + assert_nth_result_has_id (results, 0, event_id); |
595 | + assert_nth_result_has_text (results, 0, |
596 | + "Example.com Wiki Page. Kanji is awesome 漢字"); |
597 | } |
598 | |
599 | static void |
600 | @@ -734,26 +700,13 @@ |
601 | index_event (fix, create_test_event2 ()); |
602 | event_id = index_event (fix, create_test_event3 ()); |
603 | |
604 | - GPtrArray *results = |
605 | - zeitgeist_indexer_search (fix->indexer, |
606 | - "παράδειγμα", |
607 | - zeitgeist_time_range_new_anytime (), |
608 | - g_ptr_array_new (), |
609 | - 0, |
610 | - 10, |
611 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
612 | - &matches, |
613 | - NULL); |
614 | + GPtrArray *results = search_simple (fix, "παράδειγμα", NULL, |
615 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
616 | |
617 | g_assert_cmpuint (matches, >, 0); |
618 | g_assert_cmpuint (results->len, ==, 1); |
619 | - |
620 | - event = (ZeitgeistEvent*) results->pdata[0]; |
621 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
622 | - |
623 | - subject = (ZeitgeistSubject*) |
624 | - g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); |
625 | - g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, "IDNwiki"); |
626 | + assert_nth_result_has_id (results, 0, event_id); |
627 | + assert_nth_result_has_text (results, 0, "IDNwiki"); |
628 | } |
629 | |
630 | static void |
631 | @@ -771,30 +724,16 @@ |
632 | index_event (fix, create_test_event3 ()); |
633 | index_event (fix, create_test_event4 ()); |
634 | |
635 | - GPtrArray *results = |
636 | - zeitgeist_indexer_search_with_relevancies (fix->indexer, |
637 | - "text", |
638 | - zeitgeist_time_range_new_anytime (), |
639 | - g_ptr_array_new (), |
640 | - ZEITGEIST_STORAGE_STATE_ANY, |
641 | - 0, |
642 | - 10, |
643 | - (ZeitgeistResultType) 100, |
644 | - &relevancies, &relevancies_size, |
645 | - &matches, |
646 | - NULL); |
647 | + GPtrArray *results = search_with_relevancies_simple (fix, "text", NULL, |
648 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS, |
649 | + &relevancies, &relevancies_size, &matches); |
650 | |
651 | g_assert_cmpuint (matches, >, 0); |
652 | g_assert_cmpuint (results->len, ==, 1); |
653 | g_assert_cmpint (relevancies_size, ==, 1); |
654 | g_assert_cmpfloat (relevancies[0], >=, 1.0); |
655 | - |
656 | - event = (ZeitgeistEvent*) results->pdata[0]; |
657 | - g_assert_cmpuint (zeitgeist_event_get_id (event), ==, event_id); |
658 | - |
659 | - ZeitgeistSubject *subject = (ZeitgeistSubject*) |
660 | - g_ptr_array_index (zeitgeist_event_get_subjects (event), 0); |
661 | - g_assert_cmpstr (zeitgeist_subject_get_text (subject), ==, "text"); |
662 | + assert_nth_result_has_id (results, 0, event_id); |
663 | + assert_nth_result_has_text (results, 0, "text"); |
664 | } |
665 | |
666 | static void |
667 | @@ -815,18 +754,9 @@ |
668 | usleep (50000); |
669 | event_id6 = index_event (fix, create_test_event6 ()); |
670 | |
671 | - GPtrArray *results = |
672 | - zeitgeist_indexer_search_with_relevancies (fix->indexer, |
673 | - "user*", |
674 | - zeitgeist_time_range_new_anytime (), |
675 | - g_ptr_array_new (), |
676 | - ZEITGEIST_STORAGE_STATE_ANY, |
677 | - 0, |
678 | - 10, |
679 | - ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS, |
680 | - &relevancies, &relevancies_size, |
681 | - &matches, |
682 | - NULL); |
683 | + GPtrArray *results = search_with_relevancies_simple (fix, "user*", NULL, |
684 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS, |
685 | + &relevancies, &relevancies_size, &matches); |
686 | |
687 | g_assert_cmpuint (matches, >, 0); |
688 | g_assert_cmpuint (results->len, ==, 3); |
689 | @@ -834,8 +764,131 @@ |
690 | |
691 | // we're creating event 6 after 5 and 4, so it has to be more recent (but it seems |
692 | // that number of terms indexed matters as well, so careful with the relevancies) |
693 | - g_assert_cmpuint (event_id6, ==, |
694 | - zeitgeist_event_get_id ((ZeitgeistEvent*) results->pdata[0])); |
695 | + assert_nth_result_has_id (results, 0, event_id6); |
696 | +} |
697 | + |
698 | +static void |
699 | +test_simple_move_event (Fixture *fix, gconstpointer data) |
700 | +{ |
701 | + guint matches; |
702 | + guint event_id; |
703 | + ZeitgeistEvent* event; |
704 | + |
705 | + // add test events to DBs |
706 | + index_event (fix, create_test_event1 ()); |
707 | + index_event (fix, create_test_event4 ()); |
708 | + event_id = index_event (fix, create_test_event8 ()); |
709 | + |
710 | + GPtrArray *results = search_simple (fix, "awesome", NULL, |
711 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
712 | + |
713 | + g_assert_cmpuint (matches, >, 0); |
714 | + g_assert_cmpuint (results->len, ==, 1); |
715 | + assert_nth_result_has_id (results, 0, event_id); |
716 | +} |
717 | + |
718 | +static void |
719 | +test_simple_most_recent (Fixture *fix, gconstpointer data) |
720 | +{ |
721 | + guint matches; |
722 | + guint event_id1, event_id2, event_id3, event_id4; |
723 | + ZeitgeistEvent* event; |
724 | + GPtrArray* results; |
725 | + gdouble *relevancies; |
726 | + gint relevancies_size; |
727 | + |
728 | + // add test events to DBs |
729 | + event_id1 = index_event (fix, create_test_event1 ()); |
730 | + event_id2 = index_event (fix, create_test_event2 ()); |
731 | + event_id3 = index_event (fix, create_test_event3 ()); |
732 | + event_id4 = index_event (fix, create_test_event4 ()); |
733 | + |
734 | + for (int i = 0; i < 4; ++i) |
735 | + { |
736 | + if (i == 0) |
737 | + { |
738 | + // Search for MostRecentEvents |
739 | + results = search_simple (fix, "*text*", NULL, |
740 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, &matches); |
741 | + } |
742 | + else if (i == 1) |
743 | + { |
744 | + // Search for MostRecentSubjects |
745 | + results = search_simple (fix, "*text*", NULL, |
746 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS, &matches); |
747 | + } |
748 | + else if (i == 2) |
749 | + { |
750 | + // SearchWithRelevancies for MostRecentEvents |
751 | + GPtrArray *results = search_with_relevancies_simple (fix, "*text*", NULL, |
752 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_EVENTS, |
753 | + &relevancies, &relevancies_size, &matches); |
754 | + } |
755 | + else |
756 | + { |
757 | + // SearchWithRelevancies for MostRecentSubjects |
758 | + GPtrArray *results = search_with_relevancies_simple (fix, "*text*", NULL, |
759 | + ZEITGEIST_RESULT_TYPE_MOST_RECENT_SUBJECTS, |
760 | + &relevancies, &relevancies_size, &matches); |
761 | + } |
762 | + |
763 | + g_assert_cmpuint (matches, >, 0); |
764 | + g_assert_cmpuint (results->len, ==, 2); |
765 | + assert_nth_result_has_id (results, 0, event_id4); |
766 | + assert_nth_result_has_id (results, 1, event_id1); |
767 | + } |
768 | +} |
769 | + |
770 | +static void |
771 | +test_simple_least_recent (Fixture *fix, gconstpointer data) |
772 | +{ |
773 | + guint matches; |
774 | + guint event_id1, event_id2, event_id3, event_id4; |
775 | + ZeitgeistEvent* event; |
776 | + GPtrArray* results; |
777 | + gdouble *relevancies; |
778 | + gint relevancies_size; |
779 | + |
780 | + // add test events to DBs |
781 | + event_id1 = index_event (fix, create_test_event1 ()); |
782 | + event_id2 = index_event (fix, create_test_event2 ()); |
783 | + event_id3 = index_event (fix, create_test_event3 ()); |
784 | + event_id4 = index_event (fix, create_test_event4 ()); |
785 | + |
786 | + for (int i = 0; i < 4; ++i) |
787 | + { |
788 | + if (i == 0) |
789 | + { |
790 | + // Search for LeastRecentEvents |
791 | + results = search_simple (fix, "*text*", NULL, |
792 | + ZEITGEIST_RESULT_TYPE_LEAST_RECENT_EVENTS, &matches); |
793 | + } |
794 | + else if (i == 1) |
795 | + { |
796 | + // Search for LeastRecentSubjects |
797 | + results = search_simple (fix, "*text*", NULL, |
798 | + ZEITGEIST_RESULT_TYPE_LEAST_RECENT_SUBJECTS, &matches); |
799 | + } |
800 | + else if (i == 2) |
801 | + { |
802 | + // SearchWithRelevancies for LeastRecentEvents |
803 | + GPtrArray *results = search_with_relevancies_simple (fix, "*text*", NULL, |
804 | + ZEITGEIST_RESULT_TYPE_LEAST_RECENT_EVENTS, |
805 | + &relevancies, &relevancies_size, &matches); |
806 | + } |
807 | + else |
808 | + { |
809 | + // SearchWithRelevancies for LeastRecentSubjects |
810 | + GPtrArray *results = search_with_relevancies_simple (fix, "*text*", NULL, |
811 | + ZEITGEIST_RESULT_TYPE_LEAST_RECENT_SUBJECTS, |
812 | + &relevancies, &relevancies_size, &matches); |
813 | + } |
814 | + |
815 | + g_assert_cmpuint (matches, >, 0); |
816 | + g_assert_cmpuint (results->len, ==, 2); |
817 | + assert_nth_result_has_id (results, 0, event_id1); |
818 | + assert_nth_result_has_id (results, 1, event_id4); |
819 | + } |
820 | } |
821 | |
822 | G_BEGIN_DECLS |
823 | @@ -851,6 +904,10 @@ |
824 | { |
825 | g_test_add ("/Zeitgeist/FTS/Indexer/SimpleQuery", Fixture, 0, |
826 | setup, test_simple_query, teardown); |
827 | + g_test_add ("/Zeitgeist/FTS/Indexer/SimpleQueryEmptyDatabase", Fixture, 0, |
828 | + setup, test_simple_query_empty_database, teardown); |
829 | + g_test_add ("/Zeitgeist/FTS/Indexer/SimpleQueryNoResults", Fixture, 0, |
830 | + setup, test_simple_query_no_results, teardown); |
831 | g_test_add ("/Zeitgeist/FTS/Indexer/SimpleWithFilter", Fixture, 0, |
832 | setup, test_simple_with_filter, teardown); |
833 | g_test_add ("/Zeitgeist/FTS/Indexer/SimpleWithValidFilter", Fixture, 0, |
834 | @@ -881,6 +938,12 @@ |
835 | setup, test_simple_relevancies_query, teardown); |
836 | g_test_add ("/Zeitgeist/FTS/Indexer/RelevanciesSubject", Fixture, 0, |
837 | setup, test_simple_relevancies_subject_query, teardown); |
838 | + g_test_add ("/Zeitgeist/FTS/Indexer/MoveEvent", Fixture, 0, |
839 | + setup, test_simple_move_event, teardown); |
840 | + g_test_add ("/Zeitgeist/FTS/Indexer/MostRecent", Fixture, 0, |
841 | + setup, test_simple_most_recent, teardown); |
842 | + g_test_add ("/Zeitgeist/FTS/Indexer/LeastRecent", Fixture, 0, |
843 | + setup, test_simple_least_recent, teardown); |
844 | |
845 | // get rid of the "rebuilding index..." messages |
846 | g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE, discard_message, NULL); |
847 | |
848 | === modified file 'test/dbus/engine-test.py' |
849 | --- test/dbus/engine-test.py 2012-01-02 07:42:53 +0000 |
850 | +++ test/dbus/engine-test.py 2012-03-16 18:46:19 +0000 |
851 | @@ -134,7 +134,7 @@ |
852 | |
853 | def testIllegalPredefinedEventId(self): |
854 | event = Event() |
855 | - event[0][0] = str(23) # This is illegal, we assert the erro later |
856 | + event[0][0] = str(23) # This is illegal, we assert the error later |
857 | event.timestamp = 0 |
858 | event.interpretation = Manifestation.USER_ACTIVITY |
859 | event.manifestation = Interpretation.CREATE_EVENT |
Outstanding issue: Should CompileEventFil terQuery also be changed to use current_uri instead (or in addition to?) uri?