Skip to content

Commit

Permalink
chore:reduce result count and fix pagination handling
Browse files Browse the repository at this point in the history
Updated the API result count from 100 to 20 for better performance. Fixed pagination handling by correctly iterating through remaining pages and avoiding nested structure issues. Removed redundant checks for empty search terms in views.py to streamline the search process.
  • Loading branch information
hareshkainthdbt committed Oct 30, 2024
1 parent 8b153fc commit 6bf5d0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 6 additions & 3 deletions orp/orp_search/legislation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def search(self, config: SearchDocumentConfig):
"lang": "en",
"title": search_terms,
"text": search_terms,
"results-count": 100,
"results-count": 20,
}

# Register namespaces
Expand Down Expand Up @@ -137,12 +137,15 @@ def _extract_entries(root):
all_entries += _extract_entries(root)

morePages = int(page_data["morePages"])
logger.info(f"legislation more pages: {morePages}")
if morePages > 1:
logger.info(f"legislation more pages: {morePages}")

# Get remaining pages
for page in range(2, morePages + 1):
params["page"] = page
root, _ = _do_request()
all_entries.append(_extract_entries(root))
results = _extract_entries(root)
all_entries += results

logger.info(f"legislation total results: {len(all_entries)}")
return all_entries
6 changes: 0 additions & 6 deletions orp/orp_search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,6 @@ def search(request: HttpRequest) -> HttpResponse:
search_results = public_gateway.search(config)

# Legislation search
# If config.search_terms is empty then we don't need to
# search for legislation
if not config.search_terms or "" in config.search_terms:
logger.info("no search terms provided")
return render(request, template_name="orp.html", context=context)

if not config.document_types or "legislation" in config.document_types:
logger.info("searching for legislation: %s", config.search_terms)
legislation = Legislation()
Expand Down

0 comments on commit 6bf5d0b

Please sign in to comment.