orgzly-android icon indicating copy to clipboard operation
orgzly-android copied to clipboard

Search for tag with exact match

Open kisp opened this issue 6 years ago • 4 comments

t.bee searches for a tag with substring match.

I would need the functionality to search for tags matching exactly bee.

Is this currently possible?

If not what should the syntax be?

Can I provide a patch?

kisp avatar Nov 01 '19 16:11 kisp

It's not currently possible. Both t.bee and tn.bee do tag LIKE '%bee%'.

The reason that this was done in the first place is because tag is a space-separated string, so I wasn't sure what's the best way to do it properly in SQL. Patch would be great. Relevant code to follow is Condition.HasTag and Condition.HasOwnTag.

nevenz avatar Nov 01 '19 17:11 nevenz

@nevenz I would have to dig around to see about patching it, but I can describe both a quick fix and a more optimal SQL approach.

(Apologies if any of this is already obvious; I'm a data normalization junkie.) I believe the normal way to do this in SQL would be to save the tags not as a single delimited string but as multiple rows in a second table with a foreign key reference to the notes; then you could search that table for the IDs of the notes with those tags, or join it and filter on the tags, etc. A more space efficient and data-consistent variation is: since the tags should be used by more than one note in a notebook, have the one-tag-per-row table contain all tags for that book (this would make looking up all available tags efficient too), and have a third table the rows of which merely pair notes to which tags they have (so e.g. one row says note 1 has tag 2, next says note 1 has tag 6, etc.).

Quick fix on the other hand is a simple two-step change: add the delimiter (space in this case) between the search term and the wildcard on each side so you match the beginning and end of the entry in the list, then add the delimiter to either end of the list too so the first and last entries can still be matched. For example, t.bee becomes "% bee %" and matches " bee wasp dragonfly " (no longer matches honeybee).

ScottFreeCode avatar Dec 01 '19 02:12 ScottFreeCode

@ScottFreeCode Would also be possible to store it like in Emacs org-mode, so using colon instead of space. Tagged by foo and bar would become :foo:bar:.

Personally, this feature has become somewhat less important for me.

I would like to add that orgzly is an amazing piece of software that changes completely how I can work with Emacs org-mode ❤️

kisp avatar Dec 01 '19 09:12 kisp

I still hope this feature can one day be implemented. We all have our own custom ways of using tags, which is part of what makes org-mode so incredible. I rely on a hierarchical system of short tags with lots of groups. It sounds more complex than it is.

But the result is that often I even a simple tag condition creates search results which include many extraneous tags.

I've tried creating extremely long and complex queries to account for every extraneous tag while not excluding the tag I do want, but it is just not practical and requires a lot of manual upkeep. And in many cases, I have not even been able to achieve it at all.

Still love Orgzly. Just wanted to renew this request for consideration at some point.

max6166 avatar Dec 09 '22 00:12 max6166