Class WebSearchResults

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

public class WebSearchResults extends Object
Represents the response of a web search performed. This includes the list of organic search results, information about the search, and pagination information.

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

The organic search results are the web pages that are returned by the search engine in response to a search query. These results are typically ranked by relevance to the search query.

  • Constructor Details

    • WebSearchResults

      public WebSearchResults(WebSearchInformationResult searchInformation, List<WebSearchOrganicResult> results)
      Constructs a new instance of WebSearchResults.
      Parameters:
      searchInformation - The information about the web search.
      results - The list of organic search results.
    • WebSearchResults

      public WebSearchResults(Map<String,Object> searchMetadata, WebSearchInformationResult searchInformation, List<WebSearchOrganicResult> results)
      Constructs a new instance of WebSearchResults.
      Parameters:
      searchMetadata - The metadata associated with the web search.
      searchInformation - The information about the web search.
      results - The list of organic search results.
  • Method Details

    • searchMetadata

      public Map<String,Object> searchMetadata()
      Gets the metadata associated with the web search.
      Returns:
      The metadata associated with the web search.
    • searchInformation

      public WebSearchInformationResult searchInformation()
      Gets the information about the web search.
      Returns:
      The information about the web search.
    • results

      public List<WebSearchOrganicResult> results()
      Gets the list of organic search results.
      Returns:
      The list of organic search results.
    • equals

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

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

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

      public List<TextSegment> toTextSegments()
      Converts the organic search results to a list of text segments.
      Returns:
      The list of text segments.
    • toDocuments

      public List<Document> toDocuments()
      Converts the organic search results to a list of documents.
      Returns:
      The list of documents.
    • from

      public static WebSearchResults from(WebSearchInformationResult searchInformation, List<WebSearchOrganicResult> results)
      Creates a new instance of WebSearchResults from the specified parameters.
      Parameters:
      searchInformation - The information about the web search.
      results - The list of organic search results.
      Returns:
      The new instance of WebSearchResults.
    • from

      public static WebSearchResults from(Map<String,Object> searchMetadata, WebSearchInformationResult searchInformation, List<WebSearchOrganicResult> results)
      Creates a new instance of WebSearchResults from the specified parameters.
      Parameters:
      searchMetadata - The metadata associated with the search results.
      searchInformation - The information about the web search.
      results - The list of organic search results.
      Returns:
      The new instance of WebSearchResults.