Class MemoryIndexChunkScorer

java.lang.Object
org.elasticsearch.xpack.core.common.chunks.MemoryIndexChunkScorer

public class MemoryIndexChunkScorer extends Object
Utility class for scoring pre-determined chunks using an in-memory Lucene index.
  • Field Details

  • Constructor Details

    • MemoryIndexChunkScorer

      public MemoryIndexChunkScorer()
    • MemoryIndexChunkScorer

      public MemoryIndexChunkScorer(org.apache.lucene.analysis.Analyzer analyzer)
      Parameters:
      analyzer - the analyzer used for indexing chunks and parsing query text.
  • Method Details

    • analyzer

      public org.apache.lucene.analysis.Analyzer analyzer()
    • buildQuery

      public org.apache.lucene.search.Query buildQuery(String queryText)
      Parses queryText into a boolean-OR query over CONTENT_FIELD using this scorer's analyzer. Returns null when no terms survive analysis (e.g. all stop-words).
    • scoreChunks

      public List<ScoredChunk> scoreChunks(List<String> chunks, String queryText, int maxResults, boolean backfillResults)
      Creates an in-memory index of chunks, scores them against the query text, and returns the top results ordered by relevance.
      Parameters:
      chunks - the list of text chunks to score
      queryText - the query text to compare against
      maxResults - maximum number of results to return
      backfillResults - if true, backfills no matches with the first chunks in the list with scores of 0
      Returns:
      list of scored chunks ordered by relevance
      Throws:
      ElasticsearchException - on failure scoring chunks
    • scoreChunks

      public List<ScoredChunk> scoreChunks(List<String> chunks, org.apache.lucene.search.Query query, int maxResults, boolean backfillResults)
      Scores chunks against a pre-built Query.
      Parameters:
      chunks - the list of text chunks to score
      query - the Lucene query to score against; if null no chunks will match
      maxResults - maximum number of results to return
      backfillResults - if true, backfills no matches with the first chunks in the list with scores of 0
      Returns:
      list of scored chunks ordered by relevance
      Throws:
      ElasticsearchException - on failure scoring chunks
    • toString

      public String toString()
      Overrides:
      toString in class Object