Overview | Package | Class | Use | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.queryparser.complexPhrase
Class ComplexPhraseQueryParser

    java.lang.Object
      org.apache.lucene.queryparser.classic.QueryParserBase
          org.apache.lucene.queryparser.classic.QueryParser
              org.apache.lucene.queryparser.complexPhrase.ComplexPhraseQueryParser

All Implemented Interfaces:
  QueryParserConstants, CommonQueryParserConfiguration

    public class ComplexPhraseQueryParser

extends QueryParser

QueryParser which permits complex phrase query syntax eg "(john jon jonathan~) peters*".

Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects

This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status

Nested Class Summary

Nested classes/interfaces inherited from class org.apache.lucene.queryparser.classic.QueryParser
`QueryParser.Operator`

Nested classes/interfaces inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
`QueryParserBase.MethodRemovedUseAnother`

Field Summary

Fields inherited from class org.apache.lucene.queryparser.classic.QueryParser
`jj_nt, token, token_source`

Fields inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
`AND_OPERATOR, OR_OPERATOR`

Fields 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
`ComplexPhraseQueryParser(Version matchVersion, String f, Analyzer a)`

Method Summary
`protected Query` | `getFieldQuery(String field, String queryText, int slop)` Base implementation delegates to `QueryParserBase.getFieldQuery(String,String,boolean)`.
`protected Query` | `getFuzzyQuery(String field, String termStr, float minSimilarity)` Factory method for generating a query (similar to `QueryParserBase.getWildcardQuery(java.lang.String, java.lang.String)`).
`protected Query` | `getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive)`
`protected Query` | `getWildcardQuery(String field, String termStr)` Factory method for generating a query.
`protected Query` | `newRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive)` Builds a new `TermRangeQuery` instance
`protected Query` | `newTermQuery(Term term)` Builds a new TermQuery instance
`Query` | `parse(String query)` Parses a query string, returning a `Query`.

Methods inherited from class org.apache.lucene.queryparser.classic.QueryParser
`Clause, Conjunction, disable_tracing, enable_tracing, generateParseException, getNextToken, getToken, Modifiers, Query, ReInit, ReInit, Term, TopLevelQuery`

Methods inherited from class org.apache.lucene.queryparser.classic.QueryParserBase
`addClause, analyzeMultitermTerm, escape, getAllowLeadingWildcard, getAnalyzer, getAnalyzeRangeTerms, getAutoGeneratePhraseQueries, getBooleanQuery, getBooleanQuery, getDateResolution, getDefaultOperator, getEnablePositionIncrements, getField, getFieldQuery, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getLowercaseExpandedTerms, getMultiTermRewriteMethod, getPhraseSlop, getPrefixQuery, getRegexpQuery, getTimeZone, init, newBooleanClause, newBooleanQuery, newFieldQuery, newFuzzyQuery, newMatchAllDocsQuery, newMultiPhraseQuery, newPhraseQuery, newPrefixQuery, newRegexpQuery, newWildcardQuery, setAllowLeadingWildcard, setAnalyzeRangeTerms, setAutoGeneratePhraseQueries, setDateResolution, setDateResolution, setDefaultOperator, setEnablePositionIncrements, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiTermRewriteMethod, setPhraseSlop, setTimeZone`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ComplexPhraseQueryParser

    public ComplexPhraseQueryParser(Version matchVersion,
                                    String f,
                                    Analyzer a)

Method Detail

### getFieldQuery

    protected Query getFieldQuery(String field,
                                  String queryText,
                                  int slop)

  Description copied from class: `QueryParserBase`
  Base implementation delegates to `QueryParserBase.getFieldQuery(String,String,boolean)`. This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.

  Overrides:
    `getFieldQuery` in class `QueryParserBase`

### parse

    public Query parse(String query)
                throws ParseException

  Description copied from class: `QueryParserBase`
  Parses a query string, returning a `Query`.

  Overrides:
    `parse` in class `QueryParserBase`
  Parameters:
    `query` - the query string to be parsed.
  Throws:
    `ParseException` - if the parsing fails

### newTermQuery

    protected Query newTermQuery(Term term)

  Description copied from class: `QueryParserBase`
  Builds a new TermQuery instance

  Overrides:
    `newTermQuery` in class `QueryParserBase`
  Parameters:
    `term` - term
  Returns:
    new TermQuery instance

### getWildcardQuery

    protected Query getWildcardQuery(String field,
                                     String termStr)
                              throws ParseException

  Description copied from class: `QueryParserBase`
  Factory method for generating a query. Called when parser parses an input term token that contains one or more wildcard characters (? and *), but is not a prefix term token (one that has just a single * character at the end)

  Depending on settings, prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.

  Can be overridden by extending classes, to provide custom handling for wildcard queries, which may be necessary due to missing analyzer calls.

  Overrides:
    `getWildcardQuery` in class `QueryParserBase`
  Parameters:
    `field` - Name of the field query will use.
    `termStr` - Term token that contains one or more wild card characters (? or *), but is not simple prefix term
  Returns:
    Resulting `Query` built for the term
  Throws:
    `ParseException` - throw in overridden method to disallow

### getRangeQuery

    protected Query getRangeQuery(String field,
                                  String part1,
                                  String part2,
                                  boolean startInclusive,
                                  boolean endInclusive)
                           throws ParseException

  Overrides:
    `getRangeQuery` in class `QueryParserBase`
  Throws:
    `ParseException`

### newRangeQuery

    protected Query newRangeQuery(String field,
                                  String part1,
                                  String part2,
                                  boolean startInclusive,
                                  boolean endInclusive)

  Description copied from class: `QueryParserBase`
  Builds a new `TermRangeQuery` instance

  Overrides:
    `newRangeQuery` in class `QueryParserBase`
  Parameters:
    `field` - Field
    `part1` - min
    `part2` - max
    `startInclusive` - true if the start of the range is inclusive
    `endInclusive` - true if the end of the range is inclusive
  Returns:
    new `TermRangeQuery` instance

### getFuzzyQuery

    protected Query getFuzzyQuery(String field,
                                  String termStr,
                                  float minSimilarity)
                           throws ParseException

  Description copied from class: `QueryParserBase`
  Factory method for generating a query (similar to `QueryParserBase.getWildcardQuery(java.lang.String, java.lang.String)`). Called when parser parses an input term token that has the fuzzy suffix (~) appended.

  Overrides:
    `getFuzzyQuery` in class `QueryParserBase`
  Parameters:
    `field` - Name of the field query will use.
    `termStr` - Term token to use for building term for the query
  Returns:
    Resulting `Query` built for the term
  Throws:
    `ParseException` - throw in overridden method to disallow

Overview | Package | Class | Use | Tree | Deprecated | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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