Skip to content

Commit 7f77f13

Browse files
author
David Robertson
committed
Revert "Fix tests for change in PostgreSQL 14 behavior change. (#14310)"
This reverts commit 6758328.
1 parent 220af1d commit 7f77f13

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

synapse/storage/databases/main/search.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,9 @@ def _tokenize_query(query: str) -> TokenList:
824824
in_phrase = False
825825
parts = deque(query.split('"'))
826826
for i, part in enumerate(parts):
827-
# The contents inside double quotes is treated as a phrase.
828-
in_phrase = bool(i % 2)
827+
# The contents inside double quotes is treated as a phrase, a trailing
828+
# double quote is not implied.
829+
in_phrase = bool(i % 2) and i != (len(parts) - 1)
829830

830831
# Pull out the individual words, discarding any non-word characters.
831832
words = deque(re.findall(r"([\w\-]+)", part, re.UNICODE))

tests/storage/test_room_search.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class MessageSearchTest(HomeserverTestCase):
239239
("fox -nope", (True, False)),
240240
("fox -brown", (False, True)),
241241
('"fox" quick', True),
242+
('"fox quick', True),
242243
('"quick brown', True),
243244
('" quick "', True),
244245
('" nope"', False),
@@ -268,15 +269,6 @@ def prepare(
268269
response = self.helper.send(self.room_id, self.PHRASE, tok=self.access_token)
269270
self.assertIn("event_id", response)
270271

271-
# The behaviour of a missing trailing double quote changed in PostgreSQL 14
272-
# from ignoring the initial double quote to treating it as a phrase.
273-
main_store = homeserver.get_datastores().main
274-
found = False
275-
if isinstance(main_store.database_engine, PostgresEngine):
276-
assert main_store.database_engine._version is not None
277-
found = main_store.database_engine._version < 140000
278-
self.COMMON_CASES.append(('"fox quick', (found, True)))
279-
280272
def test_tokenize_query(self) -> None:
281273
"""Test the custom logic to tokenize a user's query."""
282274
cases = (
@@ -288,9 +280,9 @@ def test_tokenize_query(self) -> None:
288280
("fox -brown", ["fox", SearchToken.Not, "brown"]),
289281
("- fox", [SearchToken.Not, "fox"]),
290282
('"fox" quick', [Phrase(["fox"]), SearchToken.And, "quick"]),
291-
# No trailing double quote.
292-
('"fox quick', [Phrase(["fox", "quick"])]),
293-
('"-fox quick', [Phrase(["-fox", "quick"])]),
283+
# No trailing double quoe.
284+
('"fox quick', ["fox", SearchToken.And, "quick"]),
285+
('"-fox quick', [SearchToken.Not, "fox", SearchToken.And, "quick"]),
294286
('" quick "', [Phrase(["quick"])]),
295287
(
296288
'q"uick brow"n',

0 commit comments

Comments
 (0)