Merge pull request #510 from taigaio/Issue/3445/to_tsquery-function-not-working-properly

Fixing ts_query function
remotes/origin/logger
David Barragán Merino 2015-11-04 10:13:01 +01:00
commit ed483e9970
2 changed files with 27 additions and 1 deletions

View File

@ -204,6 +204,7 @@ def to_tsquery(term):
continue
bit = bit.replace("'", "")
bit = bit.replace("\\", "")
if not bit:
continue

View File

@ -17,9 +17,10 @@
from unittest import mock
import django_sites as sites
import re
from taiga.base.utils.urls import get_absolute_url, is_absolute_url, build_url
from taiga.base.utils.db import save_in_bulk, update_in_bulk, update_in_bulk_with_ids
from taiga.base.utils.db import save_in_bulk, update_in_bulk, update_in_bulk_with_ids, to_tsquery
def test_is_absolute_url():
@ -89,3 +90,27 @@ def test_update_in_bulk_with_ids():
]
model.objects.filter.assert_has_calls(expected_calls)
TS_QUERY_TRANSFORMATIONS = [
("1 OR 2", "1 | 2"),
("(1) 2", "( 1 ) & 2"),
("&", "'&':*"),
('"hello world"', "'hello world'"),
("not 1", "! 1"),
("1 and not (2 or 3)", "1 & ! ( 2 | 3 )"),
("not and and 1) or ( 2 not", "! 1 | ( 2 )"),
("() 1", "1"),
("1 2 3", "1 & 2 & 3"),
("'&' |", "'&':* & '|':*"),
(") and 1 (2 or", "1 & ( 2 )"),
("it's '", "'its':*"),
("(1)", "( 1 )"),
("1((", "1"),
("test\\", "'test':*"),
]
def test_to_tsquery():
for (input, expected) in TS_QUERY_TRANSFORMATIONS:
expected = re.sub("([0-9])", r"'\1':*", expected)
actual = to_tsquery(input)
assert actual == expected