Skip to content

Commit

Permalink
Add LIMIT & OFFSET to Search query (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
recalcitrantsupplant authored Oct 4, 2023
1 parent a8e64b4 commit 630d403
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion prez/models/search_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class SearchMethod(BaseModel):
def __hash__(self):
return hash(self.uri)

def populate_query(self, term, limit, focus_to_filter, filter_to_focus, predicates):
def populate_query(self, term, limit, offset, focus_to_filter, filter_to_focus, predicates):
self.populated_query = self.template_query.substitute(
{
"TERM": term,
"LIMIT": limit,
"OFFSET": offset,
"FOCUS_TO_FILTER": focus_to_filter,
"FILTER_TO_FOCUS": filter_to_focus,
"PREDICATES": predicates,
Expand Down
3 changes: 2 additions & 1 deletion prez/reference_data/search_methods/search_default.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ prez:default
}
}
GROUP BY ?search_result_uri ?predicate ?match
LIMIT $LIMIT
ORDER BY DESC(?weight)
LIMIT $LIMIT OFFSET $OFFSET
}
""" .
3 changes: 2 additions & 1 deletion prez/routers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async def search(
):
term = request.query_params.get("term")
limit = request.query_params.get("limit", 20)
offset = request.query_params.get("offset", 0)
foc_2_filt, filt_2_foc = extract_qsa_params(request.query_params)
if not term:
return PlainTextResponse(
Expand Down Expand Up @@ -59,7 +60,7 @@ async def search(
)
predicates_sparql_string = " ".join(f"<{p}>" for p in predicates)
search_query.populate_query(
term, limit, filter_to_focus_str, focus_to_filter_str, predicates_sparql_string
term, limit, offset, filter_to_focus_str, focus_to_filter_str, predicates_sparql_string
)

full_query = generate_item_construct(
Expand Down

0 comments on commit 630d403

Please sign in to comment.