Package org.apache.solr.search
Class ExtendedDismaxQParser
- java.lang.Object
-
- org.apache.solr.search.QParser
-
- org.apache.solr.search.ExtendedDismaxQParser
-
public class ExtendedDismaxQParser extends QParser
Query parser that generates DisjunctionMaxQueries based on user configuration. See Wiki page https://solr.apache.org/guide/edismax-query-parser.html
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ExtendedDismaxQParser.Clause
static class
ExtendedDismaxQParser.ExtendedDismaxConfiguration
Simple container for configuration information used when parsing queriesstatic class
ExtendedDismaxQParser.ExtendedSolrQueryParser
A 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
Constructors Constructor Description ExtendedDismaxQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDebugInfo(NamedList<Object> debugInfo)
protected void
addPhraseFieldQueries(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 void
addShingledPhraseQueries(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.protected ExtendedDismaxQParser.ExtendedDismaxConfiguration
createConfiguration(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req)
Creates an instance of ExtendedDismaxConfiguration.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.protected List<org.apache.lucene.search.Query>
getBoostFunctions()
Parses all function queriesprotected List<org.apache.lucene.search.Query>
getBoostQueries()
Parses all boost queriesString[]
getDefaultHighlightFields()
String
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.Query
getHighlightQuery()
protected List<org.apache.lucene.queries.function.ValueSource>
getMultiplicativeBoosts()
Parses all multiplicative boostsorg.apache.lucene.search.Query
parse()
Create and return theQuery
object represented byqstr
.protected org.apache.lucene.search.Query
parseEscapedQuery(ExtendedDismaxQParser.ExtendedSolrQueryParser up, String escapedUserQuery, ExtendedDismaxQParser.ExtendedDismaxConfiguration config)
Parses an escaped version of the user's query.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.protected String
rebuildUserQuery(List<ExtendedDismaxQParser.Clause> clauses, boolean lowercaseOperators)
Generates a query string from the raw clauses, uppercasing 'and' and 'or' as needed.protected boolean
shouldRemoveStopFilter(ExtendedDismaxQParser.ExtendedDismaxConfiguration config, org.apache.lucene.search.Query query)
Determines if query should be re-parsed removing the stop filter.static List<String>
split(String s, boolean ignoreQuote)
List<ExtendedDismaxQParser.Clause>
splitIntoClauses(String s, boolean ignoreQuote)
protected void
validateQueryFields(ExtendedDismaxQParser.ExtendedSolrQueryParser up)
Validate query field names.-
Methods inherited from class org.apache.solr.search.QParser
getFlags, getLocalParams, getParam, getParams, getParser, getParser, getParser, getQuery, getReq, getSortSpec, getString, isFilter, setFlags, setIsFilter, setLocalParams, setParams, setReq, setString, subQuery
-
-
-
-
Constructor Detail
-
ExtendedDismaxQParser
public ExtendedDismaxQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req)
-
-
Method Detail
-
parse
public org.apache.lucene.search.Query parse() throws SyntaxError
Description copied from class:QParser
Create and return theQuery
object represented byqstr
. Null MAY be returned to signify there was no input (e.g. no query string) to parse.- Specified by:
parse
in classQParser
- Throws:
SyntaxError
- See Also:
QParser.getQuery()
-
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, SolrParams localParams, 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(org.apache.solr.search.ExtendedDismaxQParser.ExtendedSolrQueryParser, java.lang.String, java.util.List<org.apache.solr.search.ExtendedDismaxQParser.Clause>, org.apache.solr.search.ExtendedDismaxQParser.ExtendedDismaxConfiguration)
,SolrPluginUtils.flattenBooleanQuery(org.apache.lucene.search.BooleanQuery.Builder, org.apache.lucene.search.BooleanQuery)
-
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:
parseEscapedQuery(org.apache.solr.search.ExtendedDismaxQParser.ExtendedSolrQueryParser, java.lang.String, org.apache.solr.search.ExtendedDismaxQParser.ExtendedDismaxConfiguration)
-
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 SyntaxError
Parses all multiplicative boosts- Throws:
SyntaxError
-
getBoostFunctions
protected List<org.apache.lucene.search.Query> getBoostFunctions() throws SyntaxError
Parses all function queries- Throws:
SyntaxError
-
getBoostQueries
protected List<org.apache.lucene.search.Query> getBoostQueries() throws SyntaxError
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
public String[] getDefaultHighlightFields()
- Overrides:
getDefaultHighlightFields
in classQParser
-
getHighlightQuery
public org.apache.lucene.search.Query getHighlightQuery() throws SyntaxError
- Overrides:
getHighlightQuery
in classQParser
- Throws:
SyntaxError
-
addDebugInfo
public void addDebugInfo(NamedList<Object> debugInfo)
- Overrides:
addDebugInfo
in classQParser
-
splitIntoClauses
public List<ExtendedDismaxQParser.Clause> splitIntoClauses(String s, boolean ignoreQuote)
-
getFieldName
public String getFieldName(String s, int pos, int end)
returns a field name or legal field alias from the current position of the string
-
-