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.
Classes
Methods
-
<static> getConfigurationDefinition()
-
Returns the MLJS Workplace Context Configuration definition JSON object
-
addErrorListener(fl)
-
Adds an error listener to this widget
Parameters:
Name Type Description flfunction The error listener to add
-
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 flfunction The Facet Listener to add
-
addResultsListener(rl)
-
Add a results listener.
Parameters:
Name Type Description rlfunction Results listener to add
-
addSortListener(sl)
-
Adds a sort listener to this widget.
Parameters:
Name Type Description slfunction The sort listener to add
-
contributeFacet(facetName, facetValue)
-
Contributes a facet selection to the underlying query (simple or structured).
Parameters:
Name Type Description facetNamestring The name of the facet to contribute a selection for
facetValuestring The value selection to contribute
-
contributeFacets(facetArray)
-
Contributes an array of facet selections to the underlying query (simple or structured).
Parameters:
Name Type Description facetArrayArray The facet values to restrict the search results by. [{name: "facetName", value: "facetValue"}, ... ]
-
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 contributorstring Unique name of the contributor (to prevent clashes)
queryTermjson | 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_optinteger The optional first result to show (defaults to 1)
-
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 searchHandlerfunction Your custom search handler function. Your function MUST invoke context.resultsPublisher, context.facetsPublisher and/or context.valuesPublisher.
-
deselectFacet(facetName, facetValue_opt)
-
Deselects the specified facet, or facet value pair
Parameters:
Name Type Description facetNamestring The name of the facet to deselect
facetValue_optstring The value to deselect. If undefined, all values of this facet are deselected.
-
doSimpleQuery(q, start)
-
Fires a simple query as specified, updating all listeners when the result is returned.
Parameters:
Name Type Description qstring The simple text query using the grammar in the search options
startinteger The start index (result number), starting at 1
-
doStructuredQuery(q, start)
-
Performs a structured query against this search context.
Parameters:
Name Type Description qjson The structured query JSON representation
startinteger The start index (result number), starting at 1
-
doSuggest(q, additional_properties_opt)
-
Fetches suggestions based on the currently used options and the specified query
Parameters:
Name Type Description qstring The partial query to suggest completion for
additional_properties_optjson Any extra properties. E.g. q, limit,cursor-position
-
getMetadataValue(result, fieldName)
-
Returns a single metadata field value for the specified result and field.
Parameters:
Name Type Description resultjson REST API single search result
fieldNamestring The field name to extract
-
getMetadataValues(result, fieldName)
-
Returns all metadata field values for the specified result and field.
Parameters:
Name Type Description resultjson REST API single search result
fieldNamestring The field name to extract values for
-
getOptions()
-
Returns the raw options JSON object.
-
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.
-
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 promobject Promise object with notify, resolve, reject
-
register(searchWidget)
-
Registers a search widget (visual or not) to this context.
Parameters:
Name Type Description searchWidgetobject The widget to register with this context. Will be introspected by this function.
-
removeErrorListener(fl)
-
Removes an error listener
Parameters:
Name Type Description flfunction The error listener to remove
-
removeFacetsListener(fl)
-
Removes a facet listener
Parameters:
Name Type Description flfunction The Facet Listener to remove
-
removeResultsListener(rl)
-
Remove a results listener
Parameters:
Name Type Description rlfunction The result listener function to remove.
-
removeSortListener(sl)
-
Removes a sort listener
Parameters:
Name Type Description slfunction The sort listener to remove
-
reset()
-
Resets the search bar input box. Resets all dependant search results/facets/pager/sorters too.
-
searchEndpoint()
-
Instructs this context to use the /v1/search endpoint, and thus the search() or structuredSearch() methods on MLJS
-
setCollection(col)
-
Sets the collection to restrict search results by on the fly. See GET /v1/search
Parameters:
Name Type Description colstring the collection name, or comma delimited collection names, to restrict the search results to
-
setConfiguration(config)
-
Sets the configuration of this context using the MLJS Workplace JSON format.
Parameters:
Name Type Description configJSON The JSON configuration of this context.
-
setConnection(connection)
-
Sets the underlying mljs connection to use
Parameters:
Name Type Description connectionmljs The mljs connection instance to use.
-
setDefaultQuery(defQuery)
-
Sets the default query. Should be set to non blank, E.g. "sort:relevance"
Parameters:
Name Type Description defQuerystring Default string query to use
-
setDirectory(dir)
-
Restricts search results by the directory a document is within. See GET /v1/search
Parameters:
Name Type Description dirstring Directory base uri
-
setFormat(format)
-
Sets the format to use. If not specified, defaults to json
Parameters:
Name Type Description formatstring The format to use (json or xml)
-
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 namestring The name of the options object to manage
optionsJSON 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)
-
setSortWord(word)
-
Specifies the sort word from the search options to use to sort the results on the next search
Parameters:
Name Type Description wordstring The sort option to use
-
setTransform(t)
-
Sets the name of the search transform to use. See GET /v1/search
Parameters:
Name Type Description tstring The transform name to use
-
setTransform(tps)
-
Sets the name of the search transform parameters to use. See GET /v1/search
Parameters:
Name Type Description tpsJSON The transform parameter JSON object {paramname: "value", ...} to use
-
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 facetSelectionArray The facet values to restrict the search results by. [{name: "facetName", value: "facetValue"}, ... ]
-
updateGeoHeatmap(constraint_name, heatmap)
-
Updates a geospatial searches heatmap configuration using the provided heatmap JSON configuration
Parameters:
Name Type Description constraint_namestring The name of the constraint whose heatmap should be changed
heatmapjson The REST API heatmap configuration
-
updateGeoSelection(selection)
-
Updates the selected area, be it a radius, polugon, or bounding box (or indeed empty - null)
Parameters:
Name Type Description selectionJSON 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}
-
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 resultSelectionjson The JSON object {mode: "append|replace", uri: "/some/uri"} for the selected document. Specifying null in replace mode clears the selection
-
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 jsonJSON JSON representing the start result and the number of results to return per page.
-
updateResults(msg)
-
Update all listeners' results with the provided search results
Parameters:
Name Type Description msgjson The results json (or true(result being refreshed) or false(results refresh failed) )
-
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 resultSelectionjson The JSON object {mode: "append|replace", uri: "/some/uri"} for the selected document. Specifying null in replace mode clears the selection
-
updateSort(sortSelection)
-
Event Target. Useful for linking to a search sorter. Updates the sort word and executes a search.
Parameters:
Name Type Description sortSelectionJSON The sort-order JSON object - E.g. {"json-key": year, direction: "ascending"}
-
valuesEndpoint(tuplesname)
-
Instructs this context to use the /v1/values endpoint, and thus the values() method on MLJS
Parameters:
Name Type Description tuplesnamestring The name of the tuple to fetch lexicon (or co-occurence) values for. Multiple tuples name arguments allowed (not as an array).