Class GoogleCustomWebSearchEngine
java.lang.Object
dev.langchain4j.web.search.google.customsearch.GoogleCustomWebSearchEngine
- All Implemented Interfaces:
WebSearchEngine
An implementation of a
WebSearchEngine that uses
Google Custom Search API for performing web searches.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuilder()search(WebSearchRequest webSearchRequest) Performs a search request on the web search engine and returns the search results.static GoogleCustomWebSearchEnginewithApiKeyAndCsi(String apiKey, String csi) Creates a new builder for constructing a GoogleCustomWebSearchEngine with the specified API key and Custom Search ID.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface WebSearchEngine
search
-
Constructor Details
-
GoogleCustomWebSearchEngine
public GoogleCustomWebSearchEngine(String apiKey, String csi, Boolean siteRestrict, Boolean includeImages, Duration timeout, Integer maxRetries, Boolean logRequests, Boolean logResponses) Constructs a new GoogleCustomWebSearchEngine with the specified parameters.- Parameters:
apiKey- the Google Search API key for accessing the Google Custom Search APIYou can just generate an API key here
csi- the Custom Search ID parameter for search the entire webYou can create a Custom Search Engine here
siteRestrict- if your Search Engine is restricted to only searching specific sites, you can set this parameter to true.Default value is false. View the documentation for more information here
includeImages- If it is true then include public images relevant to the query. This can add more latency to the search.Default value is false.
timeout- the timeout duration for API requestsDefault value is 60 seconds.
maxRetries- the maximum number of retries for API requestsDefault value is 2.
logRequests- whether to log API requestsDefault value is false.
logResponses- whether to log API responsesDefault value is false.
-
-
Method Details
-
withApiKeyAndCsi
Creates a new builder for constructing a GoogleCustomWebSearchEngine with the specified API key and Custom Search ID.- Parameters:
apiKey- the API key for accessing the Google Custom Search APIcsi- the Custom Search ID parameter for search the entire web- Returns:
- a new builder instance
-
builder
-
search
Description copied from interface:WebSearchEnginePerforms a search request on the web search engine and returns the search results.- Specified by:
searchin interfaceWebSearchEngine- Parameters:
webSearchRequest- the search request- Returns:
- the web search results
-