Class WebSearchOrganicResult

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

public class WebSearchOrganicResult extends Object
Represents organic search results, which are the web pages returned by a search engine in response to a query. This includes the title, URL, snippet and/or content, and metadata of the web page.

These results are typically ranked by relevance to the search query.

Snippet vs Content:
A snippet is a concise extract or summary from the web page relevant to the query. It is meant for preview purposes.
Content (if available) refers to the full textual content extracted from the web page.

Search Engine Specific Behavior:
- Google: Snippet is a short preview (from Google's API); content is typically null.
- Tavily: Snippet contains a short extract of content that is most relevant to the search query; content includes the full raw page content.

  • Constructor Details

    • WebSearchOrganicResult

      public WebSearchOrganicResult(String title, URI url)
      Constructs a WebSearchOrganicResult object with the given title and URL.
      Parameters:
      title - The title of the search result.
      url - The URL associated with the search result.
    • WebSearchOrganicResult

      public WebSearchOrganicResult(String title, URI url, String snippet, String content)
      Constructs a WebSearchOrganicResult object with the given title, URL, snippet and/or content.
      Parameters:
      title - The title of the search result.
      url - The URL associated with the search result.
      snippet - The snippet of the search result, in plain text.
      content - The most query related content from the scraped url.
    • WebSearchOrganicResult

      public WebSearchOrganicResult(String title, URI url, String snippet, String content, Map<String,String> metadata)
      Constructs a WebSearchOrganicResult object with the given title, URL, snippet and/or content, and metadata.
      Parameters:
      title - The title of the search result.
      url - The URL associated with the search result.
      snippet - The snippet of the search result, in plain text.
      content - The most query related content from the scraped url.
      metadata - The metadata associated with the search result.
  • Method Details

    • title

      public String title()
      Returns the title of the web page.
      Returns:
      The title of the web page.
    • url

      public URI url()
      Returns the URL associated with the web page.
      Returns:
      The URL associated with the web page.
    • snippet

      public String snippet()
      Returns the snippet associated with the web page.
      Returns:
      The snippet associated with the web page.
    • content

      public String content()
      Returns the content scraped from the web page.
      Returns:
      The content scraped from the web page.
    • metadata

      public Map<String,String> metadata()
      Returns the result metadata associated with the search result.
      Returns:
      The result metadata associated with the search result.
    • 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
    • toTextSegment

      public TextSegment toTextSegment()
      Converts this WebSearchOrganicResult to a TextSegment.
      Returns:
      The TextSegment representation of this WebSearchOrganicResult.
    • toDocument

      public Document toDocument()
      Converts this WebSearchOrganicResult to a Document.
      Returns:
      The Document representation of this WebSearchOrganicResult.
    • from

      public static WebSearchOrganicResult from(String title, URI url)
      Creates a WebSearchOrganicResult object from the given title and URL.
      Parameters:
      title - The title of the search result.
      url - The URL associated with the search result.
      Returns:
      The created WebSearchOrganicResult object.
    • from

      public static WebSearchOrganicResult from(String title, URI url, String snippet, String content)
      Creates a WebSearchOrganicResult object from the given title, URL, snippet and/or content.
      Parameters:
      title - The title of the search result.
      url - The URL associated with the search result.
      snippet - The snippet of the search result, in plain text.
      content - The most query related content from the scraped url.
      Returns:
      The created WebSearchOrganicResult object.
    • from

      public static WebSearchOrganicResult from(String title, URI url, String snippet, String content, Map<String,String> metadata)
      Creates a WebSearchOrganicResult object from the given title, URL, snippet and/or content, and result metadata.
      Parameters:
      title - The title of the search result.
      url - The URL associated with the search result.
      snippet - The snippet of the search result, in plain text.
      content - The most query related content from the scraped url.
      metadata - The metadata associated with the search result.
      Returns:
      The created WebSearchOrganicResult object.