Class: StructuredQuery

$k. StructuredQuery

new $k.StructuredQuery(domains)

Constructs structured query

Name Type Description
domains $k.Domain optional

The domain or internal name of a type

Since:
  • 4.1.0 Represents a structured query

Extends

Methods

addAlternativeGroup() : $k.AlternativeGroupCondition

Add an empty alternative condition group (OR group)

Since:
  • 4.2.0
Returns:
Type Description
$k.AlternativeGroupCondition

addAttribute(type) : $k.HasAttributeCondition

Add an empty attribute condition without value/cardinality conditions

Name Type Description
type

AttributeType or internal name

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.ObjectNotFound

If the attribute cannot be found

$k.exception.TypeError

If the type is not an attribute type

$k.exception.QueryError

If the condition is not valid

Returns:
Type Description
$k.HasAttributeCondition

addAttributeValue(type, parameter, operator, defaultValue) : $k.AttributeValueCondition

Add an attribute value condition

Name Type Description
type

AttributeType or internal name

parameter optional

Parameter name of the value

operator string optional

Name of operator

defaultValue optional

Default value if no parameter is specified

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.ObjectNotFound

If the attribute cannot be found

$k.exception.TypeError

If the type is not an attribute type

$k.exception.QueryError

If the condition is not valid

Returns:
Type Description
$k.AttributeValueCondition

addCardinality(type, cardinality, operator)

Add a cardinality condition

Name Type Description
type

AttributeType or internal name

cardinality number

Cardinality. Must be an integer >= 0.

operator string optional

Name of cardinality operator. "Equal cardinality" if not specified

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.ObjectNotFound

If the type cannot be found

$k.exception.TypeError

If the type is not a property type

$k.exception.QueryError

If the condition is not valid

Returns:
HasAttribute or HasRelation condition

addElementsFilter(parameter) : $k.ElementsCondition

Add an element condition. Only elements from the list / parameter are returned.

Name Type Description
parameter

Element or array of elements or the name of a parameter to use its value

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.TypeError

If neither elements or a parameter was passed

$k.exception.QueryError

If the condition is not valid

Returns:
Type Description
$k.ElementsCondition

addHandle(parameter) : Condition

Add a handle

Name Type Description
parameter string
Version:
  • Experimental feature, might be removed at any time
Since:
  • 4.1.0
Returns:
Type Description
Condition

addQueryReference(query, operator) : QueryReferenceCondition

References another query that selects elements of this query according to the operator. If $k.Operator.EQUAL or NOT_EQUAL are selected, then the reference works in both directions. If $k.Operator.FILTER is selected, then the subquery is only applied to this query.

Name Type Description
query optional

Referenced query. A new empty query will be referenced if not defined

operator string optional

An operator that defines how the subquery is applied. One of $k.Operator.EQUAL, NOT_EQUAL, FILTER. Default is FILTER

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.QueryError

If the condition is not valid

Returns:
Type Description
QueryReferenceCondition Condition for the subquery

addRelation(type) : $k.HasRelationCondition

Add an empty relation condition without target/cardinality conditions

Name Type Description
type

RelationType or internal name

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.ObjectNotFound

If the relation cannot be found

$k.exception.TypeError

If the type is not an relation type

$k.exception.QueryError

If the condition is not valid

Returns:
Type Description
$k.HasRelationCondition

addRelationTarget(type, targetQuery) : $k.RelationTargetCondition

Add a relation target condition

Name Type Description
type

RelationType or internal name

targetQuery optional

Target query. If not specified an empty subquery will be build

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.ObjectNotFound

If the relation cannot be found

$k.exception.TypeError

If the type is not an relation type

$k.exception.QueryError

If the condition is not valid

Returns:
Type Description
$k.RelationTargetCondition Condition for the relation target

clone() : $k.StructuredQuery

Returns a copy of the query. The copy can be modified.

Since:
  • 4.1.0
Throws:
Type Description
$k.exception.QueryError

If the query cannot be cloned

Returns:
Type Description
$k.StructuredQuery

conditions() : Array.<QueryConditon>

Returns the conditions of the query

Since:
  • 4.1.0
Returns:
Type Description
Array.<QueryConditon>

domains() : Array.<$k.Domain>

Returns the domains of the query

Since:
  • 4.1.0
Returns:
Type Description
Array.<$k.Domain>

filterHits(hits, parameters, searchString) : Array.<$k.Hit>

Returns all hits that match the query

Name Type Description
hits Array.<$k.Hit>
parameters object optional
searchString string optional
Since:
  • 5.3.0
See:
Throws:
Type Description
$k.exception.QueryError

When the query could not be solved, e.g. missing parameters

Returns:
Type Description
Array.<$k.Hit>
Example

var hits = $k.Registry.query("experts").filterHits(hits);

findSolutions(parameters, singleElementIdentifiers) : Array.<object>

Search and return all solutions

Name Type Description
parameters object optional
singleElementIdentifiers array optional
Since:
  • 5.2.2
Throws:
Type Description
$k.exception.QueryError

When the query could not be solved, e.g. missing parameters

Returns:
Type Description
Array.<object> Each solution is an object containing an element of the result set, and all elements at identifiers of the query, e.g. {element: element1, identifiers: { someIdentifier1: [ element2, ... ], someIdentifier2: [ element3, ... ] }}. Each identifier in singleElementIdentifiers will be distribute multiple elements to one separate solution each

inheritance() : boolean

Returns true if elements of subdomains should be returned

Since:
  • 4.1.0
Returns:
Type Description
boolean

inverseConditions() : Array.<QueryConditon>

Returns the conditions pointing to this query

Since:
  • 4.1.0
Returns:
Type Description
Array.<QueryConditon>

setAccessParameter(accessParameter, value)

Set a parameter of the query.

Name Type Description
accessParameter string

One of the access parameters ("topic", "property", "accessedObject", "concept", "user" etc)

value

The value of the parameter. The type (string etc.) depends on the parameter. Arrays of values can be passed, too. The value undefined or null disables the parametrized condition.

Throws:
Type Description
$k.exception.TypeError

When the value is not suitable for the parameter

setAlternatives(conditions)

Set the conditions as alternatives (OR group). If <= 1 conditions are passed this will be a no-op.

Name Type Description
conditions Array.<QueryCondition>

Conditions of this query that should be alternatives

Since:
  • 4.1.0
Deprecated
  • Use addAlternativeGroup() instead
    Throws:
    Type Description
    $k.exception.QueryError

    If the conditions cannot be alternatives of this query

    $k.exception.TypeError

    setInheritance(useInheritance)

    Set to false if elements of subdomains should not be returned

    Name Type Description
    useInheritance boolean
    Since:
    • 4.1.0

    setMergeCauses(mergeCauses)

    Determines whether causes should be merged when filtering hits

    Name Type Description
    mergeCauses boolean
    Version:
    • Experimental feature, might be removed at any time
    Since:
    • 5.3.0

    Intherited methods