Skip to content

Commit

Permalink
Merge pull request #167 from TranslatorSRI/return-nothing-on-empty-query
Browse files Browse the repository at this point in the history
This PR catches cases where NameRes is queried with an empty string, and causes it to return an empty set of results.

(Currently we actually return everything in our index sorted from the highest clique count to the lowest, which is cute but not really necessary.)

Closes #131.
  • Loading branch information
gaurav authored Oct 19, 2024
2 parents 9b18de1 + fe22016 commit 3ffaefd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ async def lookup(string: str,
will be returned, rather than filtering to concepts that are both PhenotypicFeature and Disease.
"""

# Do we have a search string at all?
if string.strip() == "":
return []

# First, we lowercase the query since all our indexes are case-insensitive.
string_lc = string.lower()

Expand Down Expand Up @@ -492,5 +496,5 @@ async def lookup(string: str,
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
FastAPIInstrumentor.instrument_app(app, tracer_provider=provider, excluded_urls=
"docs,openapi.json")
"docs,openapi.json")
HTTPXClientInstrumentor().instrument()
9 changes: 9 additions & 0 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def test_simple_check():
#There are more than 10, but it should cut off at 10 if we don't give it a max?
assert len(syns) == 10


def test_empty():
""" Checks that calling NameRes without an input string return an empty list. """
client = TestClient(app)
response = client.get("/lookup", params={'string':''})
syns = response.json()
assert len(syns) == 0


def test_limit():
client = TestClient(app)
params = {'string': 'alzheimer', 'limit': 1}
Expand Down

0 comments on commit 3ffaefd

Please sign in to comment.