Lucene++ - a full-featured, c++ search engine
API Documentation

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
Lucene::MultiFieldQueryParser Class Reference

A QueryParser which constructs queries to search multiple fields. More...

`#include <MultiFieldQueryParser.h>`

Inheritance diagram for Lucene::MultiFieldQueryParser:

## Public Member Functions

| MultiFieldQueryParser (LuceneVersion::Version matchVersion, Collection< String > fields, AnalyzerPtr analyzer, MapStringDouble boosts)
| Creates a MultiFieldQueryParser. Allows passing of a map with term to Boost, and the boost to apply to each term. More...
| MultiFieldQueryParser (LuceneVersion::Version matchVersion, Collection< String > fields, AnalyzerPtr analyzer)
| Creates a MultiFieldQueryParser. 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 title and body): More...
virtual | ~MultiFieldQueryParser ()
virtual String | getClassName ()
boost::shared_ptr < MultiFieldQueryParser > | shared_from_this ()
Public Member Functions inherited from Lucene::QueryParser
| QueryParser (LuceneVersion::Version matchVersion, const String &field, AnalyzerPtr analyzer)
| Constructs a query parser. More...
| QueryParser (QueryParserCharStreamPtr stream)
| Constructor with user supplied QueryParserCharStream. More...
| QueryParser (QueryParserTokenManagerPtr tokenMgr)
| Constructor with generated Token Manager. More...
virtual | ~QueryParser ()
boost::shared_ptr< QueryParser > | shared_from_this ()
QueryPtr | parse (const String &query)
| Parses a query string, returning a Query. More...
AnalyzerPtr | getAnalyzer ()
String | getField ()
double | getFuzzyMinSim ()
| Get the minimal similarity for fuzzy queries. More...
void | setFuzzyMinSim (double fuzzyMinSim)
| Set the minimum similarity for fuzzy queries. Default is 0.5. More...
int32_t | getFuzzyPrefixLength ()
| Get the prefix length for fuzzy queries. More...
void | setFuzzyPrefixLength (int32_t fuzzyPrefixLength)
| Set the prefix length for fuzzy queries. Default is 0. More...
void | setPhraseSlop (int32_t phraseSlop)
| Sets the default slop for phrases. If zero, then exact phrase matches are required. Default value is zero. More...
int32_t | getPhraseSlop ()
| Gets the default slop for phrases. More...
void | setAllowLeadingWildcard (bool allowLeadingWildcard)
| Set to true to allow leading wildcard characters. More...
bool | getAllowLeadingWildcard ()
void | setEnablePositionIncrements (bool enable)
| Set to true to enable position increments in result query. More...
bool | getEnablePositionIncrements ()
void | setDefaultOperator (Operator op)
| Sets the boolean operator of the QueryParser. In default mode (OR_OPERATOR) terms without any modifiers are considered optional: for example capital of Hungary is equal to capital OR of OR Hungary. In AND_OPERATOR mode terms are considered to be in conjunction: the above mentioned query is parsed as capital AND of AND Hungary. More...
Operator | getDefaultOperator ()
| Gets implicit operator setting, which will be either AND_OPERATOR or OR_OPERATOR. More...
void | setLowercaseExpandedTerms (bool lowercaseExpandedTerms)
| Whether terms of wildcard, prefix, fuzzy and range queries are to be automatically lower-cased or not. Default is true. More...
bool | getLowercaseExpandedTerms ()
void | setMultiTermRewriteMethod (RewriteMethodPtr method)

By default QueryParser uses MultiTermQuery#CONSTANT_SCORE_AUTO_REWRITE_DEFAULT when creating a PrefixQuery, WildcardQuery or RangeQuery. This implementation is generally preferable because it a) Runs faster b) Does not have the scarcity of terms unduly influence score c) avoids any "TooManyClauses" exception. However, if your application really needs to use the old- fashioned BooleanQuery expansion rewriting and the above points are not relevant then use this to change the rewrite method. More...

