• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

Namespace Lucene.Net.QueryParsers.Classic

Classes

FastCharStream

An efficient implementation of JavaCC's ICharStream interface.

Note that this does not do line-number counting, but instead keeps track of the character position of the token in the input, as required by Lucene's Token API.

LexicalToken

MultiFieldQueryParser

A QueryParser which constructs queries to search multiple fields.

ParseException

This exception is thrown when parse errors are encountered. You can explicitly create objects of this exception type by calling the method GenerateParseException in the generated parser.

You can modify this class to customize your error reporting mechanisms so long as you retain the public fields.

QueryParser

This class is generated by JavaCC. The most important method is Parse(String).

The syntax for query strings is as follows: A Query is a series of clauses. A clause may be prefixed by:

  • a plus (+) or a minus (-) sign, indicating that the clause is required or prohibited respectively; or
  • a term followed by a colon, indicating the field to be searched. This enables one to construct queries which search multiple fields.

A clause may be either:

  • a term, indicating all the documents that contain this term; or
  • a nested query, enclosed in parentheses. Note that this may be used with a +/- prefix to require any of a set of terms.

Thus, in BNF, the query grammar is:

    Query  ::= ( Clause )*
    Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )

Examples of appropriately formatted queries can be found in the query syntax documentation.

In TermRangeQuerys, QueryParser tries to detect date values, e.g. date:[6/1/2005 TO 6/4/2005] produces a range query that searches for "date" fields between 2005-06-01 and 2005-06-04. Note that the format of the accepted input depends on the System.Globalization.CultureInfo. A DateTools.Resolution has to be set, if you want to use DateTools for date conversion.

The date resolution that shall be used for RangeQueries can be set using SetDateResolution(DateTools.Resolution) or SetDateResolution(String, DateTools.Resolution). The former sets the default date resolution for all fields, whereas the latter can be used to set field specific date resolutions. Field specific date resolutions take, if set, precedence over the default date resolution.

If you don't use DateTools in your index, you can create your own query parser that inherits QueryParser and overwrites GetRangeQuery(String, String, String, Boolean, Boolean) to use a different method for date conversion.

Note that QueryParser is not thread-safe.

NOTE: there is a new QueryParser in contrib, which matches the same syntax as this class, but is more modular, enabling substantial customization to how a query is created.

NOTE: You must specify the required LuceneVersion compatibility when creating QueryParser:

  • As of 3.1, AutoGeneratePhraseQueries is false by default.

QueryParserBase

This class is overridden by QueryParser.

QueryParserBase.MethodRemovedUseAnother

Do not catch this exception in your code, it means you are using methods that you should no longer use.

QueryParserConstants

Token literal values and constants. Generated by org.javacc.parser.OtherFilesGen#start()

QueryParserTokenManager

Token Manager.

RegexpToken

Token

Describes the input token stream.

TokenMgrError

Token Manager Error.

Interfaces

ICharStream

This interface describes a character stream that maintains line and column number positions of the characters. It also has the capability to backup the stream to some extent. An implementation of this interface is used in the TokenManager implementation generated by JavaCCParser.

All the methods except BackUp(Int32) can be implemented in any fashion. BackUp(Int32) needs to be implemented correctly for the correct operation of the lexer. Rest of the methods are all used to get information like line number, column number and the string that constitutes a token and are not used by the lexer. Hence their implementation won't affect the generated lexer's operation.

Enums

Operator

The default operator for parsing queries. Use DefaultOperator to change it.

Back to top Copyright © 2017 Alachisoft