Class QueryCommand

java.lang.Object
org.codelibs.fess.query.QueryCommand
Direct Known Subclasses:
BooleanQueryCommand, BoostQueryCommand, FuzzyQueryCommand, MatchAllQueryCommand, PhraseQueryCommand, PrefixQueryCommand, TermQueryCommand, TermRangeQueryCommand, WildcardQueryCommand

public abstract class QueryCommand extends Object
Abstract base class for query command implementations. Provides common functionality for processing and executing search queries.
  • Constructor Details

    • QueryCommand

      public QueryCommand()
      Default constructor for QueryCommand. Creates a new instance of the query command with default settings.
  • Method Details

    • execute

      public abstract org.opensearch.index.query.QueryBuilder execute(QueryContext context, org.apache.lucene.search.Query query, float boost)
      Executes the query command and returns a QueryBuilder.
      Parameters:
      context - The query context containing search parameters.
      query - The Lucene query to execute.
      boost - The boost factor to apply.
      Returns:
      The executed QueryBuilder.
    • getQueryClassName

      protected abstract String getQueryClassName()
      Gets the class name of the query this command handles.
      Returns:
      The query class name.
    • register

      public void register()
      Registers this query command with the query processor. Associates this command with its query class name in the processor.
    • getQueryFieldConfig

      protected QueryFieldConfig getQueryFieldConfig()
      Gets the query field configuration.
      Returns:
      The query field configuration instance.
    • getQueryProcessor

      protected QueryProcessor getQueryProcessor()
      Gets the query processor instance.
      Returns:
      The query processor instance.
    • createFieldSortBuilder

      protected org.opensearch.search.sort.SortBuilder<?> createFieldSortBuilder(String field, org.opensearch.search.sort.SortOrder order)
      Creates a sort builder for the specified field and order.
      Parameters:
      field - The field name to sort by.
      order - The sort order (ascending or descending).
      Returns:
      The appropriate sort builder for the field.
    • isSearchField

      protected boolean isSearchField(String field)
      Checks if the specified field is a search field. Uses O(1) Set lookup for improved performance.
      Parameters:
      field - The field name to check.
      Returns:
      True if the field is a search field, false otherwise.
    • getQueryLanguages

      protected org.dbflute.optional.OptionalThing<String[]> getQueryLanguages()
      Gets the query languages from the current request.
      Returns:
      An optional containing the query languages array, or empty if not available.
    • buildDefaultQueryBuilder

      protected DefaultQueryBuilder buildDefaultQueryBuilder(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, QueryContext context, QueryCommand.DefaultQueryBuilderFunction builder)
      Builds a default query builder with configured fields and boost values.
      Parameters:
      fessConfig - The Fess configuration.
      context - The query context.
      builder - The function to build individual field queries.
      Returns:
      The constructed default query builder.
    • createDefaultQueryBuilder

      protected DefaultQueryBuilder createDefaultQueryBuilder()
      Creates a default query builder based on the configured query type.
      Returns:
      The default query builder (either dismax or bool query).
    • buildMatchPhraseQuery

      protected org.opensearch.index.query.QueryBuilder buildMatchPhraseQuery(String f, String text)
      Builds a match phrase query, with special handling for single CJK characters. For single CJK characters in title or content fields, uses prefix query instead.
      Parameters:
      f - The field name.
      text - The text to search for.
      Returns:
      The appropriate query builder.
    • getSearchField

      protected String getSearchField(String defaultField, String field)
      Gets the actual search field, replacing default field placeholder if needed.
      Parameters:
      defaultField - The default field to use if field is the default placeholder.
      field - The field name to check.
      Returns:
      The actual field name to use for searching.
    • convertWithFieldCheck

      protected org.opensearch.index.query.QueryBuilder convertWithFieldCheck(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, QueryContext context, String field, String text, float boost, QueryCommand.DefaultQueryBuilderFunction defaultBuilder, QueryCommand.FieldQueryBuilder fieldBuilder)
      Template method that handles the common pattern of query conversion: 1. Check if field is DEFAULT_FIELD and apply default query builder 2. Check if field is a search field and apply field-specific query 3. Fall back to default query builder for unsupported fields This reduces code duplication across query command implementations.
      Parameters:
      fessConfig - the Fess configuration
      context - the query context
      field - the field name
      text - the query text
      boost - the boost value
      defaultBuilder - function to build default queries
      fieldBuilder - function to build field-specific queries
      Returns:
      the constructed query builder