Package org.apache.solr.search
Class ExtendedDismaxQParser
java.lang.Object
org.apache.solr.search.QParser
org.apache.solr.search.ExtendedDismaxQParser
Query parser that generates DisjunctionMaxQueries based on user configuration. See the Reference
Guide page
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classstatic classSimple container for configuration information used when parsing queriesstatic classA subclass of SolrQueryParser that supports aliasing fields for constructing DisjunctionMaxQueries. -
Field Summary
Fields inherited from class org.apache.solr.search.QParser
FLAG_FILTER, flags, localParams, localParamsEnd, params, qstr, query, recurseCount, req, stringIncludingLocalParams, valFollowedParams -
Constructor Summary
ConstructorsConstructorDescriptionExtendedDismaxQParser(String qstr, org.apache.solr.common.params.SolrParams localParams, org.apache.solr.common.params.SolrParams params, SolrQueryRequest req) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDebugInfo(org.apache.solr.common.util.NamedList<Object> debugInfo) protected voidaddPhraseFieldQueries(org.apache.lucene.search.BooleanQuery.Builder query, List<ExtendedDismaxQParser.Clause> clauses, ExtendedDismaxQParser.ExtendedDismaxConfiguration config) Adds shingled phrase queries to all the fields specified in the pf, pf2 anf pf3 parametersprotected voidaddShingledPhraseQueries(org.apache.lucene.search.BooleanQuery.Builder mainQuery, List<ExtendedDismaxQParser.Clause> clauses, Collection<FieldParams> fields, int shingleSize, float tiebreaker, int slop) Modifies the main query by adding a new optional Query consisting of shingled phrase queries across the specified clauses using the specified field => boost mappings.createConfiguration(String qstr, org.apache.solr.common.params.SolrParams localParams, org.apache.solr.common.params.SolrParams params, SolrQueryRequest req) Creates an instance of ExtendedDismaxConfiguration.createEdismaxQueryParser(QParser qParser, String field) Creates an instance of ExtendedSolrQueryParser, the query parser that's going to be used to parse the query.protected List<org.apache.lucene.search.Query> Parses all function queriesprotected List<org.apache.lucene.search.Query> Parses all boost queriesString[]getFieldName(String s, int pos, int end) returns a field name or legal field alias from the current position of the stringorg.apache.lucene.search.Queryprotected List<org.apache.lucene.queries.function.ValueSource> Parses all multiplicative boostsorg.apache.lucene.search.Queryparse()Create and return theQueryobject represented byqstr.protected org.apache.lucene.search.QueryparseEscapedQuery(ExtendedDismaxQParser.ExtendedSolrQueryParser up, String escapedUserQuery, ExtendedDismaxQParser.ExtendedDismaxConfiguration config) Parses an escaped version of the user's query.protected org.apache.lucene.search.QueryparseOriginalQuery(ExtendedDismaxQParser.ExtendedSolrQueryParser up, String mainUserQuery, List<ExtendedDismaxQParser.Clause> clauses, ExtendedDismaxQParser.ExtendedDismaxConfiguration config) Parses the user's original query.protected StringrebuildUserQuery(List<ExtendedDismaxQParser.Clause> clauses, boolean lowercaseOperators) Generates a query string from the raw clauses, uppercasing 'and' and 'or' as needed.protected booleanshouldRemoveStopFilter(ExtendedDismaxQParser.ExtendedDismaxConfiguration config, org.apache.lucene.search.Query query) Determines if query should be re-parsed removing the stop filter.splitIntoClauses(String s, boolean ignoreQuote) protected voidValidate query field names.Methods inherited from class org.apache.solr.search.QParser
getFlags, getLocalParams, getParam, getParams, getParser, getParser, getParser, getPrefixQueryMinPrefixLength, getQuery, getReq, getSortSpec, getString, isFilter, parseAsValueSource, setFlags, setIsFilter, setLocalParams, setParams, setReq, setString, subQuery
-
Constructor Details
-
ExtendedDismaxQParser
public ExtendedDismaxQParser(String qstr, org.apache.solr.common.params.SolrParams localParams, org.apache.solr.common.params.SolrParams params, SolrQueryRequest req)
-
-
Method Details
-
parse
Description copied from class:QParserCreate and return theQueryobject represented byqstr. Null MAY be returned to signify there was no input (e.g. no query string) to parse.- Specified by:
parsein classQParser- Throws:
SyntaxError- See Also:
-
validateQueryFields
protected void validateQueryFields(ExtendedDismaxQParser.ExtendedSolrQueryParser up) throws SyntaxError Validate query field names. Must be explicitly defined in the schema or match a dynamic field pattern. Checks source field(s) represented by a field alias- Parameters:
up- parser used- Throws:
SyntaxError- for invalid field name
-
addPhraseFieldQueries
protected void addPhraseFieldQueries(org.apache.lucene.search.BooleanQuery.Builder query, List<ExtendedDismaxQParser.Clause> clauses, ExtendedDismaxQParser.ExtendedDismaxConfiguration config) throws SyntaxError Adds shingled phrase queries to all the fields specified in the pf, pf2 anf pf3 parameters- Throws:
SyntaxError
-
createConfiguration
protected ExtendedDismaxQParser.ExtendedDismaxConfiguration createConfiguration(String qstr, org.apache.solr.common.params.SolrParams localParams, org.apache.solr.common.params.SolrParams params, SolrQueryRequest req) Creates an instance of ExtendedDismaxConfiguration. It will contain all the necessary parameters to parse the query -
createEdismaxQueryParser
protected ExtendedDismaxQParser.ExtendedSolrQueryParser createEdismaxQueryParser(QParser qParser, String field) Creates an instance of ExtendedSolrQueryParser, the query parser that's going to be used to parse the query. -
parseEscapedQuery
protected org.apache.lucene.search.Query parseEscapedQuery(ExtendedDismaxQParser.ExtendedSolrQueryParser up, String escapedUserQuery, ExtendedDismaxQParser.ExtendedDismaxConfiguration config) throws SyntaxError Parses an escaped version of the user's query. This method is called in the event that the original query encounters exceptions during parsing.- Parameters:
up- parser usedescapedUserQuery- query that is parsed, should already be escaped so that no trivial parse errors are encounteredconfig- Configuration options for this parse request- Returns:
- the resulting query (flattened if needed) with "min should match" rules applied as specified in the config.
- Throws:
SyntaxError- See Also:
-
parseOriginalQuery
protected org.apache.lucene.search.Query parseOriginalQuery(ExtendedDismaxQParser.ExtendedSolrQueryParser up, String mainUserQuery, List<ExtendedDismaxQParser.Clause> clauses, ExtendedDismaxQParser.ExtendedDismaxConfiguration config) Parses the user's original query. This method attempts to cleanly parse the specified query string using the specified parser, any Exceptions are ignored resulting in null being returned.- Parameters:
up- parser usedmainUserQuery- query string that is parsedclauses- used to dictate "min should match" logicconfig- Configuration options for this parse request- Returns:
- the resulting query with "min should match" rules applied as specified in the config.
- See Also:
-
shouldRemoveStopFilter
protected boolean shouldRemoveStopFilter(ExtendedDismaxQParser.ExtendedDismaxConfiguration config, org.apache.lucene.search.Query query) Determines if query should be re-parsed removing the stop filter.- Returns:
- true if there are stopwords configured and the parsed query was empty false in any other case.
-
rebuildUserQuery
protected String rebuildUserQuery(List<ExtendedDismaxQParser.Clause> clauses, boolean lowercaseOperators) Generates a query string from the raw clauses, uppercasing 'and' and 'or' as needed.- Parameters:
clauses- the clauses of the query string to be rebuiltlowercaseOperators- if true, lowercase 'and' and 'or' clauses will be recognized as operators and uppercased in the final query string.- Returns:
- the generated query string.
-
getMultiplicativeBoosts
protected List<org.apache.lucene.queries.function.ValueSource> getMultiplicativeBoosts() throws SyntaxErrorParses all multiplicative boosts- Throws:
SyntaxError
-
getBoostFunctions
Parses all function queries- Throws:
SyntaxError
-
getBoostQueries
Parses all boost queries- Throws:
SyntaxError
-
addShingledPhraseQueries
protected void addShingledPhraseQueries(org.apache.lucene.search.BooleanQuery.Builder mainQuery, List<ExtendedDismaxQParser.Clause> clauses, Collection<FieldParams> fields, int shingleSize, float tiebreaker, int slop) throws SyntaxError Modifies the main query by adding a new optional Query consisting of shingled phrase queries across the specified clauses using the specified field => boost mappings.- Parameters:
mainQuery- Where the phrase boosting queries will be addedclauses- Clauses that will be used to construct the phrasesfields- Field => boost mappings for the phrase queriesshingleSize- how big the phrases should be, 0 means a single phrasetiebreaker- tie breaker value for the DisjunctionMaxQueries- Throws:
SyntaxError
-
getDefaultHighlightFields
- Overrides:
getDefaultHighlightFieldsin classQParser
-
getHighlightQuery
- Overrides:
getHighlightQueryin classQParser- Throws:
SyntaxError
-
addDebugInfo
- Overrides:
addDebugInfoin classQParser
-
splitIntoClauses
-
getFieldName
returns a field name or legal field alias from the current position of the string -
split
-