Class ContextQuery

All Implemented Interfaces:
Accountable

public class ContextQuery extends CompletionQuery implements Accountable
A CompletionQuery that matches documents specified by a wrapped CompletionQuery supporting boosting and/or filtering by specified contexts.

Use this query against ContextSuggestField

Example of using a CompletionQuery with boosted contexts:

  CompletionQuery completionQuery = ...;
  ContextQuery query = new ContextQuery(completionQuery);
  query.addContext("context1", 2);
  query.addContext("context2", 1);
 

NOTE:

WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Field Details

  • Constructor Details

  • Method Details

    • addContext

      public void addContext(CharSequence context)
      Adds an exact context with default boost of 1
    • addContext

      public void addContext(CharSequence context, float boost)
      Adds an exact context with boost
    • addContext

      public void addContext(CharSequence context, float boost, boolean exact)
      Adds a context with boost, set exact to false if the context is a prefix of any indexed contexts
    • addAllContexts

      public void addAllContexts()
      Add all contexts with a boost of 1f
    • toString

      public String toString(String field)
      Overrides:
      toString in class CompletionQuery
    • createWeight

      public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException
      Overrides:
      createWeight in class Query
      Throws:
      IOException
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in class Query
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class Query
    • visit

      public void visit(QueryVisitor visitor)
      Specified by:
      visit in class Query
    • ramBytesUsed

      public long ramBytesUsed()
      Specified by:
      ramBytesUsed in interface Accountable