Class QueryContext

java.lang.Object
org.codelibs.fess.entity.QueryContext

public class QueryContext extends Object
Context object that holds query-related information and state during search processing. Contains the query string, query builder, sort criteria, and various metadata.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final String
    Prefix for queries that search only in title fields.
    protected static final String
    Prefix for queries that search only in URL fields.
    protected String
    The default field to search in when no specific field is specified.
    protected boolean
    Flag indicating whether role-based query filtering should be disabled.
    protected Map<String,List<String>>
    Map storing field names and their associated query terms for logging.
    protected Set<String>
    Set of query terms that should be highlighted in search results.
    protected org.opensearch.index.query.QueryBuilder
    The OpenSearch query builder used for executing the search.
    protected String
    The original query string provided by the user.
    protected final List<org.opensearch.search.sort.SortBuilder<?>>
    List of sort builders to apply to the search query.
  • Constructor Summary

    Constructors
    Constructor
    Description
    QueryContext(String queryString, boolean isQuery)
    Constructs a new QueryContext with the specified query string.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addFieldLog(String field, String text)
    Adds a field and text pair to the field log for tracking query terms.
    void
    addFunctionScore(Consumer<List<org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder>> functionScoreQuery)
    Adds function score configuration to the query builder.
    void
    Adds a query term to the highlighted query set.
    void
    addQuery(Consumer<org.opensearch.index.query.BoolQueryBuilder> boolQuery)
    Adds additional query clauses using a boolean query builder.
    void
    addSorts(org.opensearch.search.sort.SortBuilder<?>... sortBuilders)
    Adds sort builders to the query context.
    Gets the default field for this query context.
    Gets the default field keywords from the field log.
    Gets the field log map containing field names and their associated query terms.
    Gets the set of highlighted query terms.
    org.opensearch.index.query.QueryBuilder
    Gets the query builder for this context.
    Gets the processed query string.
    boolean
    Checks if any sort builders have been added to this context.
    boolean
    Checks if role-based query filtering is enabled.
    void
    setDefaultField(String defaultField)
    Sets the default field for this query context.
    void
    setQueryBuilder(org.opensearch.index.query.QueryBuilder queryBuilder)
    Sets the query builder for this context.
    void
    Disables role-based query filtering for this context.
    List<org.opensearch.search.sort.SortBuilder<?>>
    Gets the list of sort builders for this query context.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ALLINURL_FIELD_PREFIX

      protected static final String ALLINURL_FIELD_PREFIX
      Prefix for queries that search only in URL fields.
      See Also:
    • ALLINTITLE_FIELD_PREFIX

      protected static final String ALLINTITLE_FIELD_PREFIX
      Prefix for queries that search only in title fields.
      See Also:
    • queryBuilder

      protected org.opensearch.index.query.QueryBuilder queryBuilder
      The OpenSearch query builder used for executing the search.
    • sortBuilderList

      protected final List<org.opensearch.search.sort.SortBuilder<?>> sortBuilderList
      List of sort builders to apply to the search query.
    • queryString

      protected String queryString
      The original query string provided by the user.
    • highlightedQuerySet

      protected Set<String> highlightedQuerySet
      Set of query terms that should be highlighted in search results.
    • fieldLogMap

      protected Map<String,List<String>> fieldLogMap
      Map storing field names and their associated query terms for logging.
    • disableRoleQuery

      protected boolean disableRoleQuery
      Flag indicating whether role-based query filtering should be disabled.
    • defaultField

      protected String defaultField
      The default field to search in when no specific field is specified.
  • Constructor Details

    • QueryContext

      public QueryContext(String queryString, boolean isQuery)
      Constructs a new QueryContext with the specified query string. Processes special query prefixes (allinurl:, allintitle:) and initializes request-scoped attributes for highlighting and field logging.
      Parameters:
      queryString - The query string to process.
      isQuery - Whether this is a search query (enables highlighting and logging).
  • Method Details

    • addFunctionScore

      public void addFunctionScore(Consumer<List<org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder>> functionScoreQuery)
      Adds function score configuration to the query builder.
      Parameters:
      functionScoreQuery - Consumer that configures the function score filters.
    • addQuery

      public void addQuery(Consumer<org.opensearch.index.query.BoolQueryBuilder> boolQuery)
      Adds additional query clauses using a boolean query builder.
      Parameters:
      boolQuery - Consumer that configures the boolean query.
    • setQueryBuilder

      public void setQueryBuilder(org.opensearch.index.query.QueryBuilder queryBuilder)
      Sets the query builder for this context.
      Parameters:
      queryBuilder - The query builder to use.
    • addSorts

      public void addSorts(org.opensearch.search.sort.SortBuilder<?>... sortBuilders)
      Adds sort builders to the query context.
      Parameters:
      sortBuilders - Variable number of sort builders to add.
    • hasSorts

      public boolean hasSorts()
      Checks if any sort builders have been added to this context.
      Returns:
      True if sort builders are present, false otherwise.
    • sortBuilders

      public List<org.opensearch.search.sort.SortBuilder<?>> sortBuilders()
      Gets the list of sort builders for this query context.
      Returns:
      The list of sort builders.
    • getQueryBuilder

      public org.opensearch.index.query.QueryBuilder getQueryBuilder()
      Gets the query builder for this context.
      Returns:
      The query builder.
    • addFieldLog

      public void addFieldLog(String field, String text)
      Adds a field and text pair to the field log for tracking query terms.
      Parameters:
      field - The field name.
      text - The query text for this field.
    • getDefaultKeyword

      public List<String> getDefaultKeyword()
      Gets the default field keywords from the field log.
      Returns:
      List of keywords for the default field, or empty list if none.
    • addHighlightedQuery

      public void addHighlightedQuery(String text)
      Adds a query term to the highlighted query set.
      Parameters:
      text - The query text to highlight.
    • getQueryString

      public String getQueryString()
      Gets the processed query string.
      Returns:
      The query string.
    • roleQueryEnabled

      public boolean roleQueryEnabled()
      Checks if role-based query filtering is enabled.
      Returns:
      True if role query is enabled, false otherwise.
    • skipRoleQuery

      public void skipRoleQuery()
      Disables role-based query filtering for this context.
    • getDefaultField

      public String getDefaultField()
      Gets the default field for this query context.
      Returns:
      The default field name, or null if not set.
    • setDefaultField

      public void setDefaultField(String defaultField)
      Sets the default field for this query context.
      Parameters:
      defaultField - The default field name to set.
    • getHighlightedQuerySet

      public Set<String> getHighlightedQuerySet()
      Gets the set of highlighted query terms.
      Returns:
      The set of highlighted query terms, or empty set if not initialized.
    • getFieldLogMap

      public Map<String,List<String>> getFieldLogMap()
      Gets the field log map containing field names and their associated query terms.
      Returns:
      The field log map, or empty map if not initialized.