MMOframework
Why AI Playground Libraries Documentation Search Agency
FR EN
Index

SearchQuery

MMO.core · 1 symbol · generated 27 Oct 2026

class

SearchQuery

SearchQuery.js:28

The model behind <mmo-search>: a query's filters seen as a list of chips, and back.

class MMO.core.SearchQuery
Namespace
MMO.core
A filter (`MMO.core.APIRequester#filters`, the `?filters[...]` of a repository url) is a tree; the bar shows the part of it a user reads at a glance: - `conditions`: one chip each, `{path, op, value}` -- `op` is a filter operator (`$eq`, `$in`, `$regex`...) or `$between` (a `$gte` and a `$lte` on the same path, one chip); - `any`: the conditions are ORed, not ANDed; - `text`: the free text, ORed `$regex` over the text fields (or the `$text` search, `Parse`); - `search`: a search property of the collection (`?search[type]=siren&search[text]=123`); - `advanced`: what the bar cannot show as a chip (nested groups, `$nor`...), kept verbatim so nothing is lost. A field (`FieldsFromSchema`) is `{key, title, kind, values}`, `kind` being `text`, `ref`, `enum`, `bool`, `number`, `date` or `search`: it decides the operators offered, how a typed value is read (`ParseToken`) and how a value is shown (`Label`). `key` is the path filtered on, an alias's too (`adresse/ville`: the server filters on what it reads, `adresses/default/ville`); `word`, what is typed for it. A property of an embedded object is a field of its own (`adresse/ville`, "Adresse - Ville", its `parent` being `adresse`, its `group` "Adresse"); a `ref` (an entity of another collection) has the `collection` its entities are listed from and the `labels` known of them, by uid: its value is an uid.
const state = MMO.core.SearchQuery.Parse({'$and': [{status: {'$in': ['active', 'pending']}}]}); state.conditions; // [{path: 'status', op: '$in', value: ['active', 'pending']}] MMO.core.SearchQuery.Build(state); // {'$and': [{status: {'$in': ['active', 'pending']}}]}

Index

