$k. Hit

new Hit(semanticElement, quality)

Creates a new hit

Parameters:
NameTypeDescription
semanticElement$k.SemanticElement

Semantic element of the hit

qualitynumber

Quality of the hit. If undefined, 1 will be set as quality

Throws:
  • If the quality is not between 0 and 1

    Type
    $k.exception.InvalidValue
  • If the argument is not a semantic element

    Provides details about a topic returned by a query. Each hit has a quality between 0 (worst quality) and 1 (best quality). Additional details are attached as causes.

    Type
    $k.exception.TypeError

Methods

(static) unwrap(hits) → {Array.<$k.SemanticElement>}

Map each hit to a semantic element. Equivalent to (but much faster than)

hits.map(function(h) { return h.element())
Parameters:
NameTypeDescription
hitsArray.<$k.Hit>

Hits. Elements are accepted, too (returns the element itself).

Since
  • 5.3.1
Returns:
Type: 
Array.<$k.SemanticElement>

(static) wrap(elements, qualityopt) → {Array.<$k.Hit>}

Map each element to a hit. Equivalent to (but much faster than)

elements.map(function(e) { return new $k.Hit(e, q) })
Parameters:
NameTypeAttributesDescription
elementsArray.<$k.SemanticElement>

Element. Hits are accepted, too (returns the hit itself).

qualitynumber<optional>

Quality of each hit

Since
  • 5.3.1
Returns:
Type: 
Array.<$k.Hit>

addCause(cause)

Add a cause

Parameters:
NameTypeDescription
cause$k.Cause

attributeType() → {$k.AttributeType}

Returns the attribute type of the hit

Since
  • 5.2.2
Returns:
Type: 
$k.AttributeType

causeOfType() → {Array.<$k.Cause>}

Returns the cause of this hit with the given type, or undefined if no or more than one cause exists

Returns:
Type: 
Array.<$k.Cause>

causePropertyElements(propertyKeysopt) → {Array.<$k.SemanticElement>}

Returns the elements of all properties matching the given property-keys of all (custom-) causes of this hit

Parameters:
NameTypeAttributesDescription
propertyKeysArray.<string><optional>

property keys

Since
  • 5.3.0
Returns:
Type: 
Array.<$k.SemanticElement>

causes() → {Array.<$k.Cause>}

Returns the causes of this hit

Returns:
Type: 
Array.<$k.Cause>

causesOfType() → {Array.<$k.Cause>}

Returns the causes of this hit with the given type

Returns:
Type: 
Array.<$k.Cause>

element() → {$k.SemanticElement}

The semantic element associated with this hit

Since
  • 4.3.0
Returns:
Type: 
$k.SemanticElement

language() → {string}

Returns the language of the hit for translated attributes, or undefined if not translated

Since
  • 5.2.2
Returns:
Type: 
string

quality() → {number}

Returns the quality of the hit, a number between 0 (worst quality) and 1 (best quality)

Returns:
Type: 
number

setElement(semanticElement)

Set the semantic element associated with this hit

Parameters:
NameTypeDescription
semanticElement$k.SemanticElement

Semantic element of the hit

Throws:

If the argument is not a semantic element

Type
$k.exception.TypeError

setQuality(quality)

Set the quality, a number between 0 and 1

Parameters:
NameTypeDescription
qualitynumber
Throws:

If the quality is not between 0 and 1

Type
$k.exception.InvalidValue

snippet(startTag, endTag, maxFragmentLength, maxFragments, fragmentSeparator, maxDocCharsToAnalyze) → {String}

Returns a snippet of the content which contains the matching term(s)

Parameters:
NameTypeDescription
startTagstring

Text which should be inserted before matching terms in the snippet.

endTagstring

Text which should be inserted before matching terms in the snippet

maxFragmentLengthnumber

Maximum length of a text fragment in the snippet excluding start and end tags

maxFragmentsnumber

Maximum number of text fragements in a snippet

fragmentSeparatorstring

Separator

maxDocCharsToAnalyzestring

Maximum text length for snippet search

Since
  • 4.4.0
Returns:
Type: 
String