RewriteMethodPtr | getMultiTermRewriteMethod ()
void | setLocale (std::locale locale)
| Set locale used by date range parsing. More...
std::locale | getLocale ()
| Returns current locale, allowing access by subclasses. More...
void | setDateResolution (DateTools::Resolution dateResolution)
| Sets the default date resolution used by RangeQueries for fields for which no specific date resolutions has been set. Field specific resolutions can be set with setDateResolution(const String&, DateTools::Resolution). More...
void | setDateResolution (const String &fieldName, DateTools::Resolution dateResolution)
| Sets the date resolution used by RangeQueries for a specific field. More...
DateTools::Resolution | getDateResolution (const String &fieldName)
| Returns the date resolution that is used by RangeQueries for the given field. Returns null, if no default or field specific date resolution has been set for the given field. More...
void | setRangeCollator (CollatorPtr rc)
| Sets the collator used to determine index term inclusion in ranges for RangeQuerys. More...
CollatorPtr | getRangeCollator ()
int32_t | Conjunction ()
| Query ::= ( Clause )* Clause ::= ["+", "-"] [ ":"] ( | "(" Query ")" ) More...
int32_t | Modifiers ()
virtual QueryPtr | TopLevelQuery (const String &field)
| This makes sure that there is no garbage after the query string. More...
virtual QueryPtr | ParseQuery (const String &field)
virtual QueryPtr | ParseClause (const String &field)
virtual QueryPtr | ParseTerm (const String &field)
virtual void | ReInit (QueryParserCharStreamPtr stream)
| Reinitialise. More...
virtual void | ReInit (QueryParserTokenManagerPtr tokenMgr)
| Reinitialise. More...
virtual QueryParserTokenPtr | getNextToken ()
| Get the next Token. More...
virtual QueryParserTokenPtr | getToken (int32_t index)
| Get the specific Token. More...
virtual void | generateParseException ()
| Generate QueryParserError exception. More...
virtual void | enable_tracing ()
| Enable tracing. More...
virtual void | disable_tracing ()
| Disable tracing. More...
Public Member Functions inherited from Lucene::QueryParserConstants
virtual | ~QueryParserConstants ()
Public Member Functions inherited from Lucene::LuceneObject
virtual | ~LuceneObject ()
virtual void | initialize ()
| Called directly after instantiation to create objects that depend on this object being fully constructed. More...
virtual LuceneObjectPtr | clone (LuceneObjectPtr other=LuceneObjectPtr())
| Return clone of this object. More...
virtual int32_t | hashCode ()
| Return hash code for this object. More...
virtual bool | equals (LuceneObjectPtr other)
| Return whether two objects are equal. More...
virtual int32_t | compareTo (LuceneObjectPtr other)
| Compare two objects. More...
virtual String | toString ()
| Returns a string representation of the object. More...
Public Member Functions inherited from Lucene::LuceneSync
virtual | ~LuceneSync ()
virtual SynchronizePtr | getSync ()
| Return this object synchronize lock. More...
virtual LuceneSignalPtr | getSignal ()
| Return this object signal. More...
virtual void | lock (int32_t timeout=0)
| Lock this object using an optional timeout. More...
virtual void | unlock ()
| Unlock this object. More...
virtual bool | holdsLock ()
| Returns true if this object is currently locked by current thread. More...
virtual void | wait (int32_t timeout=0)
| Wait for signal using an optional timeout. More...
virtual void | notifyAll ()
| Notify all threads waiting for signal. More...

## Static Public Member Functions

static String | _getClassName ()
static QueryPtr | parse (LuceneVersion::Version matchVersion, Collection< String > queries, Collection< String > fields, AnalyzerPtr analyzer)
| Parses a query which searches on the fields specified. More...
static QueryPtr | parse (LuceneVersion::Version matchVersion, const String &query, Collection< String > fields, Collection< BooleanClause::Occur > flags, AnalyzerPtr analyzer)
| Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited. More...
static QueryPtr | parse (LuceneVersion::Version matchVersion, Collection< String > queries, Collection< String > fields, Collection< BooleanClause::Occur > flags, AnalyzerPtr analyzer)
| Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited. More...
Static Public Member Functions inherited from Lucene::QueryParser
static String | _getClassName ()
static int | main (Collection< String > args)
| Command line tool to test QueryParser, using SimpleAnalyzer. More...
Static Public Member Functions inherited from Lucene::QueryParserConstants
static String | _getClassName ()

## Protected Member Functions