OPERATORS static readonly accessor
FieldsFromSchema(schema) static asyncThe fields a collection can be filtered on: its visible properties a chip can describe, in their order, then its search properties that take one text (#[SearchProperty] without a view; label is…
FieldOf(prop, key, parent) static asyncThe field a property is, its enum loaded, its class looked at: an entity of a collection (its class has an id) is a ref, picked by its label (RefQuery); an embedded one an object, whose …
CollectionOf(prop, instance) staticWhere the entities a property points to are listed from: its schema's collection, or the $collection the server gives their class in data/schemas.json (mmo.core's `RepositoryController::getCo…
KindOf(schema) static
TextFields(fields) static
MatchField(word, fields) staticThe field a typed word names, by its key or its title (case and accents ignored): statut or Statut is the field status titled "Statut".
SuggestFields(word, fields) staticThe fields a word being typed could be the start of, best first: those it starts, then those it is in.
NamesOf(field, short) static
SuggestValues(field, word) staticThe values of an enum a typed word could be, best first, by value or by label.
Parse(filters, search) staticRead a query's filters (and search) as the bar shows them.
FlattenAnd(filter) staticThe members of a filter's root AND, wherever they sit: {a: 1, b: 2}, {'$and': [{a: 1}, {b: 2}]} and {'$and': [{a: 1}], b: 2} are all [{a: 1}, {b: 2}].
ConditionsOfItem(item) static
ConditionsOf(members) static
TextOf(members) static
Build(state, textFields) staticWrite the bar back as a filter.
ItemOf(cond) static
SetCondition(state, cond, index) staticAdd a condition, in place of the one already on that path -- except two bounds (> and <), which narrow the same path together.
ParseToken(field, raw) staticRead what was typed after field:.
MatchRef(field, text) staticThe entity a typed text names, among those whose label is known (AddRefs): the one it is the label of, or the only one whose label holds it.
SuggestRefs(field, word) staticThe entities a typed word could be, best first, among those whose label is known.
AddRefs(field, entities) staticLearn the labels of entities a ref field points to (Label shows them, MatchRef finds them).
RefQuery(field, {text = null, uids = null, limit = 20}) staticThe query listing the entities of a ref field: those whose label holds a text, or those it does not know the label of yet.
MissingRefs(state, fields) static
MatchValue(field, text) static
DateRange(text) staticThe days a typed date covers.
Bool(value) static
Operators(kind) staticThe operators the editor offers for a kind of field.
EditorOperator(cond, kind) staticThe editor's operator for a condition: Operators.
OperatorLabel(op, kind) static
Label(field, value) static
Describe(cond, field) staticWhat a chip says.
Normalize(value) static
IsNumericObject(value) static
List(value) static

Properties1

OPERATORS

staticreadonlyaccessorSearchQuery.js:30
static get OPERATORS()
Type
Array<string>

Methods34

FieldsFromSchema(schema)

staticasyncSearchQuery.js:45

The fields a collection can be filtered on: its visible properties a chip can describe, in their order, then its search properties that take one text (#[SearchProperty] without a view; label is the free text's).

static async FieldsFromSchema(schema)An enum class (`cStatus`, `type: ['instance', 'enum']`) lists its values in a schema of its own: it is loaded, hence the promise.
schemaMMO.schemas.Schemathe collection's schema
returnsPromise<Object<string, {key: string, title: string, kind: string, values: ?Array>>}

FieldOf(prop, key, parent)

staticasyncSearchQuery.js:84

The field a property is, its enum loaded, its class looked at: an entity of a collection (its class has an id) is a ref, picked by its label (RefQuery); an embedded one an object, whose properties are fields of their own (adresse/ville).

static async FieldOf(prop, key, parent = null)
propMMO.schemas.Schema
keystringits key in its entity
parent = null?Objectthe object field it is a property of: its path and title come first ("Adresse - Ville")
returnsPromise<?Object>null for a property a chip cannot describe

CollectionOf(prop, instance)

staticSearchQuery.js:135

Where the entities a property points to are listed from: its schema's collection, or the $collection the server gives their class in data/schemas.json (mmo.core's RepositoryController::getCollectionOf). Nothing is guessed: a class no collection holds, or several (an abstract one), has none, and its chip is typed by uid.

static CollectionOf(prop, instance = null)
propMMO.schemas.Schemaa ref property
instance = null?MMO.schemas.Schemathe schema of its class
returns?{collection: string, repository: ?string}

KindOf(schema)

staticSearchQuery.js:146
static KindOf(schema)
schemaMMO.schemas.Schemaa property's schema
returns?stringthe kind of field it is, null for one a chip cannot describe (an object, a list...)

TextFields(fields)

staticSearchQuery.js:167
static TextFields(fields)
fieldsObjectFieldsFromSchema
returnsArray<string>the paths the free text is looked for in

MatchField(word, fields)

staticSearchQuery.js:178

The field a typed word names, by its key or its title (case and accents ignored): statut or Statut is the field status titled "Statut".

static MatchField(word, fields)
wordstring
fieldsObjectFieldsFromSchema
returns?Objectthe field, null when the word names none

SuggestFields(word, fields)

staticSearchQuery.js:197

The fields a word being typed could be the start of, best first: those it starts, then those it is in.

static SuggestFields(word, fields)
wordstring'' lists them all
fieldsObjectFieldsFromSchema
returnsArray<Object>

NamesOf(field, short)

staticSearchQuery.js:213
static NamesOf(field, short = true)
fieldObject
short = truebooleanwith the names of a property of an embedded object alone (ville, "Ville")
returnsArray<string>the words that name a field, normalized: its key, what is typed for it, its title

SuggestValues(field, word)

staticSearchQuery.js:225

The values of an enum a typed word could be, best first, by value or by label.

static SuggestValues(field, word)
fieldObjectan enum field
wordstring
returnsArray<*>

Parse(filters, search)

staticSearchQuery.js:245

Read a query's filters (and search) as the bar shows them.

static Parse(filters, search = null)
filters?ObjectMMO.core.APIRequester#filters
search = null?ObjectMMO.core.APIRequester#search
returnsconditions: Array<Object>, any: boolean, text: string, search: ?Object, advanced: Array<Object>}

FlattenAnd(filter)

staticSearchQuery.js:288

The members of a filter's root AND, wherever they sit: {a: 1, b: 2}, {'$and': [{a: 1}, {b: 2}]} and {'$and': [{a: 1}], b: 2} are all [{a: 1}, {b: 2}].

static FlattenAnd(filter)
filter*
returnsArray<Object>

ConditionsOfItem(item)

staticSearchQuery.js:305
static ConditionsOfItem(item)
itemObjectone path and its value: {age: {'$gte': 18}}
returns?Array<Object>its conditions, null when a chip cannot describe it

ConditionsOf(members)

staticSearchQuery.js:332
static ConditionsOf(members)
membersArray<Object>the members of an OR
returns?Array<Object>one condition per member, null when one of them is not a single condition

TextOf(members)

staticSearchQuery.js:346
static TextOf(members)
membersArray<Object>the members of an OR
returns?stringthe free text they look for, when they are the same $regex on every path; null otherwise

Build(state, textFields)

staticSearchQuery.js:367

Write the bar back as a filter.

static Build(state, textFields = [])
stateObjectParse
textFields = []Array<string>the paths the free text is looked for in (TextFields); none when the text goes to a search instead
returns?Object{'$and': [...]}, null when there is nothing to filter on

ItemOf(cond)

staticSearchQuery.js:382
static ItemOf(cond)
condObjecta condition
returnsObjectits filter: {status: 'active'}, {age: {'$gte': 18}}...

SetCondition(state, cond, index)

staticSearchQuery.js:403

Add a condition, in place of the one already on that path -- except two bounds (> and <), which narrow the same path together.

static SetCondition(state, cond, index = null)
stateObjectParse
condObject
index = null?numberthe condition it replaces, when it is edited rather than added
returnsObjectstate

ParseToken(field, raw)

staticSearchQuery.js:430

Read what was typed after field:.

static ParseToken(field, raw)- every kind: `!x` is "is not x", `!` alone "is empty"; - enum: `active` or `active,pending`, by value or label (`actif`); - number: `18`, `>18`, `>=18`, `<`, `<=`, `18..30`; - date: `2026-09-01` (or `01/09/2026`, `2026-09`, `09/2026`, `2026` for the whole month/year), with the same `>`, `<` and `..` as a number; - bool: `oui`/`non`, `yes`/`no`, `true`/`false`, `1`/`0`; - text: `dup` contains it, `=Dupont` is exactly it; - ref: the entity whose label it is, or the only one whose label holds it (`MatchRef`), or an uid.
fieldObjectFieldsFromSchema
rawstring
returns?Objectthe condition, null when the text is not a value of that field

MatchRef(field, text)

staticSearchQuery.js:515

The entity a typed text names, among those whose label is known (AddRefs): the one it is the label of, or the only one whose label holds it. An uid (mongodb://.../contrats#12) is itself.

static MatchRef(field, text)
fieldObjecta ref field
textstring
returnsstring | undefinedits uid, undefined when the text names none, or several

SuggestRefs(field, word)

staticSearchQuery.js:532

The entities a typed word could be, best first, among those whose label is known.

static SuggestRefs(field, word)
fieldObjecta ref field
wordstring
returnsArray<string>their uids

AddRefs(field, entities)

staticSearchQuery.js:551

Learn the labels of entities a ref field points to (Label shows them, MatchRef finds them).

static AddRefs(field, entities)
fieldObjecta ref field
entitiesIterable<Object | string> | Objectwhat the api answered: {uid, metadata: {title}}, {uid, title}, or a list's links (<uid>;title="...", MMO.core.APIRequester#listOnly)
returnsArray<string>their uids, in their order

RefQuery(field, {text = null, uids = null, limit = 20})

staticSearchQuery.js:575

The query listing the entities of a ref field: those whose label holds a text, or those it does not know the label of yet.

static RefQuery(field, {text = null, uids = null, limit = 20} = {})
fieldObjecta ref field
{text = null, uids = null, limit = 20} = {}
returns?{collection: string, repository: ?string, filters: ?Object, search: ?Object, limit: number} null without a collection

MissingRefs(state, fields)

staticSearchQuery.js:592
static MissingRefs(state, fields)
stateObjectParse
fieldsObjectFieldsFromSchema
returnsObject<string, Array<string>>by field, the uids its chips hold whose label is not known yet

MatchValue(field, text)

staticSearchQuery.js:611
static MatchValue(field, text)
fieldObjectan enum field
textstringa value or its label, case and accents ignored; or the start of only one of them
returns*the value, undefined when the text is none of them

DateRange(text)

staticSearchQuery.js:624

The days a typed date covers.

static DateRange(text)
textstring2026-09-01, 01/09/2026, 1/9/26, 2026-09, 09/2026 or 2026
returns?Array<string>[first, last] as YYYY-MM-DD, null when it is not a date

Bool(value)

staticSearchQuery.js:655
static Bool(value)
value*
returns?booleannull when the value is no boolean

Operators(kind)

staticSearchQuery.js:672

The operators the editor offers for a kind of field. Besides the filter's own: $between, $on (a date's whole day), $set/$empty ($exists), $search (a search property).

static Operators(kind)
kindstring
returnsArray<string>

EditorOperator(cond, kind)

staticSearchQuery.js:690

The editor's operator for a condition: Operators.

static EditorOperator(cond, kind)
condObject
kindstring
returnsstring

OperatorLabel(op, kind)

staticSearchQuery.js:705
static OperatorLabel(op, kind)
opstringa filter or an editor operator
kindstring
returnsstringhow it reads: "contains", "is one of", "after", "≥"...

Label(field, value)

staticSearchQuery.js:721
static Label(field, value)
field?ObjectFieldsFromSchema, null for a path the schema does not describe
value*
returnsstringthe value as a user reads it: an enum's label, "yes", 01/09/2026...

Describe(cond, field)

staticSearchQuery.js:745

What a chip says.

static Describe(cond, field)
condObject
field?ObjectFieldsFromSchema
returnsfield: string, op: string, value: string}

Normalize(value)

staticSearchQuery.js:778
static Normalize(value)
value*
returnsstringlower case, without accents nor surrounding spaces: what two words are compared on

IsNumericObject(value)

staticSearchQuery.js:786
static IsNumericObject(value)
value*
returnsbooleantrue for an object whose keys are 0, 1, 2...: a list, as a query string can hand one over

List(value)

staticSearchQuery.js:796
static List(value)
value*
returnsArraythe value as a list: itself, its values (IsNumericObject) or [value]