% (percent sign) in the search term - a bug? [should explain to user, support escaping, same for _]

When using search in DC app, I enter a couple of letters, like ‘abc’, and there are some number of results, let’s say 50. Then I add % in the middle (‘ab%c’), and numbers of results is much higher, like 200.

When I add % to the beginning or the end end (‘abc%’), the results number stays the same, but results show other parts of messages.

Adding not single %, but multiple %%%%%% produces very same number of search results.

Is % some special character?

This magic happens at least on both latest Android and Electron DC apps.

Here is the code:

The query is passed raw (surrounded by %) as the SQL LIKE argument. % represents zero or more characters. So when you type “abc%def”, the query will match “abc 123 def” as well as “abcdef”.
It’s like this since at leas 7 years ago, and probably not intentional.
But I’ll be using this, to make the search suck less, thanks for discovering!

Note that _ (the underscore) also has special meaning - matching any single literal character:

I would like to propose that the above Delta Chat function should also include an ESCAPE clause to allow escaping the special meaning of these metacharacters with \.

I think the search widget should either communicate this feature to the user or escape any special character in the user input itself (i.e., disallow the special meaning of both metacharacters).

In my head usual search wildcard is *, not %.
‘_’ as wildcard… I would never guess.
For me this choices are slightly esotheric. But I’m not blesed with much of SQL experience…

Maybe replace them in search query with more intutive ones?

'' escaping will also be useful.

On search field design: in some apps I saw help hints describing wildcards etc. which shows after user enters one of such mea-characters in search field.