Class WebSearchRequest

java.lang.Object
dev.langchain4j.web.search.WebSearchRequest

public class WebSearchRequest extends Object
Represents a search request that can be made by the user to perform searches in any implementation of WebSearchEngine.

WebSearchRequest follow opensearch foundation standard implemented by most web search engine libs like Google, Bing, Yahoo, etc. OpenSearch#parameters

The searchTerms are the keywords that the search client desires to search for. This param is mandatory to perform a search.


Configurable parameters (optional):

  • maxResults - The expected number of results to be found if the search request were made. Each search engine may have a different limit for the maximum number of results that can be returned.
  • language - The desired language for search results is a string that indicates that the search client desires search results in the specified language. Each search engine may have a different set of supported languages.
  • geoLocation - The desired geolocation for search results is a string that indicates that the search client desires search results in the specified geolocation. Each search engine may have a different set of supported geolocations.
  • startPage - The start page number for search results is the page number of the set of search results desired by the search user.
  • startIndex - The start index for search results is the index of the first search result desired by the search user. Each search engine may have a different set of supported start indexes in combination with the start page number.
  • safeSearch - The safe search flag is a boolean that indicates that the search client desires search results with safe search enabled or disabled.
  • additionalParams - The additional parameters for the search request are a map of key-value pairs that represent additional parameters for the search request. It's a way to be flex and add custom param for each search engine.
  • Method Details

    • searchTerms

      public String searchTerms()
      Get the search terms.
      Returns:
      The search terms.
    • maxResults

      public Integer maxResults()
      Get the maximum number of results.
      Returns:
      The maximum number of results.
    • language

      public String language()
      Get the desired language for search results.
      Returns:
      The desired language for search results.
    • geoLocation

      public String geoLocation()
      Get the desired geolocation for search results.
      Returns:
      The desired geolocation for search results.
    • startPage

      public Integer startPage()
      Get the start page number for search results.
      Returns:
      The start page number for search results.
    • startIndex

      public Integer startIndex()
      Get the start index for search results.
      Returns:
      The start index for search results.
    • safeSearch

      public Boolean safeSearch()
      Get the safe search flag.
      Returns:
      The safe search flag.
    • additionalParams

      public Map<String,Object> additionalParams()
      Get the additional parameters for the search request.
      Returns:
      The additional parameters for the search request.
    • equals

      public boolean equals(Object another)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static WebSearchRequest.Builder builder()
      Create a new builder instance.
      Returns:
      A new builder instance.
    • from

      public static WebSearchRequest from(String searchTerms)
      Create a web search request with the given search terms.
      Parameters:
      searchTerms - The search terms.
      Returns:
      The web search request.
    • from

      public static WebSearchRequest from(String searchTerms, Integer maxResults)
      Create a web search request with the given search terms and maximum number of results.
      Parameters:
      searchTerms - The search terms.
      maxResults - The maximum number of results.
      Returns:
      The web search request.