org.apache.solr.search
Class ExtendedDismaxQParser

java.lang.Object
  extended by org.apache.solr.search.QParser
      extended by org.apache.solr.search.ExtendedDismaxQParser

public class ExtendedDismaxQParser
extends QParser

Query parser that generates DisjunctionMaxQueries based on user configuration. See Wiki page http://wiki.apache.org/solr/ExtendedDisMax


Nested Class Summary
protected static class ExtendedDismaxQParser.Clause
           
 class ExtendedDismaxQParser.ExtendedDismaxConfiguration
          Simple container for configuration information used when parsing queries
static 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
localParams, localParamsEnd, params, qstr, query, recurseCount, req, stringIncludingLocalParams, valFollowedParams
 
Constructor Summary
ExtendedDismaxQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req)
           
 
Method Summary
 void addDebugInfo(NamedList<Object> debugInfo)
           
protected  void addPhraseFieldQueries(BooleanQuery query, List<ExtendedDismaxQParser.Clause> clauses, ExtendedDismaxQParser.ExtendedDismaxConfiguration config)
          Adds shingled phrase queries to all the fields specified in the pf, pf2 anf pf3 parameters
protected  void addShingledPhraseQueries(BooleanQuery mainQuery, List<ExtendedDismaxQParser.Clause> clauses, Map<String,Float> 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<Query> getBoostFunctions()
          Parses all function queries
protected  List<Query> getBoostQueries()
          Parses all boost queries
 String[] getDefaultHighlightFields()
           
 String getFieldName(String s, int pos, int end)
          returns a field name or legal field alias from the current position of the string
 Query getHighlightQuery()
           
protected  List<ValueSource> getMultiplicativeBoosts()
          Parses all multiplicative boosts
 Query parse()
          Create and return the Query object represented by qstr.
protected  Query parseEscapedQuery(ExtendedDismaxQParser.ExtendedSolrQueryParser up, String escapedUserQuery, ExtendedDismaxQParser.ExtendedDismaxConfiguration config)
          Parses an escaped version of the user's query.
protected  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, 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)
           
 
Methods inherited from class org.apache.solr.search.QParser
getLocalParams, getParam, getParams, getParser, getQuery, getReq, getSort, getString, setLocalParams, setParams, setReq, setString, subQuery
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtendedDismaxQParser

public ExtendedDismaxQParser(String qstr,
                             SolrParams localParams,
                             SolrParams params,
                             SolrQueryRequest req)
Method Detail

parse

public Query parse()
            throws SyntaxError
Description copied from class: QParser
Create and return the Query object represented by qstr. Null MAY be returned to signify there was no input (e.g. no query string) to parse.

Specified by:
parse in class QParser
Throws:
SyntaxError
See Also:
QParser.getQuery()

addPhraseFieldQueries

protected void addPhraseFieldQueries(BooleanQuery 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 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 used
escapedUserQuery - query that is parsed, should already be escaped so that no trivial parse errors are encountered
config - 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.ExtendedDismaxConfiguration), SolrPluginUtils.flattenBooleanQuery(org.apache.lucene.search.BooleanQuery, org.apache.lucene.search.BooleanQuery)

parseOriginalQuery

protected 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 used
mainUserQuery - query string that is parsed
clauses - used to dictate "min should match" logic
config - 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,
                                         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 rebuilt
lowercaseOperators - 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<ValueSource> getMultiplicativeBoosts()
                                             throws SyntaxError
Parses all multiplicative boosts

Throws:
SyntaxError

getBoostFunctions

protected List<Query> getBoostFunctions()
                                 throws SyntaxError
Parses all function queries

Throws:
SyntaxError

getBoostQueries

protected List<Query> getBoostQueries()
                               throws SyntaxError
Parses all boost queries

Throws:
SyntaxError

addShingledPhraseQueries

protected void addShingledPhraseQueries(BooleanQuery mainQuery,
                                        List<ExtendedDismaxQParser.Clause> clauses,
                                        Map<String,Float> 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 added
clauses - Clauses that will be used to construct the phrases
fields - Field => boost mappings for the phrase queries
shingleSize - how big the phrases should be, 0 means a single phrase
tiebreaker - tie breaker value for the DisjunctionMaxQueries
slop - slop value for the constructed phrases
Throws:
SyntaxError

getDefaultHighlightFields

public String[] getDefaultHighlightFields()
Overrides:
getDefaultHighlightFields in class QParser

getHighlightQuery

public Query getHighlightQuery()
                        throws SyntaxError
Overrides:
getHighlightQuery in class QParser
Throws:
SyntaxError

addDebugInfo

public void addDebugInfo(NamedList<Object> debugInfo)
Overrides:
addDebugInfo in class QParser

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


split

public static List<String> split(String s,
                                 boolean ignoreQuote)


Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.