Package org.codelibs.fess.query
Class QueryCommand
java.lang.Object
org.codelibs.fess.query.QueryCommand
- Direct Known Subclasses:
BooleanQueryCommand,BoostQueryCommand,FuzzyQueryCommand,MatchAllQueryCommand,PhraseQueryCommand,PrefixQueryCommand,TermQueryCommand,TermRangeQueryCommand,WildcardQueryCommand
Abstract base class for query command implementations.
Provides common functionality for processing and executing search queries.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceFunctional interface for building query builders with field and boost parameters.protected static interfaceFunctional interface for building field-specific query builders. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DefaultQueryBuilderbuildDefaultQueryBuilder(org.codelibs.fess.mylasta.direction.FessConfig fessConfig, QueryContext context, QueryCommand.DefaultQueryBuilderFunction builder) Builds a default query builder with configured fields and boost values.protected org.opensearch.index.query.QueryBuilderbuildMatchPhraseQuery(String f, String text) Builds a match phrase query, with special handling for single CJK characters.protected org.opensearch.index.query.QueryBuilderconvertWithFieldCheck(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.protected DefaultQueryBuilderCreates a default query builder based on the configured query type.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.abstract org.opensearch.index.query.QueryBuilderexecute(QueryContext context, org.apache.lucene.search.Query query, float boost) Executes the query command and returns a QueryBuilder.protected abstract StringGets the class name of the query this command handles.protected QueryFieldConfigGets the query field configuration.protected org.dbflute.optional.OptionalThing<String[]> Gets the query languages from the current request.protected QueryProcessorGets the query processor instance.protected StringgetSearchField(String defaultField, String field) Gets the actual search field, replacing default field placeholder if needed.protected booleanisSearchField(String field) Checks if the specified field is a search field.voidregister()Registers this query command with the query processor.
-
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
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
Gets the query field configuration.- Returns:
- The query field configuration instance.
-
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
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
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
Creates a default query builder based on the configured query type.- Returns:
- The default query builder (either dismax or bool query).
-
buildMatchPhraseQuery
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
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 configurationcontext- the query contextfield- the field nametext- the query textboost- the boost valuedefaultBuilder- function to build default queriesfieldBuilder- function to build field-specific queries- Returns:
- the constructed query builder
-