feat #1915 support for google custom search site restricted api (#1920)

#1915 

https://developers.google.com/custom-search/v1/site_restricted_api

It is possible to search unrestricted to specific sites.
searx
goka 1 year ago committed by GitHub
parent c50fafb35d
commit 62e08f80de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -49,6 +49,7 @@ class GoogleSearchAPIWrapper(BaseModel):
google_api_key: Optional[str] = None google_api_key: Optional[str] = None
google_cse_id: Optional[str] = None google_cse_id: Optional[str] = None
k: int = 10 k: int = 10
siterestrict: bool = False
class Config: class Config:
"""Configuration for this pydantic object.""" """Configuration for this pydantic object."""
@ -56,11 +57,10 @@ class GoogleSearchAPIWrapper(BaseModel):
extra = Extra.forbid extra = Extra.forbid
def _google_search_results(self, search_term: str, **kwargs: Any) -> List[dict]: def _google_search_results(self, search_term: str, **kwargs: Any) -> List[dict]:
res = ( cse = self.search_engine.cse()
self.search_engine.cse() if self.siterestrict:
.list(q=search_term, cx=self.google_cse_id, **kwargs) cse = cse.siterestrict()
.execute() res = cse.list(q=search_term, cx=self.google_cse_id, **kwargs).execute()
)
return res.get("items", []) return res.get("items", [])
@root_validator() @root_validator()

Loading…
Cancel
Save