Property

new MLSearchContext(options)

Parameter

Name Type Optional Description

options

Object

 

provided object properties will override MLSearchContext.defaults

Properties

Name Type Optional Description

qb

MLQueryBuilder

 

query builder service from ml.common

results

Object

 

search results

storedOptions

Object

 

cache stored search options by name

activeFacets

Object

 

active facet selections

namespaces

Object

 

namespace prefix-to-URI mappings

boostQueries

Array of Object

 

boosting queries to be added to the current query

additionalQueries

Array of Object

 

additional queries to be added to the current query

searchTransform

String

 

search results transformation name

qtext

String

 

current search phrase

start

Number

 

current pagination offset

options

Object

 

configuration options

Property

static
defaults  object

pass an object to new MLSearchContext() or MLSearchFactory#newContext with any of these properties to override their values

Properties

Name Type Optional Description

defaults.queryOptions

String

 

stored search options name ('all')

defaults.suggestOptions

String

 

stored search options name for suggestions (same as queryOptions)

defaults.pageLength

Number

 

results page length (10)

defaults.snippet

String

 

results transform operator state-name ('compact')

defaults.sort

String

 

sort operator state-name (null)

defaults.facetMode

String

 

determines if facets are combined in an and-query or an or-query (and)

defaults.includeProperties

Boolean

 

include document properties in queries (false)

defaults.includeAggregates

Boolean

 

automatically get aggregates for facets (false)

defaults.params

Object

 

URL params settings

Values in defaults.params have the following properties:

Name Type Optional Description

separator

String

 

constraint-name and value separator (':')

qtext

String

 

qtext parameter name ('qtext')

facets

String

 

facets parameter name ('f')

sort

String

 

sort parameter name ('s')

page

String

 

page parameter name ('p')

prefix

String

 

optional string prefix for each parameter name (null)

prefixSeparator

String

 

separator for prefix and parameter name. (null)
if null, options.params.separator is used as the prefix separator

Methods

addAdditionalQuery(query) → MLSearchContext

Adds an additional query to this.additionalQueries

Parameter

Name Type Optional Description

query

Object

 

additional query

Returns

MLSearchContext this

addBoostQuery(query) → MLSearchContext

Adds a boost query to this.boostQueries

Parameter

Name Type Optional Description

query

Object

 

boost query

Returns

MLSearchContext this

addNamespace(namespace) → MLSearchContext

Adds a namespace prefix->URI mapping

Parameter

Name Type Optional Description

namespace

Object

 

object with uri and prefix properties

Returns

MLSearchContext this

annotateActiveFacets(facets)

Annotates facets (from a search response object) with the selections from this.activeFacets

Parameter

Name Type Optional Description

facets

Object

 

facets object from a search response

clearAdditionalQueries() → MLSearchContext

Clears the additional queries

Returns

MLSearchContext this

clearAllFacets() → MLSearchContext

Clears the activeFacets list

Returns

MLSearchContext this

clearBoostQueries() → MLSearchContext

Clears the boost queries

Returns

MLSearchContext this

clearFacet(name, value) → MLSearchContext

Removes the facet/value combination from the activeFacets list

Parameters

Name Type Optional Description

name

String

 

facet name

value

String

 

facet value

Returns

MLSearchContext this

clearNamespaces() → MLSearchContext

Clears namespace prefix->URI mappings

Returns

MLSearchContext this

clearSnippet() → MLSearchContext

Clears the results transform operator (resets it to its default value)

Returns

MLSearchContext this

clearSort() → MLSearchContext

Clears the sort operator state name (resets it to its default value)

Returns

MLSearchContext this

fromParams([params]) → Promise

Updates the current state based on the URL query params

Parameter

Name Type Optional Description

params

Object

Yes

a URL query params object (defaults to $location.search())

Returns

Promise a promise resolved once the params have been applied

getActiveFacets() → Object

Gets the object repesenting active facet selections

Returns

Object this.activeFacets

getAdditionalQueries() → Object

Gets the additional queries

Returns

Object this.additionalQueries

getAggregates(facets) → Promise

Gets aggregates for facets (from a search response object) based on facet type

Parameter

Name Type Optional Description

facets

