summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_operations/tests.py15
-rw-r--r--ishtar_common/views_item.py19
2 files changed, 27 insertions, 7 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 4edf62e22..f8925f610 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -1661,6 +1661,21 @@ class OperationSearchTest(TestCase, OperationInitTest):
search_open_q = unicode(pgettext("key for text search", u"is-open"))
self._test_search(c, search_open_q, u"Yes", 2, "Boolean")
+ def test_mixed_search_vector(self):
+ operation_1 = models.Operation.objects.get(pk=self.operations[0].pk)
+ operation_1.common_name = u"Opération : Château de Fougères"
+ operation_1.year = 2042
+ operation_1.save()
+
+ c = Client()
+ c.login(username=self.username, password=self.password)
+
+ search_year_q = unicode(pgettext("key for text search", u"year"))
+ q = '"chateau fougere" {}="2042"'.format(search_year_q)
+ response = c.get(reverse('get-operation'), {'search_vector': q})
+ result = json.loads(response.content)
+ self.assertEqual(result['recordsTotal'], 1)
+
def create_relations(self):
rel1 = models.RelationType.objects.create(
symmetrical=True, label='Include', txt_idx='include')
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 7c6cbc24a..c14973bc3 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -391,7 +391,7 @@ def _parse_parentheses_groups(groups, request_keys, current_dct=None,
SEP = u"?ç;?" # replace spaces inside quote with this characters
previous_quote = None
while found != -1:
- if previous_quote:
+ if previous_quote is not None:
string = string[0:previous_quote] + \
string[previous_quote:found].replace(u' ', SEP) + \
string[found:]
@@ -448,17 +448,22 @@ def _search_manage_search_vector(model, dct, exc_dct, request_keys):
search_query, extra_dct, extra_exc_dct = _parse_parentheses_groups(
parentheses_groups, request_keys)
dct.update(extra_dct)
+
exc_dct.update(extra_exc_dct)
if search_query:
# remove inside parenthesis
search_query = \
search_query.replace(u'(', u'').replace(u')', u'').strip()
- dct['extras'].append(
- {'where': [model._meta.db_table +
- ".search_vector @@ (to_tsquery(%s, %s)) = true"],
- 'params': [settings.ISHTAR_SEARCH_LANGUAGE,
- search_query]}
- )
+ # manage full quoted
+ if search_query.startswith(u'"') and search_query.endswith(u'"'):
+ search_query = search_query[1:-1].replace(u" ", u" & ").strip()
+ if search_query:
+ dct['extras'].append(
+ {'where': [model._meta.db_table +
+ ".search_vector @@ (to_tsquery(%s, %s)) = true"],
+ 'params': [settings.ISHTAR_SEARCH_LANGUAGE,
+ search_query]}
+ )
return dct, exc_dct