GNOME Bugzilla – Bug 684412
Add support for tagging diary entries
Last modified: 2013-09-04 16:41:18 UTC
Users might find it useful to be able to add tags to diary entries, to allow them to categorise the entries or make searching easier. This would behave, e.g., like tagging photos in Shotwell.
Hashtags like in Tweeter can de useful to make a tag-cloud for search. @work, @home and #issue, #done, #pending
Looks like a good way to append a new tag while your writing. I like it and I'll tray to implement it when all the infrastructure is working.
After some discussion about the better way to store the tags in the Almanah database, some tests was realized with two different schemas to take the better decision: A. Two tables, one for tags and other for the relation between tag and an entry CREATE TABLE "tags" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "tag" TEXT ) CREATE TABLE "entry_tag" ( "year" INTEGER, "month" INTEGER, "day" INTEGER, "tag_id" INTEGER NOT NULL ) B. Just one table with this CREATE TABLE entry_tag ( "year" INTEGER, "month" INTEGER, "day" INTEGER, "tag" TEXT ) With 1.000 entries (one entry per day in three years) and three tags per entry: 1. Select the entries with a specific tag: A: SELECT et.year, et.month, et.day FROM entry_tag et LEFT JOIN tags t ON (t.id = et.tag_id) WHERE t.tag = '%s'; 0.014 s B: SELECT year, month, day FROM entry_tag WHERE tag='%s'; 0.018 s 2. Get the tags for an entry: A: SELECT t.tag FROM tags t LEFT JOIN entry_tag et ON (t.id = et.tag_id) WHERE et.year=%d AND et.month=%d AND et.day=%d; 0.042 s B: SELECT tag FROM entry_tag WHERE year=%d AND month=%d AND day=%d; 0.004 s 3. Get the tags names: A: SELECT tag FROM tags; 0.004 s B: SELECT DISTINCT tag FROM entry_tag; 0.006 s There isn't much difference between the two schemes but the second query. So the B scheme it's more simple and handy.
Here the schema into src/storage.c (create_tables function) + "CREATE TABLE IF NOT EXISTS entry_tag (year INTEGER, month INTEGER, day INTEGER, tag TEXT)", /* added in 0.10.0 */ + "CREATE INDEX idx_tag ON entry_tag(tag)", /* added in 0.10.0, for information take a look at: http://www.sqlite.org/queryplanner.html */
I have pushed to git (master) the code that allow tag diary entries. Required tests and some user feedback, also some thoughts from the design team would be great.
Created attachment 236228 [details] A diary entry with some tags The "add tag" text is a GtkEntry with an autocompletion list (with all the tags added in the diary). When the user select a tag from the autocompletion list or press "enter" with some text, a tag is added and the focus return to the entry text.
Created attachment 236229 [details] Diary entry clean window This is the way a clean entry looks.
Looks great and works nicely from some quick testing! Is it integrated with search yet?
(In reply to comment #8) > ... Is it integrated with > search yet? Good point. I have changed the search query to include the tags like this: SELECT e.content, e.is_important, e.day, e.month, e.year, e.edited_day, e.edited_month, e.edited_year, e.version, GROUP_CONCAT(et.tag) AS tags FROM entries AS e LEFT JOIN entry_tag AS et ON (e.day=et.day AND e.month=et.month AND e.year=et.year) GROUP BY e.year, e.month, e.day ORDER BY e.year DESC, e.month DESC, e.day DESC So it's possible to make a "strstr" in order to search the string entered by the user. I'll commit it ASAP.
I have done a "push" with some style and functional changes. I guess this bug can be closed.
Created attachment 254108 [details] How looks the tags zone (it can be hidden)
(In reply to comment #1) > Hashtags like in Tweeter can de useful to make a tag-cloud for search. > > @work, @home and #issue, #done, #pending I'll close this bug, but opened #707487 to follow your suggestion.