Object

 

facets object from a search response

Returns

Promise a promise resolved once facet aggregates have been retrieved

getAllStoredOptions(names) → Promise

Retrieves stored search options, caching the result in this.storedOptions

Parameter

Name Type Optional Description

names

Array of String

 

the names of the options to retrieve

Returns

Promise a promise resolved with an object containing the requested search options, keyed by name

getBoostQueries() → Array

Gets the boost queries

Returns

Array this.boostQueries

getCombinedQuery([includeOptions]) → Promise

Construct a combined query from the current state

Parameter

Name Type Optional Description

includeOptions

Boolean

Yes

if true, get and include the stored search options (defaults to false)

Returns

Promise - a promise resolved with the combined query

getCombinedQuerySync([options]) → Object

Construct a combined query from the current state (excluding stored options)

Parameter

Name Type Optional Description

options

Object

Yes

optional search options object

Returns

Object - combined query

getCurrentParams([params]) → Object

Gets the current search related URL params (excluding any params not controlled by MLSearchContext)

Parameter

Name Type Optional Description

params

Object

Yes

URL params (defaults to $location.search())

Returns

Object search-related URL params

getFacetMode() → String

Gets the current facet mode (determines if facet values are combined in an and-query or an or-query)

Returns

String facet mode

getFacetParams() → Array of String

Construct an array of facet selections (name separator value) from this.activeFacets for use in a URL query params object

Returns

Array of String an array of facet URL query param values

getFacetQuery() → Object

constructs a structured query from the current active facets

Returns

Object a structured query object

getNamespacePrefix(uri) → String

Get namspace prefix by URI

Parameter

Name Type Optional Description

uri

String

 

Returns

String prefix

getNamespaces() → Array of Object

Gets namespace prefix-to-URI mappings

Returns

Array of Object namespace prefix-to-URI mapping objects

getNamespaceUri(prefix) → String

Get namspace URI by prefix

Parameter

Name Type Optional Description

prefix

String

 

Returns

String uri

getPage() → Number

Gets the current search page

Returns

Number search page

getPageLength() → Number

Gets the current page length

Returns

Number page length

getParams() → Object

Construct a URL query params object from the current state

Returns

Object params - a URL query params object

getParamsConfig() → Object

Gets the current URL params config object

Returns

Object params config

getParamsKeys() → Array of String

Gets the key of the enabled URL params

Returns

Array of String URL params keys

getParamsPrefix() → String

Gets the URL params prefix

Returns

String the defined params prefix + separator

getQuery() → Object

Constructs a structured query from the current state

Returns

Object a structured query object

getQueryOptions() → String

Gets the current queryOptions (name of stored params)

Returns

String queryOptions

getSnippet() → String

Gets the current results transform operator state name

Returns

String operator state name

getSort() → String

Gets the current sort operator state name

Returns

String sort operator state name

getStoredOptions([name]) → Promise

Retrieves stored search options, caching the result in this.storedOptions

Parameter

Name Type Optional Description

name

String

Yes

the name of the options to retrieve (defaults to this.getQueryOptions())

Returns

Promise a promise resolved with the stored options

getStructuredQuery()

Deprecated
See also
MLSearchContext#getQuery

getSuggestOptions() → String

Gets the current suggestOptions (name of stored params for suggestions)

Returns

String suggestOptions

getText() → String

Gets the current search phrase

Returns

String search phrase

getTransform() → String

Gets the search transform name

Returns

String transform name

isFacetActive(name, value) → Boolean

Check if the facet/value combination is already selected

Parameters

Name Type Optional Description

name

String

 

facet name

value

String

 

facet value

Returns

Boolean isSelected

isFacetNegated(name, value) → Boolean

Check if the facet/value combination selected & negated

Parameters

Name Type Optional Description

name

String

 

facet name

value

String

 

facet value

Returns

Boolean isNegated

locationChange(newUrl, oldUrl, params) → Promise

Examines the current state, and determines if a new search is needed. (intended to be triggered on $locationChangeSuccess)

Parameters

Name Type Optional Description

newUrl

String

 

the target URL of a location change

oldUrl

String

 

the original URL of a location change

params

Object

 

the search params of the target URL

