Merge lp:~tombeckmann/+junk/libcolumbus into lp:~elementary-pantheon/slingshot/trunk

Proposed by Tom Beckmann
Status: Rejected
Rejected by: Tom Beckmann
Proposed branch: lp:~tombeckmann/+junk/libcolumbus
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 289 lines (+208/-4)
4 files modified
CMakeLists.txt (+15/-1)
src/Backend/AppSystem.vala (+33/-3)
src/Backend/ColumbusSearchModel.vala (+88/-0)
vapi/libcolumbus.vapi (+72/-0)
To merge this branch: bzr merge lp:~tombeckmann/+junk/libcolumbus
Reviewer Review Type Date Requested Status
Danielle Foré Needs Fixing
Review via email: mp+209144@code.launchpad.net

Description of the change

This adds support for libcolumbus, it replaces the previous search and weighting algorithm, which is still used if columbus is disabled before compilation. If I'm not completely mistaken, the app relevancies as provided by Zeitgeist should still be used to sort the results returned by libcolubmus.

Please test if the results shown are indeed sensible, otherwise I'll go and adjust the index weights or check which part of the API I misunderstood.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Hrm I'm getting a build error: make[2]: *** No rule to make target `../src/Widgets/SearchViewInterface.vala'

In my head I would think User Input > LibColumbus > Zeitgeist > Search Results. I think that's what you're saying you did right?

Revision history for this message
Tom Beckmann (tombeckmann) wrote :

You can just remove src/Widgets/SearchViewInterface.vala to make it compile, I'll fix it once I get back to my computer, which will take a while.
Theoretically that's what should happen, yes.

lp:~tombeckmann/+junk/libcolumbus updated
409. By Tom Beckmann

remove reference to non existent file

Revision history for this message
Tom Beckmann (tombeckmann) wrote :

Should work fine now.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

Relative header-paths in vapis aren't a good idea.
Aren't there bindings for libcolumbus itself to avoid using ccode with a primitive vapi?

lp:~tombeckmann/+junk/libcolumbus updated
410. By Tom Beckmann

add real libcolumbus vapi by ricotz, improve search results

Revision history for this message
Tom Beckmann (tombeckmann) wrote :

Thanks to ricotz providing a vapi for libcolumbus I could drop the C code now. Also the search results should be a lot better now.

lp:~tombeckmann/+junk/libcolumbus updated
411. By Tom Beckmann

forgot most important class -.-

412. By Tom Beckmann

add some docs, remove debug print

Revision history for this message
Danielle Foré (danrabbit) wrote :

Hrm, I feel like the top result isn't as good as it was before.

It's pretty cool getting results even when you have typos, but when I don't make typos (such as typing "mi") I'm not getting the result I expect ("Midori" or "Minecraft")

Since typos shouldn't return results, can we list results returned from the actual typed string first and results returned from libcolumbus after those?

That way, we'll get "minecraft" listed before "terminal" (command line) when I type "mine"

review: Needs Fixing

Unmerged revisions

412. By Tom Beckmann

add some docs, remove debug print

411. By Tom Beckmann

forgot most important class -.-

410. By Tom Beckmann

add real libcolumbus vapi by ricotz, improve search results

409. By Tom Beckmann

remove reference to non existent file

408. By Tom Beckmann

add support for libcolumbus

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-02-23 19:56:35 +0000
+++ CMakeLists.txt 2014-03-04 23:27:45 +0000
@@ -54,8 +54,19 @@
54 message ("-- Zeitgeist integration disabled")54 message ("-- Zeitgeist integration disabled")
55endif ()55endif ()
5656
57option (USE_LIBCOLUMBUS "Use libcolumbus for fuzzy matching" ON)
58
59if (USE_LIBCOLUMBUS)
60 message ("-- libcolumbus integration enabled")
61 set (LIBCOLUMBUS_DEPS libcolumbus)
62 set (LIBCOLUMBUS_OPTIONS --define=HAVE_LIBCOLUMBUS --vapidir=${CMAKE_SOURCE_DIR}/vapi)
63 set (LIBCOLUMBUS_SOURCES src/Backend/ColumbusSearchModel.vala)
64else ()
65 message ("-- libcolumbus integration disabled")
66endif ()
67
57set (CORE_DEPS "gobject-2.0;glib-2.0;gio-2.0;gio-unix-2.0;gee-0.8;libgnome-menu-3.0;libwnck-3.0;gdk-x11-3.0;${UNITY_DEPS};")68set (CORE_DEPS "gobject-2.0;glib-2.0;gio-2.0;gio-unix-2.0;gee-0.8;libgnome-menu-3.0;libwnck-3.0;gdk-x11-3.0;${UNITY_DEPS};")
58set (UI_DEPS "gtk+-3.0>=3.2.0;granite;${ZEITGEIST_DEPS};")69set (UI_DEPS "gtk+-3.0>=3.2.0;granite;${ZEITGEIST_DEPS};${LIBCOLUMBUS_DEPS};")
5970
60find_package (PkgConfig)71find_package (PkgConfig)
61pkg_check_modules (DEPS REQUIRED "${CORE_DEPS}${UI_DEPS}" gthread-2.0)72pkg_check_modules (DEPS REQUIRED "${CORE_DEPS}${UI_DEPS}" gthread-2.0)
@@ -81,16 +92,19 @@
81 src/Widgets/SearchItem.vala92 src/Widgets/SearchItem.vala
82 src/Widgets/Sidebar.vala93 src/Widgets/Sidebar.vala
83 src/Widgets/CategoryView.vala94 src/Widgets/CategoryView.vala
95 ${LIBCOLUMBUS_SOURCES}
84PACKAGES96PACKAGES
85 ${CORE_DEPS}97 ${CORE_DEPS}
86 ${UI_DEPS}98 ${UI_DEPS}
87CUSTOM_VAPIS99CUSTOM_VAPIS
88 vapi/config.vapi100 vapi/config.vapi
101 ${LIBCOLUMBUS_VAPI}
89OPTIONS102OPTIONS
90 --thread103 --thread
91 -g104 -g
92 ${UNITY_OPTIONS}105 ${UNITY_OPTIONS}
93 ${ZEITGEIST_OPTIONS}106 ${ZEITGEIST_OPTIONS}
107 ${LIBCOLUMBUS_OPTIONS}
94)108)
95109
96# Comment this out to enable C compiler warnings110# Comment this out to enable C compiler warnings
97111
=== modified file 'src/Backend/AppSystem.vala'
--- src/Backend/AppSystem.vala 2013-01-10 16:53:50 +0000
+++ src/Backend/AppSystem.vala 2014-03-04 23:27:45 +0000
@@ -26,6 +26,10 @@
26 private RelevancyService rl_service;26 private RelevancyService rl_service;
27#endif27#endif
2828
29#if HAVE_LIBCOLUMBUS
30 private ColumbusSearch.Model search_model;
31#endif
32
29 public signal void changed ();33 public signal void changed ();
3034
31 construct {35 construct {
@@ -35,6 +39,10 @@
35 rl_service.update_complete.connect (update_popularity);39 rl_service.update_complete.connect (update_popularity);
36#endif40#endif
3741
42#if HAVE_LIBCOLUMBUS
43 search_model = new ColumbusSearch.Model ();
44#endif
45
38 apps_menu = new GMenu.Tree ("pantheon-applications.menu", GMenu.TreeFlags.INCLUDE_EXCLUDED | GMenu.TreeFlags.SORT_DISPLAY_NAME);46 apps_menu = new GMenu.Tree ("pantheon-applications.menu", GMenu.TreeFlags.INCLUDE_EXCLUDED | GMenu.TreeFlags.SORT_DISPLAY_NAME);
39 apps_menu.changed.connect (update_app_system);47 apps_menu.changed.connect (update_app_system);
40 48
@@ -90,9 +98,24 @@
9098
91 apps.clear ();99 apps.clear ();
92100
93 foreach (var cat in categories)101#if HAVE_LIBCOLUMBUS
94 apps.set (cat.get_name (), get_apps_by_category (cat));102 search_model.clear ();
95103#endif
104
105 foreach (var cat in categories) {
106 var category_apps = get_apps_by_category (cat);
107 apps.set (cat.get_name (), category_apps);
108#if HAVE_LIBCOLUMBUS
109 foreach (var app in category_apps) {
110 search_model.add_entry (app, app.name,
111 app.description, app.exec);
112 }
113#endif
114 }
115
116#if HAVE_LIBCOLUMBUS
117 search_model.finished_adding ();
118#endif
96 }119 }
97120
98 public Gee.ArrayList<GMenu.TreeDirectory> get_categories () {121 public Gee.ArrayList<GMenu.TreeDirectory> get_categories () {
@@ -171,6 +194,12 @@
171194
172 var filtered = new Gee.ArrayList<App> ();195 var filtered = new Gee.ArrayList<App> ();
173196
197#if HAVE_LIBCOLUMBUS
198 List<void*> results = search_model.match (search);
199 foreach (var result in results) {
200 filtered.add (result as App);
201 }
202#else
174 /** It's a bit stupid algorithm, simply check if the char is present203 /** It's a bit stupid algorithm, simply check if the char is present
175 * some of the App values, then assign it a double. This is very simple:204 * some of the App values, then assign it a double. This is very simple:
176 * if an App name coincide with the search string they have obvious the205 * if an App name coincide with the search string they have obvious the
@@ -213,6 +242,7 @@
213 }242 }
214 }243 }
215 }244 }
245#endif
216246
217 filtered.sort ((a, b) => Utils.sort_apps_by_relevancy ((App) a, (App) b));247 filtered.sort ((a, b) => Utils.sort_apps_by_relevancy ((App) a, (App) b));
218248
219249
=== added file 'src/Backend/ColumbusSearchModel.vala'
--- src/Backend/ColumbusSearchModel.vala 1970-01-01 00:00:00 +0000
+++ src/Backend/ColumbusSearchModel.vala 2014-03-04 23:27:45 +0000
@@ -0,0 +1,88 @@
1
2#if HAVE_LIBCOLUMBUS
3using Columbus;
4
5namespace ColumbusSearch
6{
7 public class Model : Object {
8 Corpus corpus;
9 Matcher matcher;
10
11 Word field_name;
12 Word field_description;
13 Word field_exec;
14
15 public Model () {
16 corpus = new Corpus ();
17 matcher = new Matcher ();
18
19 field_name = new Word ("name");
20 field_description = new Word ("description");
21 field_exec = new Word ("exec");
22 }
23
24 /**
25 * Add an entry to the model.
26 *
27 * @param id A pointer to the app which is identified by these values. It
28 * is internally used as an id.
29 * @param name The app's name
30 * @param description The app's description
31 * @param exec The app's executable line
32 */
33 public void add_entry (void *id, string name, string description, string exec) {
34 var doc = new Document ((DocumentID)id);
35
36 doc.add_text (field_name, name);
37 doc.add_text (field_description, description);
38 doc.add_text (field_exec, exec);
39
40 corpus.add_document (doc);
41 }
42
43 /**
44 * Call this function after you added all the entries to build the index
45 */
46 public void finished_adding ()
47 {
48 matcher.index (corpus);
49
50 var errors = matcher.get_error_values ();
51 errors.add_standard_errors ();
52 errors.set_substring_mode ();
53
54 var weights = matcher.get_index_weights ();
55 weights.set_weight (field_description, 0.5);
56 }
57
58 /**
59 * Clear the current model
60 */
61 public void clear () {
62 corpus = new Corpus ();
63 }
64
65 /**
66 * Search in the model. Don't forget to call finished_adding before calling this
67 *
68 * @param query The query string to be searched for
69 * @return Returns a list of the ids which represent pointers to the app
70 * objects as added earlier.
71 */
72 public List<void*> match (string query) {
73 var result = matcher.match (query);
74 var len = result.size ();
75
76 var list = new List<void*> ();
77 for (var i = 0; i < len; i++) {
78 list.prepend ((void*)result.get_id (i));
79 }
80
81 list.reverse ();
82
83 return list;
84 }
85 }
86}
87
88#endif
089
=== added file 'vapi/libcolumbus.vapi'
--- vapi/libcolumbus.vapi 1970-01-01 00:00:00 +0000
+++ vapi/libcolumbus.vapi 2014-03-04 23:27:45 +0000
@@ -0,0 +1,72 @@
1/* libcolumbus.vapi generated by vapigen, do not modify. */
2
3[CCode (cprefix = "Col", lower_case_cprefix = "col_")]
4namespace Columbus {
5 [CCode (cheader_filename = "columbus.h", free_function = "col_corpus_delete")]
6 [Compact]
7 public class Corpus {
8 [CCode (has_construct_function = false, type = "ColCorpus")]
9 public Corpus ();
10 public void add_document (Columbus.Document d);
11 public void @delete ();
12 }
13 [CCode (cheader_filename = "columbus.h", free_function = "col_document_delete")]
14 [Compact]
15 public class Document {
16 [CCode (has_construct_function = false, type = "ColDocument")]
17 public Document (Columbus.DocumentID id);
18 public void add_text (Columbus.Word field_name, string text_as_utf8);
19 public void @delete ();
20 public Columbus.DocumentID get_id ();
21 }
22 [CCode (cheader_filename = "columbus.h", free_function = "")]
23 [Compact]
24 public class ErrorValues {
25 public void add_standard_errors ();
26 public void set_substring_mode ();
27 }
28 [CCode (cheader_filename = "columbus.h", free_function = "")]
29 [Compact]
30 public class IndexWeights {
31 public double get_weight (Columbus.Word field);
32 public void set_weight (Columbus.Word field, double new_weight);
33 }
34 [CCode (cheader_filename = "columbus.h", free_function = "col_match_results_delete")]
35 [Compact]
36 public class MatchResults {
37 [CCode (has_construct_function = false, type = "ColMatchResults")]
38 public MatchResults ();
39 public void @delete ();
40 public Columbus.DocumentID get_id (size_t i);
41 public double get_relevancy (size_t i);
42 public size_t size ();
43 }
44 [CCode (cheader_filename = "columbus.h", free_function = "col_matcher_delete")]
45 [Compact]
46 public class Matcher {
47 [CCode (has_construct_function = false, type = "ColMatcher")]
48 public Matcher ();
49 public void @delete ();
50 public Columbus.ErrorValues get_error_values ();
51 public Columbus.IndexWeights get_index_weights ();
52 public void index (Columbus.Corpus c);
53 public Columbus.MatchResults match (string query_as_utf8);
54 }
55 [CCode (cheader_filename = "columbus.h", free_function = "col_word_delete")]
56 [Compact]
57 public class Word {
58 [CCode (has_construct_function = false, type = "ColWord")]
59 public Word (string utf8_word);
60 public void as_utf8 (string buf, uint bufSize);
61 public void @delete ();
62 public size_t length ();
63 }
64 [CCode (cname = "uintptr_t", cheader_filename = "columbus.h", cprefix = "")]
65 [SimpleType]
66 public struct DocumentID {
67 }
68 [CCode (cname = "uint32_t", cheader_filename = "columbus.h", cprefix = "")]
69 [SimpleType]
70 public struct WordID {
71 }
72}

Subscribers

People subscribed via source and target branches