virtual QueryPtr | getFieldQuery (const String &field, const String &queryText, int32_t slop)
| Base implementation delegates to getFieldQuery(const String&, const String&). This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery. More...
virtual QueryPtr | getFieldQuery (const String &field, const String &queryText)
| Use the analyzer to get all the tokens, and then build a TermQuery, PhraseQuery, or nothing based on the term count. More...
void | applySlop (QueryPtr query, int32_t slop)
virtual QueryPtr | getFuzzyQuery (const String &field, const String &termStr, double minSimilarity)
| Factory method for generating a query (similar to getWildcardQuery). Called when parser parses an input term token that has the fuzzy suffix (~) appended. More...
virtual QueryPtr | getPrefixQuery (const String &field, const String &termStr)
| Factory method for generating a query (similar to getWildcardQuery). Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character. Since this is a special case of generic wildcard term, and such a query can be optimized easily, this usually results in a different query object. More...
virtual QueryPtr | getWildcardQuery (const String &field, const String &termStr)
| 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) More...
virtual QueryPtr | getRangeQuery (const String &field, const String &part1, const String &part2, bool inclusive)
| Builds a new TermRangeQuery instance for given min/max parts. More...
Protected Member Functions inherited from Lucene::QueryParser
void | ConstructParser (QueryParserCharStreamPtr stream, QueryParserTokenManagerPtr tokenMgr)
| Construct query parser with supplied QueryParserCharStream or TokenManager. More...
virtual void | addClause (Collection< BooleanClausePtr > clauses, int32_t conj, int32_t mods, QueryPtr q)
BooleanQueryPtr | newBooleanQuery (bool disableCoord)
| Builds a new BooleanQuery instance. More...
BooleanClausePtr | newBooleanClause (QueryPtr q, BooleanClause::Occur occur)
| Builds a new BooleanClause instance. More...
QueryPtr | newTermQuery (TermPtr term)
| Builds a new TermQuery instance. More...
PhraseQueryPtr | newPhraseQuery ()
| Builds a new PhraseQuery instance. More...
MultiPhraseQueryPtr | newMultiPhraseQuery ()
| Builds a new MultiPhraseQuery instance. More...
QueryPtr | newPrefixQuery (TermPtr prefix)
| Builds a new PrefixQuery instance. More...
QueryPtr | newFuzzyQuery (TermPtr term, double minimumSimilarity, int32_t prefixLength)
| Builds a new FuzzyQuery instance. More...
QueryPtr | newRangeQuery (const String &field, const String &part1, const String &part2, bool inclusive)
| Builds a new TermRangeQuery instance. More...
QueryPtr | newMatchAllDocsQuery ()
| Builds a new MatchAllDocsQuery instance. More...
QueryPtr | newWildcardQuery (TermPtr term)
| Builds a new WildcardQuery instance. More...
virtual QueryPtr | getBooleanQuery (Collection< BooleanClausePtr > clauses)
| Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in. More...
virtual QueryPtr | getBooleanQuery (Collection< BooleanClausePtr > clauses, bool disableCoord)
| Factory method for generating query, given a set of clauses. By default creates a boolean query composed of clauses passed in. More...
String | discardEscapeChar (const String &input)
| Returns a String where the escape char has been removed, or kept only once if there was a double escape. Supports escaped unicode characters, eg. translates \u0041 to A. More...
bool | jj_2_1 (int32_t xla)
bool | jj_3R_2 ()
bool | jj_3_1 ()
bool | jj_3R_3 ()
QueryParserTokenPtr | jj_consume_token (int32_t kind)
bool | jj_scan_token (int32_t kind)
int32_t | jj_ntk ()
void | jj_add_error_token (int32_t kind, int32_t pos)
void | jj_rescan_token ()
void | jj_save (int32_t index, int32_t xla)
Protected Member Functions inherited from Lucene::QueryParserConstants
| QueryParserConstants ()
Protected Member Functions inherited from Lucene::LuceneObject
| LuceneObject ()

## Protected Attributes

Collection< String > | fields
MapStringDouble | boosts
Protected Attributes inherited from Lucene::QueryParser
Operator | _operator
| The actual operator that parser uses to combine query terms. More...
int32_t | _jj_ntk
| Next token. More...
QueryParserTokenPtr | jj_scanpos
QueryParserTokenPtr | jj_lastpos
int32_t | jj_la
int32_t | jj_gen
Collection< int32_t > | jj_la1
Collection< JJCallsPtr > | jj_2_rtns
bool | jj_rescan
int32_t | jj_gc
Collection< Collection< int32_t > > | jj_expentries
Collection< int32_t > | jj_expentry
int32_t | jj_kind
Collection< int32_t > | jj_lasttokens
int32_t | jj_endpos