Returns

Promise a promise resolved after calling MLSearchContext#fromParams (if a new search is needed)

Retrieves search results based on the current state

If an object is passed as the adhoc parameter, the search will be run as a POST with a combined query, and the results will not be saved to MLSearchContext.results.

Parameter

Name Type Optional Description

adhoc

Object

Yes

structured query || combined query || partial search options object

Returns

Promise a promise resolved with search results

selectFacet(name, value, type, isNegated) → MLSearchContext

Add the facet/value/type combination to the activeFacets list

Parameters

Name Type Optional Description

name

String

 

facet name

value

String

 

facet value

type

String

 

facet type

isNegated

Boolean

 

facet negated (default to false)

Returns

MLSearchContext this

serializeStructuredQuery()

Deprecated
See also
MLSearchContext#getParams

setFacetMode(facetMode) → MLSearchContext

Sets the current facet mode (and|or). (determines if facet values are combined in an and-query or an or-query)

Parameter

Name Type Optional Description

facetMode

String

 

'and' or 'or'

Returns

MLSearchContext this

setNamespaces(namespaces) → MLSearchContext

Sets namespace prefix->URI mappings

Parameter

Name Type Optional Description

namespaces

Array of Object

 

objects with uri and prefix properties

Returns

MLSearchContext this

setPage(page) → MLSearchContext

Sets the search results page

Parameter

Name Type Optional Description

page

Number

 

the desired search results page

Returns

MLSearchContext this

setPageLength(pageLength) → MLSearchContext

Sets the current page length

Parameter

Name Type Optional Description

pageLength

Number

 

page length

Returns

MLSearchContext this

setSnippet(snippet) → MLSearchContext

Sets the current results transform operator state name

Parameter

Name Type Optional Description

snippet

String

 

operator state name

Returns

MLSearchContext this

setSort(sort) → MLSearchContext

Sets the current sort operator state name

Parameter

Name Type Optional Description

sort

String

 

sort operator state name

Returns

MLSearchContext this

setText(text) → MLSearchContext

Sets the current search phrase

Parameter

Name Type Optional Description

text

String

 

search phrase

Returns

MLSearchContext this

setTransform(transform) → MLSearchContext

Sets the search transform name

Parameter

Name Type Optional Description

transform

String

 

transform name

Returns

MLSearchContext this

showMoreFacets(facet, facetName[, step]) → Promise

Retrieve additional values for the provided facet object, appending them to the facet's facetValues array. Sets facet.displayingAll = true once no more values are available.

Parameters

Name Type Optional Description

facet

Object

 

a facet object returned from MLSearchContext#search

facetName

String

 

facet name

step

Number

Yes

the number of additional facet values to retrieve (defaults to 5)

Returns

Promise a promise resolved once additional facets have been retrieved

suggest(qtext[, options]) → Promise

Retrieves search phrase suggestions based on the current state

Parameters

Name Type Optional Description

qtext

String

 

the partial-phrase to match

options

(String or Object)

Yes

string options name (to override suggestOptions), or object for adhoc combined query options

Returns

Promise a promise resolved with search phrase suggestions

toggleFacet(name, value, isNegated) → MLSearchContext

If facet/value combination is active, remove it from the activeFacets list otherwise, find it's type, and add it.

Parameters

Name Type Optional Description

name

String

 

facet name

value

String

 

facet value

isNegated

Boolean

 

facet negated

Returns

MLSearchContext this

transformMetadata(result)

Transforms the metadata array in each search response result object to an object, key'd by metadata-type

Parameter

Name Type Optional Description

result

Object

 

results array from a search response (or one result object from the array)

values(name[, params][, options]) → Promise

Retrieves values or tuples from 1-or-more lexicons

Parameters

Name Type Optional Description

name

String

 

the name of a value-option definition

params

Object

Yes

URL params

options

Object

Yes

search options, used in a combined query

Returns

Promise a promise resolved with values

valuesFromConstraint(name[, params]) → Promise

Retrieves values from a lexicon (based on a constraint definition)

Parameters

Name Type Optional Description

name

String

 

the name of a search constraint definition

params

Object

Yes

URL params

Returns

Promise a promise resolved with values