Library
FD1 Query Selector Options
The "q" parameter allows you to query a subset of rows from the endpoint. Not all endpoints honour "q", but the majority do.
Some quick examples to start:
{
a: "fd1.data",
q: {
"rve(>)": 20260113.135466,
"description(like)": "bob"
},
v: {
table: "logical.products"
}
}
- Look at the logical.products data.
- Only select items where description is like 'bob'. You do not need to add wildcards
- And only those products that also have rve > 20260113.135466
{
a: "fd1.data",
q: {
"department": [2,3,4],
"spid": 8
},
v: {
table: "logical.products"
}
}
- Look at the logical.products data.
- Only return where products are in departments 2,3 or 4
- And supplier is #8 (it can be words or other forms as well)
{
a: "fd1.data",
q: {
"email(like,typed)": "ruth@gamil.com"
},
v: {
table: "logical.customers"
}
}
- Look at the logical.customers data.
- Look for "ruth@gamil.com" - note the typo
- Due to "typed" modifier, meaning this was typed by a user, the engine will probably return ruth@gmail.com (correct/near spelling)
q "Query" Object
Some endpoints use a "q" object to query, select or restrict the data to be accessed. In SQL terminology this would be the "where" clause
- Any Field name that starts with an underscore has special meaning
- Any field that starts with a letter is a reference to column in the data
- If a field name is used in isolation (eg "id": 123 ) then this means id=value
- If a field name includes a bracket reference at the end, (eg "id(gt)": 4041 means id > 4041 ) then this defines the requested predicate check. Endpoints can block predicate types if they wish, do not assume that you can use different predicates on every field
-
Predicate checks contain many of the standard checks you would expect, =,<,>,like and also some advanced ones such as
like.words - search for words in any order
bitnset - test if a specific bit is set. -
Predicate checks can contain modifiers to provide hints, description(like,typed):"bob" means perform a like operation for "bob", where bob was typed by the user.
sku(=,voice):"PLZ123" - search "sku" for exact match of "PLZ123". The PLZ123 was captured by voice, so the engine may choose to search for common verbal variations.
or sku(=,ocr):"B0B" - search sku for B-zero-B. The engine may choose to also search for B-Oh-B as well, as 0/O confusion can occur with OCR engines.Using modifers implies that you are wanting to receive "near matches" in the results. If you only want exact match, do not add modifiers.
- When q requests are processed, the engine may output warnings as "warn" packets on the output.
| Q Field | Server Operation | Description | Example |
| field field(=) field(eq) field(equal) | Field = value | Checks for equality | id: 67 |
| field(>) field(gt) field(greaterthan) | Field > value | "id(>)": 67 | |
| field(>=) field(ge) field(greaterthanequal) | Field >= value | "id(>=)": 67 | |
| field(<) field(gt) field(lessthan) | Field < value | "id(<)": 67 | |
| field(<=) field(le) field(lessthanequal) | Field <= value | "id(<=)": 67 | |
| field(!=) field(<>) field(ne) field(notequal) | Field <> value | "id(!=)": 67 | |
| field(like) | Field like value | ||
| field(like.words) | multiple likes |
Performs a like operation, treating each whitespace delimited word as a seperate term, with "or" selection of individual words.
eg. description(like.words): "cat dog mouse" searchs for rows that contain "cat" or "dog" or "mouse". |
|
| field(in) | Field in value | Selects only rows where field has one of a list of values. eg. "customer_type(in)": [3,4,5] selects only rows where customer_type is 3,4 or 5 | |
| field(bitnset) | Field & (1 << value) |
Selects rows where a single bit is set. The bit is given by the value. Bit numbers count from zero.
eg. flags(bitnset): 1 tests the flags field against the bitmask 00000010 (binary) |
|
| field(search) | Search for value in field |
Searches the single field for the value. The engine tries to identify the best matching rows for the information given, it is not
necessarily simple pattern matching. Searching with this check will generally result in some rows being returned - it is intended to be used where the
user is searching for something, and returning no results is tedious for the user.
Specifically, search will scan the field for the input value, but may apply any transform it feels appropriate, including changing spelling, dropping words, applying distance transforms and other checks. This form of search check is against a single field. See also _search to search against several fields in the row. |
|
| If "value" is an array. Array size must be less than 16 elements. | |||
| field field(=) field(eq) field(equal) |
Field = [value] | Checks if field is in the list of values. An array of [1,2,4] becomes (field=1 or field=2 or field=4) | id: [67,232,8921] |
Modifiers
A modifer can be applied to a predicate to indicate processing hints. The server is free to ignore modifiers. Modifiers allow the server to make small obvious changes to the value, but exact matches to the provided value take priority for the returned result. In the first example below, if the name "bpb" and "bob" both exist, "bpb" will be returned, not "bob". "bob" can only be returned if there is no "bpb"
| Q Field | Description |
| "name(like,typed)": "bpb" | Search for name like "bpb", and indicate that the user typed "bpb", so server can choose to expand the query. In this case, it may expand the query to name like '%bpb%' or name like '%bob%' |
| "name(like,voice)": "gita" | Search for name like "gita", and indicate that "gita" was acquired using speech to text tools. In this case, it may expand the query to name like '%gita%' or name like '%g?%ta%' |
| "invoice_number(=,ocr)": "ABC-O09" |
The search value has come from an OCR (optical character recognition) engine. These engines dont always get random text like invoice numbers 100% correct,
understandable, they dont have any context.
The invoice number here might be "Ay Bee Cee dash Oh Zero Nine", but there is a chance it might be "Ay Bee Cee dash ZERO Zero Nine". The server may elect to search both variations, favouring "Oh zero nine" if that exists. |
| "invoice_number(=,anything)": "Acme" | Experimental. Unsupported. Do whatever to try and return some rows. This option is intended to be used for "search" type functionality where the user should enter an invoice numnber into a search field, but mistakenly starts typing the supplier name. |
Q Warnings
The q engine can feedback issues by outputting a series of "warn" objects on the output.
{
q: {
id_number: "abc",
short_code: "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz23"
}
}
May result in the following response
{
data: {
rows: []
},
warn: [
{
area: "q",
key: "id_number",
message: "id_number can only be digits, result is therefore empty array"
},
{
area: "q",
key: "short_code",
message: "Short_code is defined by site policy to be maximum 12 characters, the input is longer than that so no rows can possibly match"
}
]
}
Example selecting a subset of products
{
a: "FD1 endpoint to read products"
q: {
"description(like)": "en",
"depid(in)": [3,4,5],
"price(ge)": 100,
"price(lt)": 2500
}
}
The server might run the equivalent of this SQL
select ... where description like '%en%' and depid in (3,4,5) and price >= 100 and price < 2500
Reserved Field Names
| Q Field | Description |
| _search | Searchs an entire row for the value, where "value" is treated as both scaler/absolute values and potential semantic meaning. When using _search we recommend supplying a modifier for how "value" was acquired. eg _search(typed) or _search(voice) |
| _limit | Requests a limit on the number of rows to return. The system can ignore this limit, and system administrators may set limits as well. |
_search
This keyword causes the engine to scan the entire row for "value". It is intended primarily for user facing search. Not all fields will be searched and the server decides which fields should be checked. Some site specific selection may be possible for some tables.
- A search such as _search(typed): "unsub" will select which fields to search dynamically. In this case, the "email" field will not be searched as there is no "@". Even if the email field contains exactly "unsub", it is unlikely to be searched, as emails require "@", and we do not support storing non standard data into fields.
- The search _search(typed): "no email" may choose to select only rows where email is either blank or invalid, but will eliminate rows with probably valid emails.
- _search will always at least perform a like style operation on key description style fields.
-
You can use other predicates as well as search, the following applies a generic search, but only on the subset of products from supplier Acme
{ q: { supplier: "acme", "_search(typed)": "water based paint in stock" } }