|
@@ -123,7 +123,11 @@ Supported ops: `eq`, `ne`, `lt`, `lte`, `gt`, `gte`, `in`, `contains`, `exists`,
|
|
|
- `in` - value is a JSON array, e.g. `colour:in:["red","yellow"]`.
|
|
- `in` - value is a JSON array, e.g. `colour:in:["red","yellow"]`.
|
|
|
- `contains` - **array membership**, not substring: it matches when the field is an array holding the value. `colour:contains:yellow` does NOT match the string `"yellow"`.
|
|
- `contains` - **array membership**, not substring: it matches when the field is an array holding the value. `colour:contains:yellow` does NOT match the string `"yellow"`.
|
|
|
- `search` - **IGNORES THE FIELD NAME.** A case-insensitive substring over the WHOLE document: its id, its keys, and every string and number in it. So `colour:search:ell` matches `"yellow"` in `colour` AND a document whose `note` says "excellent", AND one whose id contains `ell`. The field is syntactically required and semantically discarded - `nosuchfield:search:ell` matches exactly what `colour:search:ell` does. **For a substring within ONE field, use `regex` on that field.** Worth care if a `search` filter is doing scoping work: it admits rows you may believe it excludes, and in the same direction as a filter that was dropped entirely.
|
|
- `search` - **IGNORES THE FIELD NAME.** A case-insensitive substring over the WHOLE document: its id, its keys, and every string and number in it. So `colour:search:ell` matches `"yellow"` in `colour` AND a document whose `note` says "excellent", AND one whose id contains `ell`. The field is syntactically required and semantically discarded - `nosuchfield:search:ell` matches exactly what `colour:search:ell` does. **For a substring within ONE field, use `regex` on that field.** Worth care if a `search` filter is doing scoping work: it admits rows you may believe it excludes, and in the same direction as a filter that was dropped entirely.
|
|
|
-- `regex` - regular-expression match, and the field IS honoured. This is the field-scoped substring: `colour:regex:ell`.
|
|
|
|
|
|
|
+- `regex` - regular-expression match, and the field IS honoured. This is the field-scoped substring: `colour:regex:ell`. **Three things about it are measurable and none of them announce themselves, so read this before building a search box on it.** Everything in the four bullets below was measured against **database 2.17.2**, which is what the deployed server runs today. **A move to RE2 is in progress upstream and will change three of the four**, so treat these as the behaviour of the current server rather than as a standing contract: under RE2 a character class becomes character-oriented (so `[áÁ]` starts working), `(?i)` becomes valid, an invalid pattern becomes a real error instead of an empty result, and the exponential backtracking goes away - while **backreferences and lookaround stop being supported**, since RE2 has neither. **The one piece of advice that is correct under BOTH engines is to spell alternatives out as alternation** (`sz(?:á|Á)mfejt`) and to escape anything a user typed; a pattern written that way needs no change when the server moves. This paragraph will be updated when it ships.
|
|
|
|
|
+ - **Matching is CASE-SENSITIVE and there is no flag to ask otherwise.** `text:regex:dolgoz` and `text:regex:Dolgoz` are different queries. **`(?i)` does NOT work** - it is not valid in this grammar, and an invalid pattern behaves as described two bullets down, so `(?i)Dolgoz` reads as "no matches" rather than as an error. Case-fold caller-side: spell the alternatives out, e.g. `text:regex:(?:d|D)olgoz`.
|
|
|
|
|
+ - **The engine is BYTE-oriented, not UTF-8 aware, so a CHARACTER CLASS over non-ASCII text is wrong in BOTH directions.** A character class matches one BYTE, and any non-ASCII character is several. So `sz[áÁ]mfejt` can never match `számfejt` - it reads as "no matches" - while `[öÖ]` matches almost every Hungarian sentence, because `ö` and `Ö` share the lead byte `0xC3` with `á é í ó ú ü ő ű` and the class degenerates into match-nearly-anything. One failure reads as an empty corpus and the other as a broken search; neither reports a fault. **Use ALTERNATION of the whole sequences instead of a class**: `sz(?:á|Á)mfejt` is correct and was measured correct. The same caution applies to `.`, `\w` and any quantifier applied to a non-ASCII character, since each addresses bytes rather than characters.
|
|
|
|
|
+ - **AN INVALID PATTERN MATCHES NOTHING AND ANSWERS 200 - it is NOT an error.** `text:regex:dolgoz(` cannot compile, and the response is a clean empty result list, indistinguishable from a valid pattern that genuinely matched no rows. Note this is a different layer from the **400** `bad_filter` below, which catches a malformed `field:op:value` SPEC: a well-formed spec carrying a broken PATTERN is not currently refused anywhere. **So never pass end-user text through to `regex` unescaped** - every unbalanced `(`, `[` or trailing `\` a customer types in a search box will look to them like an empty knowledge base. Escape the input, or validate the pattern before sending it.
|
|
|
|
|
+ - **Avoid nested quantifiers on caller-supplied input** (`(a+)+`, `(.*)*` and similar). The engine backtracks exponentially: measured in isolation, a 6-character pattern of that shape against a 26-byte subject took 11 seconds and did not finish within 25 at 28 bytes. A pattern you construct yourself is fine; one assembled from user input is a way to make your own queries time out.
|
|
|
- `exists` - `field:exists:true` / `field:exists:false`.
|
|
- `exists` - `field:exists:true` / `field:exists:false`.
|
|
|
|
|
|
|
|
The value is parsed as JSON when it parses (numbers, booleans, arrays), otherwise it is taken as a string. Everything after the second `:` is the value, so a value may itself contain `:`. A malformed spec or unknown operator is rejected with **400** `bad_filter`.
|
|
The value is parsed as JSON when it parses (numbers, booleans, arrays), otherwise it is taken as a string. Everything after the second `:` is the value, so a value may itself contain `:`. A malformed spec or unknown operator is rejected with **400** `bad_filter`.
|