Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
rename var, update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel committed Oct 20, 2021
1 parent 3970b7c commit f1e92e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
10 changes: 7 additions & 3 deletions docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ The following query parameters are available:
- `history_visibility` - Rooms are ordered alphabetically by visibility of history of the room.
- `state_events` - Rooms are ordered by number of state events. Largest to smallest.
* `dir` - Direction of room order. Either `f` for forwards or `b` for backwards. Setting
this value to `b` will reverse the above sort order. Defaults to `f`.
this value to `b` will reverse the above sort order. Defaults to `f`.
* `search_term` - Filter rooms by their room name, canonical alias and room id.
Search term can be contained in any part of the room name and
local part of canonical alias or room id. Defaults to no filtering.
Specifically, rooms are selected if the search term is contained in
- the room's name,
- the local part of the room's canonical alias, or
- the local part of the room's id.

Defaults to no filtering.

**Response**

Expand Down
9 changes: 5 additions & 4 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ async def get_rooms_paginate(
"""
# Filter room names by a string
where_statement = ""
search_pattern = ""
if search_term:
where_statement = """
WHERE LOWER(state.name) LIKE ?
Expand All @@ -429,7 +430,7 @@ async def get_rooms_paginate(
# HOWEVER, if you put a % into your SQL then everything goes wibbly.
# To get around this, we're going to surround search_term with %'s
# before giving it to the database in python instead
search_term = [
search_pattern = [
"%" + search_term.lower() + "%",
"#%" + search_term.lower() + "%:%",
"!%" + search_term.lower() + "%:%",
Expand Down Expand Up @@ -527,9 +528,9 @@ async def get_rooms_paginate(
def _get_rooms_paginate_txn(txn):
# Execute the data query
sql_values = [limit, start]
if search_term:
if search_pattern:
# Add the search term into the WHERE clause
sql_values = search_term + sql_values
sql_values = search_pattern + sql_values
txn.execute(info_sql, sql_values)

# Refactor room query data into a structured dictionary
Expand Down Expand Up @@ -557,7 +558,7 @@ def _get_rooms_paginate_txn(txn):
# Execute the count query

# Add the search term into the WHERE clause if present
sql_values = search_term if search_term else ()
sql_values = search_pattern if search_pattern else ()
txn.execute(count_sql, sql_values)

room_count = txn.fetchone()
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ def _search_test(
r = rooms[0]
self.assertEqual(expected_room_id, r["room_id"])

# Perform search tests
# Test searching by room name
_search_test(room_id_1, "something")
_search_test(room_id_1, "thing")

Expand Down

0 comments on commit f1e92e6

Please sign in to comment.