This description of Montezuma Query Syntax is based on the implementation of the Montezuma Query Parser grammar used to process search queries. It is intended to be a guide for the construction of Montezuma queries, rather than to be a rigourous BNF definition of Montezuma query syntax.
Query character input has been extended with Character Entities which facilitates the inclusion of any Unicode characters into query input.
A Montezuma Query generally consists of one or more clauses, but not necessarily!
A query without clauses is equivalent to a wild-card search for all documents regardless of document content.
The full range of sort orders may be used to express built-in document number and score value sorts in addition to document fields in the index for sorting in either ascending or descending order.
Boundary values can used to specify the first document and number of documents to be retrieved.
Finally, the fields extracted from documents in search results can be used to select specified document fields.
Clauses can be combined in a list or with logical operators ('and', 'or', 'not').
In addition, clauses may be prefixed by a field specifier, optionally using a wild-card field specifier.
Queries may be given a boost factor to tune the weight of some clauses relative to the others.
Range Queries consist of one or two limiting values with operators for inclusive or exclusive limits.
Fuzzy Queries consist of a word value followed by a '~' and optionally a fuzzy factor between 0 and 1.0 which are satisfied by field words with an closely matching editing difference.
Support has been added for typed terms and range queries for: integer, float and dates.
Dates can be specified in a form based on ISO 8601: YYYYMMDDTHHmmSSssssss. A minimum datetime value is a four digit year. Datetimes may be followed by a timezone offset: Z, or a + or - followed by hhmm. For example, 2016 or 20151225. Note: dates with or without times and timezone offsets must be given without either spaces or non-alphabetic
punctuatiom. Alternatively, datetime values may be specified in a quoted datetime phrase which makes them easier to enter and read, e.g. '2015-12-25'.
Similarly, fields me be defined in a Montezuma Index as int or float in which case the Query Parser generates typed queries for these fields.
Execution of typed terms and ranges is coordinated between field definitions in the Montezuma Index and terms in queries.
~~~~~
<montezuma-query> ::= <clause> <sort-order> <boundaries> <field-list>
<boundaries> ::= ':' <first-document> ',' <number-of-documents> | ''
<first-document> ::= integer
<number-of-documents> ::= integer
<sort-order> ::= '/' <direction> <sorting> | ''
<direction> ::= '+' | '-' | ''
<sorting>> ::= 'document' | 'score' | <word> | '(' <sort-field-names> ')'
<sort-field-names> ::= <sort-field-name> | <sort-field-name> <sort-field-names>
<sort-field-name> ::= <direction> <word>
<field-list> ::= '[' <field-names> ']</field-names>' | ''
<field-names> ::= <field-name> | <field-name> <field-names>
<field-name> ::= <wild-word> | <word>
<logical-operator> ::= 'not' | 'and' | 'or' | ''
<field-specifier> ::= <field-name> ':' | ''
<simple-query> ::= <phrase-query> | <wild-query> | <parenthesised-query> |
<field-range-query> | <fuzzy-query> | <term-query>
<clause> ::= <logical-operator> <field-specifier> <simple-query> <boost> | ''
<boost> ::= '^' <number> | ''
<field-range-query> ::= <lower-bound> <word> 'to' <word> <upper-bound>
<lower-bound> ::= '[' | '{']
<upper-bound> ::= '</upper-bound>' | '}'
<parenthesised-query> ::= '(' <clause> ')'
<phrase> ::= '"' <word-list> '"' <proximity>
<word-list> ::= <word> | <word> <word-list>
<proximity> ::= '~' integer | ''
<term-query> ::= <word>
<fuzzy-query> ::= <word> '~' <fuzzy-factor>
<fuzzy-factor> ::= <number> | ''
<wild-query> ::= <wild-word>
<number> ::= integer | real
<letter> ::= <non-wild-letter> | <character-entity>
<word> ::= <letter> | <letter> <word>
<character-entity> ::= <decimal-entity> | <hexadecimal-entity> | <named-entity>
<decimal-entity> ::= '&#' integer ';'
<hexdecimal-entity> ::= '&#x' hexadecimal-number ';'
<named-entity> ::= '&' <word> ';'
<wild-word-constituent> ::= <any-letter> | <wild-letter> | <character-entity>
<wild-word> ::= non-wild-letter <wild-letter> <wild-word-constituent></wild-word-constituent></wild-letter>
<wild-letter> ::= '' | ''
<any-letter> ::= '[A-Z0-9-]'
<non-wild-letter> ::= [^*?]
~~~~</non-wild-letter></any-letter></wild-letter></wild-word></character-entity></wild-letter></any-letter></wild-word-constituent></word></named-entity></hexdecimal-entity></decimal-entity></named-entity></hexadecimal-entity></decimal-entity></character-entity></word></letter></letter></word></character-entity></non-wild-letter></letter></number></wild-word></wild-query></number></fuzzy-factor></fuzzy-factor></word></fuzzy-query></word></term-query></proximity></word-list></word></word></word-list></proximity></word-list></phrase></clause></parenthesised-query></lower-bound></upper-bound></word></word></lower-bound></field-range-query></number></boost></boost></simple-query></field-specifier></logical-operator></clause></term-query></fuzzy-query></field-range-query></parenthesised-query></wild-query></phrase-query></simple-query></field-name></field-specifier></logical-operator></word></wild-word></field-name></field-names></field-name></field-name></field-names></field-list></word></direction></sort-field-name></sort-field-names></sort-field-name></sort-field-name></sort-field-names></sort-field-names></word></sorting></direction></sorting></direction></sort-order></number-of-documents></first-document></number-of-documents></first-document></boundaries></field-list></boundaries></sort-order></clause></montezuma-query>