Skip to content

Commit

Permalink
fix: limit and offset are required params for SearchQueryRegex; speci…
Browse files Browse the repository at this point in the history
…fy them in test. Fix checking of result count to be against the SearchQueryRegex limit in order to account for both QSA and default limits.
  • Loading branch information
recalcitrantsupplant committed Aug 15, 2024
1 parent b838e57 commit 26b05c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion prez/services/listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def listing_function(
# count search results - hard to do in SPARQL as the SELECT part of the query is NOT aggregated
if search_query:
count = len(list(item_graph.subjects(RDF.type, PREZ.SearchResult)))
if count == settings.search_count_limit:
if count == search_query.limit:
count_literal = f">{count-1}"
else:
count_literal = f"{count}"
Expand Down
4 changes: 2 additions & 2 deletions prez/services/query_generation/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class SearchQueryRegex(ConstructQuery):
def __init__(
self,
term: str,
limit: int,
offset: int,
predicates: Optional[List[str]] = None,
limit: int = None,
offset: int = None,
):

limit += 1 # increase the limit by one so we know if there are further pages of results.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_query_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_basic_listing():


def test_search_query_regex():
sq = SearchQueryRegex(term="test", predicates=[RDFS.label])
sq = SearchQueryRegex(term="test", predicates=[RDFS.label], limit=10, offset=0)
test = PrezQueryConstructor(
profile_triples=[
TriplesSameSubjectPath.from_spo(
Expand Down

0 comments on commit 26b05c6

Please sign in to comment.