Class SearchEngineUtil

java.lang.Object
org.codelibs.fess.util.SearchEngineUtil

public final class SearchEngineUtil extends Object
Utility class for search engine operations and content formatting. Provides helper methods for working with XContent builders, scrolling through search results, and converting XContent objects to different output formats.
  • Method Details

    • getXContentBuilderOutputStream

      public static OutputStream getXContentBuilderOutputStream(SearchEngineUtil.XContentBuilderCallback func, org.opensearch.core.xcontent.MediaType mediaType)
      Creates an OutputStream from an XContentBuilder using the provided callback function.
      Parameters:
      func - the callback function to build XContent
      mediaType - the media type for the content builder
      Returns:
      an OutputStream containing the built content, or an empty ByteArrayOutputStream if an error occurs
    • getXContentOutputStream

      public static OutputStream getXContentOutputStream(org.opensearch.core.xcontent.ToXContent xContent, org.opensearch.core.xcontent.MediaType mediaType)
      Creates an OutputStream from a ToXContent object with the specified media type.
      Parameters:
      xContent - the content object to convert
      mediaType - the media type for the output
      Returns:
      an OutputStream containing the converted content
    • scroll

      public static long scroll(String index, Function<org.opensearch.search.SearchHit,Boolean> callback)
      Scrolls through all documents in the specified index and applies the callback function to each hit.
      Parameters:
      index - the name of the index to scroll through
      callback - the function to apply to each search hit, returning true to continue or false to stop
      Returns:
      the number of documents processed
    • getXContentString

      public static String getXContentString(org.opensearch.core.xcontent.ToXContent xContent, org.opensearch.core.xcontent.MediaType mediaType)
      Converts a ToXContent object to its string representation using the specified media type.
      Parameters:
      xContent - the content object to convert
      mediaType - the media type for the conversion
      Returns:
      the string representation of the content
      Throws:
      org.lastaflute.di.exception.IORuntimeException - if an IO error occurs during conversion