Skip to content

Commit

Permalink
The Freetext constraint now qualifies res_subject.
Browse files Browse the repository at this point in the history
This helps certain SQLServer-based implementations while not impacting
compliant ones; consider this defensive programming.
  • Loading branch information
msdemlei committed Jan 13, 2023
1 parent 8758038 commit 2caee9d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pyvo/registry/rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _get_union_condition(self, service):
"SELECT ivoid FROM rr.resource WHERE"
" 1=ivo_hasword(res_title, {{{parname}}})",
"SELECT ivoid FROM rr.res_subject WHERE"
" res_subject ILIKE {{{parpatname}}}"]
" rr.res_subject.res_subject ILIKE {{{parpatname}}}"]
self._fillers, subqueries = {}, []

for index, word in enumerate(self.words):
Expand All @@ -265,7 +265,7 @@ def _get_or_condition(self, service):
base_queries = [
" 1=ivo_hasword(res_description, {{{parname}}})",
" 1=ivo_hasword(res_title, {{{parname}}})",
" res_subject ILIKE {{{parpatname}}}"]
" rr.res_subject.res_subject ILIKE {{{parpatname}}}"]
self._fillers, conditions = {}, []

for index, word in enumerate(self.words):
Expand Down
4 changes: 2 additions & 2 deletions pyvo/registry/tests/test_regtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def keywordstest_callback(request, context):
assert "ivo_hasword(res_description, 'vizier')" in query
assert "1=ivo_hasword(res_title, 'vizier')" in query

assert " res_subject ILIKE '%pulsar%'" in query
assert ".res_subject ILIKE '%pulsar%'" in query
assert "1=ivo_hasword(res_description, 'pulsar')" in query
assert "1=ivo_hasword(res_title, 'pulsar')" in query

Expand All @@ -86,7 +86,7 @@ def keywordstest_callback(request, context):
data = dict(parse_qsl(request.body))
query = data['QUERY']

assert "OR res_subject ILIKE '%single%'" in query
assert "OR rr.res_subject.res_subject ILIKE '%single%'" in query
assert "1=ivo_hasword(res_description, 'single') " in query
assert "1=ivo_hasword(res_title, 'single')" in query

Expand Down
17 changes: 8 additions & 9 deletions pyvo/registry/tests/test_rtcons.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,30 @@ def test_basic(self):
assert rtcons.Freetext("star").get_search_condition(FAKE_GAVO) == (
"ivoid IN (SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_description, 'star') "
"UNION SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_title, 'star') "
"UNION SELECT ivoid FROM rr.res_subject WHERE res_subject ILIKE '%star%')")
"UNION SELECT ivoid FROM rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%star%')")

def test_interesting_literal(self):
assert rtcons.Freetext("α Cen's planets").get_search_condition(FAKE_GAVO) == (
"ivoid IN (SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_description, 'α Cen''s planets')"
" UNION SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_title, 'α Cen''s planets')"
" UNION SELECT ivoid FROM rr.res_subject WHERE res_subject ILIKE '%α Cen''s planets%')")
" UNION SELECT ivoid FROM rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%α Cen''s planets%')")

def test_multipleLiterals(self):
assert rtcons.Freetext("term1", "term2"
).get_search_condition(FAKE_GAVO) == (
"ivoid IN (SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_description, 'term1')"
" UNION SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_title, 'term1')"
" UNION SELECT ivoid FROM rr.res_subject WHERE res_subject ILIKE '%term1%')"
" UNION SELECT ivoid FROM rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%term1%')"
" AND "
"ivoid IN (SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_description, 'term2')"
" UNION SELECT ivoid FROM rr.resource WHERE 1=ivo_hasword(res_title, 'term2')"
" UNION SELECT ivoid FROM rr.res_subject WHERE res_subject ILIKE '%term2%')")
" UNION SELECT ivoid FROM rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%term2%')")

def test_adaption_to_service(self):
assert rtcons.Freetext("term1", "term2"
).get_search_condition(FAKE_PLAIN) == (
"( 1=ivo_hasword(res_description, 'term1') OR 1=ivo_hasword(res_title, 'term1') OR res_subject ILIKE '%term1%')"
" AND ( 1=ivo_hasword(res_description, 'term2') OR 1=ivo_hasword(res_title, 'term2') OR res_subject ILIKE '%term2%')")
"( 1=ivo_hasword(res_description, 'term1') OR 1=ivo_hasword(res_title, 'term1') OR rr.res_subject.res_subject ILIKE '%term1%')"
" AND ( 1=ivo_hasword(res_description, 'term2') OR 1=ivo_hasword(res_title, 'term2') OR rr.res_subject.res_subject ILIKE '%term2%')")


class TestAuthorConstraint:
Expand Down Expand Up @@ -336,7 +336,6 @@ def test_no_temporal(self):
== "stc_temporal missing on current RegTAP service")



class TestWhereClauseBuilding:
@staticmethod
def where_clause_for(*args, **kwargs):
Expand Down Expand Up @@ -388,11 +387,11 @@ def test_with_legacy_keyword(self):
'(ivoid IN (SELECT ivoid FROM rr.resource WHERE '
"1=ivo_hasword(res_description, 'plain') UNION SELECT ivoid FROM rr.resource "
"WHERE 1=ivo_hasword(res_title, 'plain') UNION SELECT ivoid FROM "
"rr.res_subject WHERE res_subject ILIKE '%plain%'))\n"
"rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%plain%'))\n"
' AND (ivoid IN (SELECT ivoid FROM rr.resource WHERE '
"1=ivo_hasword(res_description, 'string') UNION SELECT ivoid FROM rr.resource "
"WHERE 1=ivo_hasword(res_title, 'string') UNION SELECT ivoid FROM "
"rr.res_subject WHERE res_subject ILIKE '%string%'))")
"rr.res_subject WHERE rr.res_subject.res_subject ILIKE '%string%'))")


class TestSelectClause:
Expand Down

0 comments on commit 2caee9d

Please sign in to comment.