Class RankFusionProcessor

java.lang.Object
org.codelibs.fess.rank.fusion.RankFusionProcessor
All Implemented Interfaces:
AutoCloseable

public class RankFusionProcessor extends Object implements AutoCloseable
RankFusionProcessor manages multiple search engines and combines their results using rank fusion algorithms. This processor supports searching with multiple searchers concurrently and merging their results based on ranking scores to provide more comprehensive and accurate search results. The processor maintains a pool of searchers and an executor service for concurrent operations. It implements rank fusion techniques to combine results from different search engines and provides a unified search interface.
  • Field Details

    • searchers

      protected final List<RankFusionSearcher> searchers
      Thread-safe list of rank fusion searchers available for processing search requests
    • executorService

      protected ExecutorService executorService
      Executor service for concurrent search operations across multiple searchers
    • windowSize

      protected int windowSize
      Size of the window for rank fusion processing, determines how many results to consider
    • availableSearcherNameSet

      protected Set<String> availableSearcherNameSet
      Set of available searcher names that can be used for search processing
  • Constructor Details

    • RankFusionProcessor

      public RankFusionProcessor()
      Default constructor for RankFusionProcessor. Initializes the processor with default values. The actual initialization is performed by the init() method which is called after construction.
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes the rank fusion processor after construction. Sets up the window size based on configuration and loads available searchers. This method is called automatically after the bean is constructed.
    • update

      public void update()
      Updates the processor configuration by reloading available searchers. This method executes the load operation asynchronously in a separate thread.
    • load

      protected void load()
      Loads the available searcher names from system properties. Parses the "rank.fusion.searchers" system property to determine which searchers are available for use in rank fusion processing.
    • close

      @PreDestroy public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • search

      public List<Map<String,Object>> search(String query, SearchRequestParams params, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean)
      Performs a search operation using rank fusion across available searchers. If only one searcher is available, uses the main searcher. Otherwise, performs concurrent searches across multiple searchers and fuses the results.
      Parameters:
      query - the search query string
      params - search request parameters including pagination and filters
      userBean - optional user information for personalized search
      Returns:
      list of search result documents with fused ranking scores
    • getAvailableSearchers

      protected RankFusionSearcher[] getAvailableSearchers()
      Gets the array of available searchers based on configuration. Filters the searchers list to include only those specified in the available searcher name set. If no specific searchers are configured, returns all searchers.
      Returns:
      array of available RankFusionSearcher instances
    • searchWithMultipleSearchers

      protected List<Map<String,Object>> searchWithMultipleSearchers(RankFusionSearcher[] searchers, String query, SearchRequestParams params, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean)
      Performs concurrent searches using multiple searchers and fuses the results. Executes searches in parallel across all provided searchers, then combines the results using rank fusion algorithms to produce a unified result set.
      Parameters:
      searchers - array of searchers to use for concurrent searching
      query - the search query string
      params - search request parameters including pagination and filters
      userBean - optional user information for personalized search
      Returns:
      list of search result documents with fused ranking scores
    • extractList

      protected List<Map<String,Object>> extractList(List<Map<String,Object>> docs, int pageSize, int startPosition)
      Extracts a subset of documents from the full result list based on pagination parameters. Applies proper bounds checking to ensure the extracted range is within the document list size.
      Parameters:
      docs - the full list of search result documents
      pageSize - the number of documents to include in the page
      startPosition - the starting position for pagination
      Returns:
      sublist of documents for the requested page
    • searchWithMainSearcher

      protected List<Map<String,Object>> searchWithMainSearcher(RankFusionSearcher searcher, String query, SearchRequestParams params, org.dbflute.optional.OptionalThing<org.codelibs.fess.mylasta.action.FessUserBean> userBean)
      Performs a search using only the main searcher without rank fusion. This method is used when only one searcher is available or configured.
      Parameters:
      searcher - the main searcher to use for the search operation
      query - the search query string
      params - search request parameters including pagination and filters
      userBean - optional user information for personalized search
      Returns:
      list of search result documents from the main searcher
    • createResponseList

      protected QueryResponseList createResponseList(List<Map<String,Object>> documentList, long allRecordCount, String allRecordCountRelation, long queryTime, boolean partialResults, FacetResponse facetResponse, int start, int pageSize, int offset)
      Creates a QueryResponseList containing the search results and metadata. Wraps the document list with additional information about the search operation including record counts, timing, and pagination details.
      Parameters:
      documentList - the list of search result documents
      allRecordCount - the total number of records found
      allRecordCountRelation - the relationship of the record count (exact, approximate, etc.)
      queryTime - the time taken to execute the search query
      partialResults - whether the results are partial due to timeout or other constraints
      facetResponse - the facet information for the search results
      start - the starting position for pagination
      pageSize - the size of the current page
      offset - the offset applied to the results
      Returns:
      QueryResponseList containing the search results and metadata
    • toFloat

      protected float toFloat(Object value)
      Converts an object value to a float for score calculations. Handles Float and String types, returning 0.0f for unsupported types.
      Parameters:
      value - the object to convert to float
      Returns:
      float representation of the value, or 0.0f if conversion fails
    • setSearcher

      public void setSearcher(RankFusionSearcher searcher)
      Sets the main searcher at index 0 of the searchers list. This method is used to configure the primary searcher for rank fusion processing. If searchers list is empty, adds the searcher; otherwise, replaces the first searcher.
      Parameters:
      searcher - the RankFusionSearcher to set as the main searcher
    • register

      public void register(RankFusionSearcher searcher)
      Registers a new searcher with the rank fusion processor. Adds the searcher to the searchers list and initializes the executor service if it hasn't been created yet. The executor service is created with a thread pool sized based on configuration or system capabilities.
      Parameters:
      searcher - the RankFusionSearcher to register