## Additional Inherited Members

Public Types inherited from Lucene::QueryParser
enum | Operator { OR_OPERATOR, AND_OPERATOR }
| The default operator for parsing queries. Use QueryParser#setDefaultOperator to change it. More...
Data Fields inherited from Lucene::QueryParser
bool | lowercaseExpandedTerms
RewriteMethodPtr | multiTermRewriteMethod
bool | allowLeadingWildcard
bool | enablePositionIncrements
AnalyzerPtr | analyzer
String | field
int32_t | phraseSlop
double | fuzzyMinSim
int32_t | fuzzyPrefixLength
std::locale | locale
DateTools::Resolution | dateResolution
MapStringResolution | fieldToDateResolution
CollatorPtr | rangeCollator
QueryParserTokenManagerPtr | token_source
| Generated Token Manager. More...
QueryParserTokenPtr | token
| Current token. More...
QueryParserTokenPtr | jj_nt
| Next token. More...
Static Public Attributes inherited from Lucene::QueryParserConstants
static Collection< String > | tokenImage
| Literal token values. More...
Protected Types inherited from Lucene::QueryParser
typedef boost::shared_ptr < JJCalls > | JJCallsPtr
Static Protected Member Functions inherited from Lucene::QueryParser
static int32_t | hexToInt (wchar_t c)
| Returns the numeric value of the hexadecimal character. More...
static String | escape (const String &s)
| Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding . More...
Static Protected Attributes inherited from Lucene::QueryParser
static const int32_t | CONJ_NONE
static const int32_t | CONJ_AND
static const int32_t | CONJ_OR
static const int32_t | MOD_NONE
static const int32_t | MOD_NOT
static const int32_t | MOD_REQ
static const int32_t | jj_la1_0 []
static const int32_t | jj_la1_1 []

## Detailed Description

A QueryParser which constructs queries to search multiple fields.

## Constructor & Destructor Documentation

Lucene::MultiFieldQueryParser::MultiFieldQueryParser | ( | LuceneVersion::Version | matchVersion,
|  | Collection< String > | fields,
|  | AnalyzerPtr | analyzer,
|  | MapStringDouble | boosts
| ) |  |

Creates a MultiFieldQueryParser. 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 title and body):

    (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.

Lucene::MultiFieldQueryParser::MultiFieldQueryParser | ( | LuceneVersion::Version | matchVersion,
|  | Collection< String > | fields,
|  | AnalyzerPtr | analyzer
| ) |  |

Creates a MultiFieldQueryParser. 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 title and body):

    (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)

In other words, all the query's terms must appear, but it doesn't matter in what fields they appear.

virtual Lucene::MultiFieldQueryParser::~MultiFieldQueryParser | ( | ) |  |

virtual

## Member Function Documentation

static String Lucene::MultiFieldQueryParser::_getClassName | ( | ) |  |

inline static

void Lucene::MultiFieldQueryParser::applySlop | ( | QueryPtr | query,
|  | int32_t | slop
| ) |  |

protected

virtual String Lucene::MultiFieldQueryParser::getClassName | ( | ) |  |

inline virtual

Reimplemented from Lucene::QueryParser.

virtual QueryPtr Lucene::MultiFieldQueryParser::getFieldQuery | ( | const String & | field,
|  | const String & | queryText,
|  | int32_t | slop
| ) |  |

protected virtual

Base implementation delegates to getFieldQuery(const String&, const String&). This method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.

Reimplemented from Lucene::QueryParser.

virtual QueryPtr Lucene::MultiFieldQueryParser::getFieldQuery | ( | const String & | field,
|  | const String & | queryText
| ) |  |

protected virtual

Use the analyzer to get all the tokens, and then build a TermQuery, PhraseQuery, or nothing based on the term count.

Reimplemented from Lucene::QueryParser.

virtual QueryPtr Lucene::MultiFieldQueryParser::getFuzzyQuery | ( | const String & | field,
|  | const String & | termStr,
|  | double | minSimilarity
| ) |  |

protected virtual

Factory method for generating a query (similar to getWildcardQuery). Called when parser parses an input term token that has the fuzzy suffix (~) appended.

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

Reimplemented from Lucene::QueryParser.

