Class DefaultQueryParser
- All Implemented Interfaces:
org.apache.lucene.queryparser.classic.QueryParserConstants,org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
Automatic right truncation if enabled with property query.lucene.use-right-truncation.
Additionnal behavior can be configured through properties :
- Disable wildcard query through property
query.lucene.wildcard.enabled. - Disable fuzzy query through property
query.lucene.fuzzy.enabled. - Use scoring boolean rewrite
- for all multi-term query, right truncation PrefixQuery, through property
query.lucene.scoring-boolean-rewrite.all.enabled. - for right truncation PrefixQuery only, through property
query.lucene.scoring-boolean-rewrite.right-truncation.enabled.
- for all multi-term query, right truncation PrefixQuery, through property
- Since:
- jcms-10.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.queryparser.classic.QueryParser
org.apache.lucene.queryparser.classic.QueryParser.OperatorNested classes/interfaces inherited from class org.apache.lucene.util.QueryBuilder
org.apache.lucene.util.QueryBuilder.TermAndBoost -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanstatic booleanstatic StringA regular expression used to match words in user's search string for which right truncation will NOT be applied.static booleanFields inherited from class org.apache.lucene.queryparser.classic.MultiFieldQueryParser
boosts, fieldsFields inherited from class org.apache.lucene.queryparser.classic.QueryParser
DEFAULT_SPLIT_ON_WHITESPACE, jj_nt, token, token_sourceFields inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
AND_OPERATOR, field, OR_OPERATORFields inherited from class org.apache.lucene.util.QueryBuilder
analyzer, autoGenerateMultiTermSynonymsPhraseQuery, enableGraphQueries, enablePositionIncrementsFields inherited from interface org.apache.lucene.queryparser.classic.QueryParserConstants
_ESCAPED_CHAR, _NUM_CHAR, _QUOTED_CHAR, _TERM_CHAR, _TERM_START_CHAR, _WHITESPACE, AND, BAREOPER, Boost, CARAT, COLON, DEFAULT, EOF, FUZZY_SLOP, LPAREN, MINUS, NOT, NUMBER, OR, PLUS, PREFIXTERM, QUOTED, Range, RANGE_GOOP, RANGE_QUOTED, RANGE_TO, RANGEEX_END, RANGEEX_START, RANGEIN_END, RANGEIN_START, REGEXPTERM, RPAREN, STAR, TERM, tokenImage, WILDTERM -
Constructor Summary
ConstructorsConstructorDescriptionDefaultQueryParser(String[] fields, org.apache.lucene.analysis.Analyzer analyzer, Map<String, Float> boosts, ParseOptions options) Creates a DefaultQueryParser.DefaultQueryParser(String field, org.apache.lucene.analysis.Analyzer analyzer, ParseOptions options) Deprecated, for removal: This API element is subject to removal in a future version.since use of MultiFieldQueryParser with JCMS-11884 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddMultiTermClauses(List<org.apache.lucene.search.BooleanClause> clauses, org.apache.lucene.search.Query q) static floatgetFieldBoost(ParseOptions.Engine engine, String fieldName) Return the boost that should be applied to a field at query time for text search.protected org.apache.lucene.search.QuerygetFieldQuery(String field, String queryText, boolean quoted) protected org.apache.lucene.search.QuerygetFuzzyQuery(String field, String termStr, float minSimilarity) Disable fuzzy query.protected org.apache.lucene.search.QuerygetMultiTermPositionQuery(List<org.apache.lucene.search.Query> positionGroups) Combines the per-position field-disjunction groups above when a single getFieldQuery call is analyzed into more than one term.protected org.apache.lucene.search.QuerygetWildcardQuery(String field, String termStr) Disable wildcard query.protected org.apache.lucene.search.QuerynewTermQuery(org.apache.lucene.index.Term term, float boost) static org.apache.lucene.search.Queryparse(String searchString, ParseOptions options, org.apache.lucene.analysis.Analyzer analyzer) Invoked by JCMS Lucene search engines to parse query.static StringrewriteSearchString(String searchString, ParseOptions options) Compute the search string to use from the specified optionsMethods inherited from class org.apache.lucene.queryparser.classic.MultiFieldQueryParser
getFieldQuery, getMultiFieldQuery, getPrefixQuery, getRangeQuery, getRegexpQuery, parse, parse, parseMethods inherited from class org.apache.lucene.queryparser.classic.QueryParser
Clause, Conjunction, disable_tracing, enable_tracing, generateParseException, getNextToken, getSplitOnWhitespace, getToken, Modifiers, MultiTerm, Query, ReInit, ReInit, setAutoGeneratePhraseQueries, setSplitOnWhitespace, Term, TopLevelQuery, trace_enabledMethods inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
addClause, escape, getAllowLeadingWildcard, getAutoGeneratePhraseQueries, getBooleanQuery, getDateResolution, getDefaultOperator, getDeterminizeWorkLimit, getField, getFuzzyDistance, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getMultiTermRewriteMethod, getPhraseSlop, getTimeZone, init, newBooleanClause, newFieldQuery, newFuzzyQuery, newMatchAllDocsQuery, newPrefixQuery, newRangeQuery, newRegexpQuery, newWildcardQuery, parse, setAllowLeadingWildcard, setDateResolution, setDateResolution, setDefaultOperator, setDeterminizeWorkLimit, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setMultiTermRewriteMethod, setPhraseSlop, setTimeZoneMethods inherited from class org.apache.lucene.util.QueryBuilder
add, analyzeBoolean, analyzeGraphBoolean, analyzeGraphPhrase, analyzeMultiBoolean, analyzeMultiPhrase, analyzePhrase, analyzeTerm, createBooleanQuery, createBooleanQuery, createFieldQuery, createFieldQuery, createMinShouldMatchQuery, createPhraseQuery, createPhraseQuery, getAnalyzer, getAutoGenerateMultiTermSynonymsPhraseQuery, getEnableGraphQueries, getEnablePositionIncrements, newBooleanQuery, newGraphSynonymQuery, newMultiPhraseQueryBuilder, newSynonymQuery, setAnalyzer, setAutoGenerateMultiTermSynonymsPhraseQuery, setEnableGraphQueries, setEnablePositionIncrementsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.queryparser.flexible.standard.CommonQueryParserConfiguration
getAnalyzer, getEnablePositionIncrements, setEnablePositionIncrements
-
Field Details
-
LUCENE_WILDCARD_ENABLED
public static boolean LUCENE_WILDCARD_ENABLED -
LUCENE_FUZZY_ENABLED
public static boolean LUCENE_FUZZY_ENABLED -
USE_RIGHT_TRUNCATION
public static boolean USE_RIGHT_TRUNCATION -
RIGHT_TRUNCATION_EXCLUSION_REGEX
A regular expression used to match words in user's search string for which right truncation will NOT be applied.Default regex applies to :
- punctuation...
- words ending with punctuation (for example "said" and "world" in : "john said: hello world!")
- numbers, as we want to match them precisely (it also prevents TooManyBoolean with big index)
-
-
Constructor Details
-
DefaultQueryParser
@Deprecated(forRemoval=true) public DefaultQueryParser(String field, org.apache.lucene.analysis.Analyzer analyzer, ParseOptions options) Deprecated, for removal: This API element is subject to removal in a future version.since use of MultiFieldQueryParser with JCMS-11884Builds a new DefaultQueryParser.- Parameters:
field- the default field for query terms.analyzer- used to find terms in the query text.options- parsing options
-
DefaultQueryParser
public DefaultQueryParser(String[] fields, org.apache.lucene.analysis.Analyzer analyzer, Map<String, Float> boosts, ParseOptions options) Creates a DefaultQueryParser. Allows passing of a map with term to Boost, and the boost to apply to each term.It will, when parse(String query) is called, construct a query like this (assuming the query consists of two terms and you specify the two fields
titleandbody):(title:term1 body:term1) (title:term2 body:term2)When setDefaultOperator(AND_OPERATOR) is set, the result will be:
+(title:term1 body:term1) +(title:term2 body:term2)When you pass a boost (title=>5 body=>10) you can get
+(title:term1^5.0 body:term1^10.0) +(title:term2^5.0 body:term2^10.0)In other words, all the query's terms must appear, but it doesn't matter in what fields they appear.
- Parameters:
fields- the default field for query terms.analyzer- used to find terms in the query text.options- parsing options- Since:
- 11.0.0
-
-
Method Details
-
getWildcardQuery
protected org.apache.lucene.search.Query getWildcardQuery(String field, String termStr) throws org.apache.lucene.queryparser.classic.ParseException Disable wildcard query.- Overrides:
getWildcardQueryin classorg.apache.lucene.queryparser.classic.MultiFieldQueryParser- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
getFuzzyQuery
protected org.apache.lucene.search.Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws org.apache.lucene.queryparser.classic.ParseException Disable fuzzy query.- Overrides:
getFuzzyQueryin classorg.apache.lucene.queryparser.classic.MultiFieldQueryParser- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
newTermQuery
protected org.apache.lucene.search.Query newTermQuery(org.apache.lucene.index.Term term, float boost) - Overrides:
newTermQueryin classorg.apache.lucene.util.QueryBuilder
-
parse
public static org.apache.lucene.search.Query parse(String searchString, ParseOptions options, org.apache.lucene.analysis.Analyzer analyzer) throws org.apache.lucene.queryparser.classic.ParseException Invoked by JCMS Lucene search engines to parse query.- Parameters:
searchString- the string to search/parseoptions- parsing optionsanalyzer- analyzer used to find terms in the query text- Returns:
- a new Query instance
- Throws:
org.apache.lucene.queryparser.classic.ParseException- if lucene query was invalid- Since:
- jcms-10.0.0
-
rewriteSearchString
Compute the search string to use from the specified options- Parameters:
searchString- the string to searchoptions- a SearchOptions instance holder of search parameters- Returns:
- a String modified to be suitable for lucene search.
-
getFieldBoost
Return the boost that should be applied to a field at query time for text search.Boost value are being read from property declaration :
query.lucene.boost.{search-engine-name}.{field-name}: 2.0For example :query.lucene.boost.PUBLICATION.title: 2.0 query.lucene.boost.CATEGORY.name: 1.2 query.lucene.boost.PUBLICATION._allfields_: 1.0
- Parameters:
engine- the search engine in which search is performedfieldName- the field name being search and for which a Query object is being built- Returns:
- a float noting the boost value of the field to apply to the Query object
-
addMultiTermClauses
protected void addMultiTermClauses(List<org.apache.lucene.search.BooleanClause> clauses, org.apache.lucene.search.Query q) - Overrides:
addMultiTermClausesin classorg.apache.lucene.queryparser.classic.QueryParserBase
-
getFieldQuery
protected org.apache.lucene.search.Query getFieldQuery(String field, String queryText, boolean quoted) throws org.apache.lucene.queryparser.classic.ParseException - Overrides:
getFieldQueryin classorg.apache.lucene.queryparser.classic.MultiFieldQueryParser- Throws:
org.apache.lucene.queryparser.classic.ParseException
-
getMultiTermPositionQuery
protected org.apache.lucene.search.Query getMultiTermPositionQuery(List<org.apache.lucene.search.Query> positionGroups) throws org.apache.lucene.queryparser.classic.ParseException Combines the per-position field-disjunction groups above when a single getFieldQuery call is analyzed into more than one term. Unlike getMultiFieldQuery (field alternatives for a single term, always SHOULD), this honors the default operator, since every term position must be satisfied under AND_OPERATOR.- Throws:
org.apache.lucene.queryparser.classic.ParseException
-