Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions openfoodfacts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,21 @@ def __init__(
self.facet = FacetResource(self.api_config)
self.robotoff = RobotoffResource(self.api_config)

def search_advanced(self, query: str, filters: dict = None, page: int = 1):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid type for filters parameter here:

Suggested change
def search_advanced(self, query: str, filters: dict = None, page: int = 1):
def search_advanced(self, query: str, filters: Optional[dict] = None, page: int = 1):

"""Advanced product search using Search-a-licious endpoint."""
filters = filters or {}
params = {"search_terms": query, "page": page, **filters}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search terms should be provided using the q parameter, see the search-a-licious documentation here: https://search.openfoodfacts.org/docs#/default/search_get_search_get

url = f"{self.product.base_url}/cgi/search.pl"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not search-a-licious endpoint, https://search.openfoodfacts.org/search is the right one

response = send_get_request(
url=url,
api_config=self.api_config,
params=params,
auth=get_http_auth(self.api_config.environment),
)
if response is None:
return {}
return response


def parse_ingredients(text: str, lang: str, api_config: APIConfig) -> list[JSONType]:
"""Parse ingredients text using Product Opener API.
Expand Down
Loading