virtual QueryPtr Lucene::MultiFieldQueryParser::getPrefixQuery | ( | const String & | field,
|  | const String & | termStr
| ) |  |

protected virtual

Factory method for generating a query (similar to getWildcardQuery). Called when parser parses an input term token that uses prefix notation; that is, contains a single '*' wildcard character as its last character. Since this is a special case of generic wildcard term, and such a query can be optimized easily, this usually results in a different query object.

Depending on settings, a 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 wild card queries, which may be necessary due to missing analyzer calls.

Parameters

  field | Name of the field query will use.
  termStr | Term token to use for building term for the query (without trailing '*' character)

Returns
  Resulting Query built for the term

Reimplemented from Lucene::QueryParser.

virtual QueryPtr Lucene::MultiFieldQueryParser::getRangeQuery | ( | const String & | field,
|  | const String & | part1,
|  | const String & | part2,
|  | bool | inclusive
| ) |  |

protected virtual

Builds a new TermRangeQuery instance for given min/max parts.

Reimplemented from Lucene::QueryParser.

virtual QueryPtr Lucene::MultiFieldQueryParser::getWildcardQuery | ( | const String & | field,
|  | const String & | termStr
| ) |  |

protected virtual

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.

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

Reimplemented from Lucene::QueryParser.

static QueryPtr Lucene::MultiFieldQueryParser::parse | ( | LuceneVersion::Version | matchVersion,
|  | Collection< String > | queries,
|  | Collection< String > | fields,
|  | AnalyzerPtr | analyzer
| ) |  |

static

Parses a query which searches on the fields specified.

If x fields are specified, this effectively constructs:

    (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)

Parameters

  matchVersion | Lucene version to match; this is passed through to QueryParser.
  queries | Queries strings to parse
  fields | Fields to search on
  analyzer | Analyzer to use

static QueryPtr Lucene::MultiFieldQueryParser::parse | ( | LuceneVersion::Version | matchVersion,
|  | const String & | query,
|  | Collection< String > | fields,
|  | Collection< BooleanClause::Occur > | flags,
|  | AnalyzerPtr | analyzer
| ) |  |

static

Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.

    Usage:
    Collection<String> fields = newCollection<String>(L"filename", L"contents", L"description");
    Collection<BooleanClause::Occur> flags = newCollection<BooleanClause::Occur>(BooleanClause::SHOULD, BooleanClause::MUST, BooleanClause::MUST_NOT);
    MultiFieldQueryParser::parse(L"query", fields, flags, analyzer);

The code above would construct a query:

    (filename:query) +(contents:query) -(description:query)

Parameters

  matchVersion | Lucene version to match; this is passed through to QueryParser.
  query | Query string to parse
  fields | Fields to search on
  flags | Flags describing the fields
  analyzer | Analyzer to use

static QueryPtr Lucene::MultiFieldQueryParser::parse | ( | LuceneVersion::Version | matchVersion,
|  | Collection< String > | queries,
|  | Collection< String > | fields,
|  | Collection< BooleanClause::Occur > | flags,
|  | AnalyzerPtr | analyzer
| ) |  |

static

Parses a query, searching on the fields specified. Use this if you need to specify certain fields as required, and others as prohibited.

    Usage:
    Collection<String> query = newCollection<String>(L"query1", L"query2", L"query3");
    Collection<String> fields = newCollection<String>(L"filename", L"contents", L"description");
    Collection<BooleanClause::Occur> flags = newCollection<BooleanClause::Occur>(BooleanClause::SHOULD, BooleanClause::MUST, BooleanClause::MUST_NOT);
    MultiFieldQueryParser::parse(query, fields, flags, analyzer);

The code above would construct a query:

    (filename:query1) +(contents:query2) -(description:query3)

Parameters

  matchVersion | Lucene version to match; this is passed through to QueryParser.
  queries | Queries string to parse
  fields | Fields to search on
  flags | Flags describing the fields
  analyzer | Analyzer to use

boost::shared_ptr< MultiFieldQueryParser > Lucene::MultiFieldQueryParser::shared_from_this | ( | ) |  |

inline

## Field Documentation

MapStringDouble Lucene::MultiFieldQueryParser::boosts

protected

Collection<String> Lucene::MultiFieldQueryParser::fields

protected

The documentation for this class was generated from the following file:

- MultiFieldQueryParser.h

clucene.sourceforge.net