Class CachingEnableFilterQuery

java.lang.Object
org.apache.lucene.search.Query
org.elasticsearch.search.vectors.CachingEnableFilterQuery

public class CachingEnableFilterQuery extends org.apache.lucene.search.Query
A query wrapper that ensures the inner query is always eligible for query caching.

Lucene uses heuristics to determine whether a query should be cached (UsageTrackingQueryCachingPolicy), and some queries may be skipped if they are considered too cheap or otherwise uninteresting for caching. Wrapping a query in CachingEnableFilterQuery guarantees that it will be treated as cacheable by the query cache.

This wrapper does not alter the scoring or filtering semantics of the inner query. It only changes how the query cache perceives it, by making it always considered interesting enough to cache.

This is particularly useful in cases where the filter is always entirely consumed, such as filtered vector search, where the filter is transformed into a bitset eagerly. In these scenarios, caching the filter query can significantly improve performance and avoid recomputation.

Example usage:


 Query inner = new TermQuery(new Term("field", "value"));
 Query cacheable = new CacheWrapperQuery(inner);
 TopDocs results = searcher.search(cacheable, 10);
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    CachingEnableFilterQuery(org.apache.lucene.search.Query in)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.lucene.search.Weight
    createWeight(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.ScoreMode scoreMode, float boost)
     
    boolean
     
    int
     
    org.apache.lucene.search.Query
    rewrite(org.apache.lucene.search.IndexSearcher indexSearcher)
     
     
    void
    visit(org.apache.lucene.search.QueryVisitor visitor)
     

    Methods inherited from class org.apache.lucene.search.Query

    classHash, sameClassAs, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CachingEnableFilterQuery

      public CachingEnableFilterQuery(org.apache.lucene.search.Query in)
  • Method Details

    • createWeight

      public org.apache.lucene.search.Weight createWeight(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.ScoreMode scoreMode, float boost) throws IOException
      Overrides:
      createWeight in class org.apache.lucene.search.Query
      Throws:
      IOException
    • rewrite

      public org.apache.lucene.search.Query rewrite(org.apache.lucene.search.IndexSearcher indexSearcher) throws IOException
      Overrides:
      rewrite in class org.apache.lucene.search.Query
      Throws:
      IOException
    • toString

      public String toString(String field)
      Specified by:
      toString in class org.apache.lucene.search.Query
    • visit

      public void visit(org.apache.lucene.search.QueryVisitor visitor)
      Specified by:
      visit in class org.apache.lucene.search.Query
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in class org.apache.lucene.search.Query
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class org.apache.lucene.search.Query