Skip to content

fix: update text_search endpoint to search v2 API (#496) - #504

Open
arybhatt4533 wants to merge 2 commits into
openfoodfacts:developfrom
arybhatt4533:fix-text-search
Open

arybhatt4533 wants to merge 2 commits into
openfoodfacts:developfrom
arybhatt4533:fix-text-search

Conversation

@arybhatt4533

Copy link
Copy Markdown

Description

This PR fixes issue #496 where text_search was returning a 503 Server Error due to the deprecation/blocking of unauthenticated GET requests on the old /cgi/search.pl endpoint.

The endpoint has been updated to use the new Search V2 API (/api/v2/search), restoring functionality for text-based product searches.

Changes Made

  • Updated text_search endpoint in src/openfoodfacts/api.py from /cgi/search.pl to /api/v2/search.
  • Removed redundant json=1 parameter as V2 returns JSON by default.
  • Updated corresponding unit tests in tests/unit/test_api.py to match the new endpoint URL.

How Has This Been Tested?

  • Ran unit tests via pytest:
    python -m pytest tests/unit/test_api.py

@hangy

@humanifest-bot

Copy link
Copy Markdown

Verification note for the existing #496 discussion, using OpenAI Codex (GPT-6, agentic verification).

I checked PR head 970a7290a8a5869de8f5784324c166212fdd15ca: all 38 unchanged SDK API tests pass locally. There is still a search-contract concern:

  • The official v2 search documentation says full-text requests are unsupported.
  • The pinned server filter explicitly removes search_terms before query construction.
  • Four cases executing that original filter forward identical empty filters for ordinary text, a distinct nonsense term and no text; a structured-brand control survives. Pagination and sorting controls also survive.

This is a source/function verification, not a live API or full-server result. The SDK's fixed response mocks establish request/response handling but cannot establish query-dependent product matching.

Reproduction scripts, exact revisions and coverage limits are available. Sharing this to support your existing work before the URL substitution is treated as restoring text-search semantics. The intended authentication/full-text contract still needs maintainer confirmation; no replacement PR or independent human review is claimed.

@sonarqubecloud

Copy link
Copy Markdown

@arybhatt4533

Copy link
Copy Markdown
Author

Thanks for the detailed verification! Yes, the endpoint URL swap restores request handling and prevents the 503 error, but as noted, Search V2's handling of raw search_terms depends on the ongoing server-side API v2 search contract updates. I've updated the branch with develop and am waiting for maintainer input (@teolemon / @hangy) on whether we should merge this endpoint update now or pair it with additional parameter mappings for V2

@TaciteOFF

Copy link
Copy Markdown

The updated tests use fixed responses, so they cannot show whether the API actually uses the search words?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants