Repository: matrix-org/synapse

Issue:
room directory search is case sensitive in synapse 1.5.0
Hello folks. Originally posed this in Riot Web/Desktop room, and they told me the issue is a "Synapse" issue. I'm a knob so I had to look up what that is, and then come find this room. And with that setup info... Wanted to mention again what seems to me to be something simple to fix. I'm using the riot desktop app. I notice if I go to "explore" and type in a word, that the search is case sensitive. Seems the search should be case insensitive, and would simple fix. Enjoy life!


Discussion:
"Explore" is the room directory search?

afaik it is case-insensitive already. Perhaps you can give an example of what you're searching for, and what you'd expect to find that you're not?
@richvdh Thanks for the response. Yeah... when you click the link the popup says "Explore rooms
If you can't find the room you're looking for, ask for an invite or Create a new room."

I've built a little test room, and ended up adding the items I wanted found with BOTH the capitalization and not, but you can still see how it works "or doesn't" by searching on both "richgriese" and then "RichGriese". It only finds the one that is capitalized. The search searches BOTH the room name and the description.

The search is case insensitive on both room name and description. For example. The room I made is called "webulite", and if you search on "Webulite" it does not get found. So it's both the room name and the room description text issue.
Ah sorry, this is something that has changed in synapse 1.5. I was testing against 1.4.1. 
@richvdh So it sounds like what you're saying is... That the matrix.org riot server instance uses Synapse as part of it's install... and that if/when they update their instance software that the feature will instantly change?
no, I'm saying that the matrix.org matrix homeserver is using (the forthcoming) synapse 1.5.0 release, where room-directory search is case-sensitive.

I was testing on a different homeserver, which is running synapse 1.4.1, which is why I didn't see the case-sensitive behaviour earlier. 
@richvdh that seems strange. You mean Synapse is moving from being case insensitive to case sensitive on room searches? Is that a bug for the 1.5 release? Or is there a reason to move to these searches being case insensitive?
it was not deliberate afaik. Synapse 1.5 includes a rewrite of the room directory to make it much faster.
@richvdh That's "good" news to some extent... in that it was not a decision which I would argue with, but more of a "bug" that snuck in as part of attempts to improve something different (speed).

So... now the question is... is there a way to re-class this post as a bug instead of a feature request? when I created it the system presented me with 3 choices, bug, suggestion, and something I forgot. I chose feature request. From what your tell me, I would not consider this a bug for the upcoming / recent(?) 1.5 synapse release.

Resolving patch:
diff --git a/synapse/storage/data_stores/main/room.py b/synapse/storage/data_stores/main/room.py
--- a/synapse/storage/data_stores/main/room.py
+++ b/synapse/storage/data_stores/main/room.py
@@ -201,13 +201,17 @@ def get_largest_public_rooms(
             where_clauses.append(
                 """
                     (
-                        name LIKE ?
-                        OR topic LIKE ?
-                        OR canonical_alias LIKE ?
+                        LOWER(name) LIKE ?
+                        OR LOWER(topic) LIKE ?
+                        OR LOWER(canonical_alias) LIKE ?
                     )
                 """
             )
-            query_args += [search_term, search_term, search_term]
+            query_args += [
+                search_term.lower(),
+                search_term.lower(),
+                search_term.lower(),
+            ]
 
         where_clause = ""
         if where_clauses:


Test patch: