diff options
author | bobufa <bobufa@users.noreply.github.com> | 2018-07-10 00:31:39 +0200 |
---|---|---|
committer | bobufa <bobufa@users.noreply.github.com> | 2018-08-13 22:31:22 +0200 |
commit | 61915ca56617e8f45ae8bd85cb87f0b8a9a895b0 (patch) | |
tree | 2fd35772c1d1145852f36e0baed6fafc0a73a517 /libdino | |
parent | 8b23ddad2d33a1504cd28c0df583dfe50cadccda (diff) | |
download | dino-61915ca56617e8f45ae8bd85cb87f0b8a9a895b0.tar.gz dino-61915ca56617e8f45ae8bd85cb87f0b8a9a895b0.zip |
initial search logic / display
Diffstat (limited to 'libdino')
-rw-r--r-- | libdino/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libdino/src/application.vala | 1 | ||||
-rw-r--r-- | libdino/src/service/message_storage.vala | 1 | ||||
-rw-r--r-- | libdino/src/service/search_processor.vala | 54 |
4 files changed, 57 insertions, 0 deletions
diff --git a/libdino/CMakeLists.txt b/libdino/CMakeLists.txt index 429fc1f3..de44195d 100644 --- a/libdino/CMakeLists.txt +++ b/libdino/CMakeLists.txt @@ -42,6 +42,7 @@ SOURCES src/service/notification_events.vala src/service/presence_manager.vala src/service/roster_manager.vala + src/service/search_processor.vala src/service/stream_interactor.vala src/service/util.vala diff --git a/libdino/src/application.vala b/libdino/src/application.vala index 0edd6df6..80e474ac 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -39,6 +39,7 @@ public interface Dino.Application : GLib.Application { FileManager.start(stream_interactor, db); NotificationEvents.start(stream_interactor); ContentItemAccumulator.start(stream_interactor); + SearchProcessor.start(stream_interactor, db); create_actions(); diff --git a/libdino/src/service/message_storage.vala b/libdino/src/service/message_storage.vala index e3869e41..abc8acb4 100644 --- a/libdino/src/service/message_storage.vala +++ b/libdino/src/service/message_storage.vala @@ -1,4 +1,5 @@ using Gee; +using Qlite; using Dino.Entities; diff --git a/libdino/src/service/search_processor.vala b/libdino/src/service/search_processor.vala new file mode 100644 index 00000000..3c1057ae --- /dev/null +++ b/libdino/src/service/search_processor.vala @@ -0,0 +1,54 @@ +using Gee; + +using Xmpp; +using Qlite; +using Dino.Entities; + +namespace Dino { + +public class SearchProcessor : StreamInteractionModule, Object { + public static ModuleIdentity<SearchProcessor> IDENTITY = new ModuleIdentity<SearchProcessor>("search_processor"); + public string id { get { return IDENTITY.id; } } + + private StreamInteractor stream_interactor; + private Database db; + + public static void start(StreamInteractor stream_interactor, Database db) { + SearchProcessor m = new SearchProcessor(stream_interactor, db); + stream_interactor.add_module(m); + } + + public SearchProcessor(StreamInteractor stream_interactor, Database db) { + this.stream_interactor = stream_interactor; + this.db = db; + } + + public Gee.List<Message> match_messages(string match, int offset = -1) { + Gee.List<Message> ret = new ArrayList<Message>(Message.equals_func); + var query = db.message + .match(db.message.body, parse_search(match)) + .order_by(db.message.id, "DESC") + .limit(10); + if (offset > 0) { + query.offset(offset); + } + foreach (Row row in query) { + ret.add(new Message.from_row(db, row)); + } + return ret; + } + + public int count_match_messages(string match) { + return (int)db.message.match(db.message.body, parse_search(match)).count(); + } + + private string parse_search(string search) { + string ret = ""; + foreach(string word in search.split(" ")) { + ret += word + "* "; + } + return ret; + } +} + +} |