Class: searchcontext

mljs# searchcontext

new searchcontext()

A Search Context links together any objects affecting the query, sorting, facets or that wants to be notified of changes to those, and to any new results or pages being retrieved.

Defaults to operating against the /v1/search endpoint, but can be changed to operate against the /v1/values endpoint, depending on need.

Deprecated:
  • Use var db = new mljs(); db.createSearchContext(); instead
    Source:

    Classes

    defaultparser

    Methods

    <static> getConfigurationDefinition()

    Returns the MLJS Workplace Context Configuration definition JSON object

    Source:

    addErrorListener(fl)

    Adds an error listener to this widget

    Parameters:
    Name Type Description
    fl function

    The error listener to add

    Source:

    addFacetsListener(fl)

    Adds a facet listener to this widget. Normally you'd use a results listener instead in order to get more context.

    Parameters:
    Name Type Description
    fl function

    The Facet Listener to add

    Source:

    addResultsListener(rl)

    Add a results listener.

    Parameters:
    Name Type Description
    rl function

    Results listener to add

    Source:

    addSortListener(sl)

    Adds a sort listener to this widget.

    Parameters:
    Name Type Description
    sl function

    The sort listener to add

    Source:

    contributeFacet(facetName, facetValue)

    Contributes a facet selection to the underlying query (simple or structured).

    Parameters:
    Name Type Description
    facetName string

    The name of the facet to contribute a selection for

    facetValue string

    The value selection to contribute

    Source:

    contributeFacets(facetArray)

    Contributes an array of facet selections to the underlying query (simple or structured).

    Parameters:
    Name Type Description
    facetArray Array

    The facet values to restrict the search results by. [{name: "facetName", value: "facetValue"}, ... ]

    Source:

    contributeStructuredQuery(contributor, queryTerm, start_opt)

    For situations where many objects are contributing top level structured query terms that need AND-ing together.

    NOTE: queryTerm needs to be the result of queryBuilder.toJson().query[0] and not the top level query JSON itself - i.e. we need a term, not a full query object.

    Parameters:
    Name Type Description
    contributor string

    Unique name of the contributor (to prevent clashes)

    queryTerm json | text

    The query JSON for the REST API (E.g. an and-query instance). If text this function will do a combined query (V7) or add as a term query (V6)

    start_opt integer

    The optional first result to show (defaults to 1)

    Source:

    customEndpoint(searchHandler)

    Instructs this search context to use your own custom search handler. Useful if you have created your own REST endpoint to handle searching on the server. Use the mljs.do method in your searchHandler function to invoke your extension.

    Note your function must have the signature: function(searchcontext,textQuery,structuredQueryJson,optionsName,startIndex,additionalSearchPropertiesJson) See the tutorials on Github for one with a custom search context search function.

    Parameters:
    Name Type Description
    searchHandler function

    Your custom search handler function. Your function MUST invoke context.resultsPublisher, context.facetsPublisher and/or context.valuesPublisher.

    Source:

    deselectFacet(facetName, facetValue_opt)

    Deselects the specified facet, or facet value pair

    Parameters:
    Name Type Description
    facetName string

    The name of the facet to deselect

    facetValue_opt string

    The value to deselect. If undefined, all values of this facet are deselected.

    Source:

    doSimpleQuery(q, start)

    Fires a simple query as specified, updating all listeners when the result is returned.

    Parameters:
    Name Type Description
    q string

    The simple text query using the grammar in the search options

    start integer

    The start index (result number), starting at 1

    Source:

    doStructuredQuery(q, start)

    Performs a structured query against this search context.

    Parameters:
    Name Type Description
    q json

    The structured query JSON representation

    start integer

    The start index (result number), starting at 1

    Source:

    doSuggest(q, additional_properties_opt)

    Fetches suggestions based on the currently used options and the specified query

    Parameters:
    Name Type Description
    q string

    The partial query to suggest completion for

    additional_properties_opt json

    Any extra properties. E.g. q, limit,cursor-position

    Source:

    getMetadataValue(result, fieldName)

    Returns a single metadata field value for the specified result and field.

    Parameters:
    Name Type Description
    result json

    REST API single search result

    fieldName string

    The field name to extract

    Source:

    getMetadataValues(result, fieldName)

    Returns all metadata field values for the specified result and field.

    Parameters:
    Name Type Description
    result json

    REST API single search result

    fieldName string

    The field name to extract values for

    Source:

    getOptions()

    Returns the raw options JSON object.

    Source:

    getOptionsBuilder()

    If setOptions was passed an options builder instance instead of a JSON REST API options object, this function will return the options builder object. This is useful when you want to introspect the options. E.g. to translate facet values to human readable text.

    Source:

    promise(prom)

    Generate a promise for use with frameworks like Angular JS. This method should be called prior to any individual method that fires a search from a context. Note: Caller MUST use the object returned by this function, which is a proxy for the underlying search context, rather than call this method then another on the search context. I.e. use chaining like sc.promise().doStructuredQuery(...)

    Parameters:
    Name Type Description
    prom object

    Promise object with notify, resolve, reject

    Source:
    See:

    register(searchWidget)

    Registers a search widget (visual or not) to this context.

    Parameters:
    Name Type Description
    searchWidget object

    The widget to register with this context. Will be introspected by this function.

    Source:

    removeErrorListener(fl)

    Removes an error listener

    Parameters:
    Name Type Description
    fl function

    The error listener to remove

    Source:

    removeFacetsListener(fl)

    Removes a facet listener

    Parameters:
    Name Type Description
    fl function

    The Facet Listener to remove

    Source:

    removeResultsListener(rl)

    Remove a results listener

    Parameters:
    Name Type Description
    rl function

    The result listener function to remove.

    Source:

    removeSortListener(sl)

    Removes a sort listener

    Parameters:
    Name Type Description
    sl function

    The sort listener to remove

    Source:

    reset()

    Resets the search bar input box. Resets all dependant search results/facets/pager/sorters too.

    Source:

    searchEndpoint()

    Instructs this context to use the /v1/search endpoint, and thus the search() or structuredSearch() methods on MLJS

    Source:

    setCollection(col)

    Sets the collection to restrict search results by on the fly. See GET /v1/search

    Parameters:
    Name Type Description
    col string

    the collection name, or comma delimited collection names, to restrict the search results to

    Source:

    setConfiguration(config)

    Sets the configuration of this context using the MLJS Workplace JSON format.

    Parameters:
    Name Type Description
    config JSON

    The JSON configuration of this context.

    Source:

    setConnection(connection)

    Sets the underlying mljs connection to use

    Parameters:
    Name Type Description
    connection mljs

    The mljs connection instance to use.

    Source:

    setDefaultQuery(defQuery)

    Sets the default query. Should be set to non blank, E.g. "sort:relevance"

    Parameters:
    Name Type Description
    defQuery string

    Default string query to use

    Source:

    setDirectory(dir)

    Restricts search results by the directory a document is within. See GET /v1/search

    Parameters:
    Name Type Description
    dir string

    Directory base uri

    Source:

    setFormat(format)

    Sets the format to use. If not specified, defaults to json

    Parameters:
    Name Type Description
    format string

    The format to use (json or xml)

    Source:

    setOptions(name, options)

    Sets to options object to use. By default on V6 this will be persisted to the server. In V7 this will be passed on the fly to MarkLogic.

    Parameters:
    Name Type Description
    name string

    The name of the options object to manage

    options JSON

    The REST API JSON search options object to use, or the MLJS search options builder object. (For caching for later modification or introspection. E.g. to use for translating facet values to human readable text)

    Source:

    setSortWord(word)

    Specifies the sort word from the search options to use to sort the results on the next search

    Parameters:
    Name Type Description
    word string

    The sort option to use

    Source:

    setTransform(t)

    Sets the name of the search transform to use. See GET /v1/search

    Parameters:
    Name Type Description
    t string

    The transform name to use

    Source:

    setTransform(tps)

    Sets the name of the search transform parameters to use. See GET /v1/search

    Parameters:
    Name Type Description
    tps JSON

    The transform parameter JSON object {paramname: "value", ...} to use

    Source:

    updateFacets(facetSelection)

    Event target. Useful to call directly from a Search Facets widget upon selection of a facet value. Executes a new search.

    Parameters:
    Name Type Description
    facetSelection Array

    The facet values to restrict the search results by. [{name: "facetName", value: "facetValue"}, ... ]

    Source:

    updateGeoHeatmap(constraint_name, heatmap)

    Updates a geospatial searches heatmap configuration using the provided heatmap JSON configuration

    Parameters:
    Name Type Description
    constraint_name string

    The name of the constraint whose heatmap should be changed

    heatmap json

    The REST API heatmap configuration

    Source:

    updateGeoSelection(selection)

    Updates the selected area, be it a radius, polugon, or bounding box (or indeed empty - null)

    Parameters:
    Name Type Description
    selection JSON

    The JSON area selection object {contributor: "somename", type: "circle|polygon|box|null", "constraint_name": "name", box: {north:, south: , east:, west:}, polygon: polygon-config, latitude: ,longitude: , radiusmiles: , heatmap: heatmap-json}

    Source:

    updateHighlight(resultSelection)

    Highlight the document specified. Depending upon the highlight mode (append or replace) this will either add the document to the selection, or replace the selection with this document. Useful for selecting multiple search results over time (e.g. between pages of results).

    Fires an updateSelection event on selection listeners. (Only if the URI is not already selected)

    Parameters:
    Name Type Description
    resultSelection json

    The JSON object {mode: "append|replace", uri: "/some/uri"} for the selected document. Specifying null in replace mode clears the selection

    Source:

    updatePage(json)

    Event target. Useful to call directly from a search pager widget. Executes a new search json = {show: number, start: number}

    Parameters:
    Name Type Description
    json JSON

    JSON representing the start result and the number of results to return per page.

    Source:

    updateResults(msg)

    Update all listeners' results with the provided search results

    Parameters:
    Name Type Description
    msg json

    The results json (or true(result being refreshed) or false(results refresh failed) )

    Source:

    updateSelection(resultSelection)

    Select the document specified. Depending upon the selection mode (append or replace) this will either add the document to the selection, or replace the selection with this document. Useful for selecting multiple search results over time (e.g. between pages of results).

    Fires an updateSelection event on selection listeners. (Only if the URI is not already selected)

    Parameters:
    Name Type Description
    resultSelection json

    The JSON object {mode: "append|replace", uri: "/some/uri"} for the selected document. Specifying null in replace mode clears the selection

    Source:

    updateSort(sortSelection)

    Event Target. Useful for linking to a search sorter. Updates the sort word and executes a search.

    Parameters:
    Name Type Description
    sortSelection JSON

    The sort-order JSON object - E.g. {"json-key": year, direction: "ascending"}

    Source:

    valuesEndpoint(tuplesname)

    Instructs this context to use the /v1/values endpoint, and thus the values() method on MLJS

    Parameters:
    Name Type Description
    tuplesname string

    The name of the tuple to fetch lexicon (or co-occurence) values for. Multiple tuples name arguments allowed (not as an array).

    Source:
    MLJS - A JavaScript wrapper for the MarkLogic REST API
    MarkLogic 2012-2014
    Documentation generated by JSDoc 3.2.3-dev on Mon Jul 18 2016 09:14:12 GMT+0100 (BST) using the DocStrap template.