classMLSearchController
Source: controllers/
base search controller class; the prototype for an angular search controller
Note: this style requires you to use the controllerAs syntax.
(function() {
'use strict';
angular.module('app').controller('SearchCtrl', SearchCtrl);
SearchCtrl.$inject = ['$scope', '$location', 'MLSearchFactory'];
// inherit from MLSearchController
var superCtrl = MLSearchController.prototype;
SearchCtrl.prototype = Object.create(superCtrl);
function SearchCtrl($scope, $location, searchFactory) {
var ctrl = this;
var mlSearch = searchFactory.newContext();
MLSearchController.call(ctrl, $scope, $location, mlSearch);
// override a superCtrl method
ctrl.updateSearchResults = function updateSearchResults(data) {
superCtrl.updateSearchResults.apply(ctrl, arguments);
console.log('updated search results');
}
ctrl.init();
}
})();
Methods
new MLSearchController($scope, $location, mlSearch)
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
$scope |
Object |
|
child controller's scope |
|
$location |
Object |
|
angular's $location service |
|
mlSearch |
|
child controller's searchContext |
Properties
| Name | Type | Optional | Description |
|---|---|---|---|
|
$scope |
Object |
|
child controller's scope |
|
$location |
Object |
|
angular's $location service |
|
mlSearch |
|
child controller's searchContext |
|
|
searchPending |
Boolean |
|
signifies whether a search is in progress |
|
page |
Number |
|
the current results page |
|
qtext |
String |
|
the current query text |
|
response |
Object |
|
the search response object |
Methods
_search() → Promise
search implementation function
sets MLSearchController#searchPending to true, invokes MLSearchContext#search with MLSearchController#updateSearchResults as
the callback, and invokes MLSearchController#updateURLParams
- Returns
-
Promisethe promise from MLSearchContext#search
clearFacets() → Promise
clear all facet selections, and run a search
- Returns
-
Promisethe promise from MLSearchController#_search
init() → Promise
initialize the controller, setting the search state form URL params, and creating a handler for the $locationChangeSuccess event
- Returns
-
Promisethe promise from MLSearchContext#fromParams
locationChange(e, newUrl, oldUrl) → Promise
handle the $locationChangeSuccess event
checks if mlSearch URL params or additional params have changed (using the child controller's parseExtraURLParams() method, if available), and, if necessary, initiates a search via MLSearchController#_search
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
e |
Object |
|
the |
|
newUrl |
String |
|
|
|
oldUrl |
String |
|
- Returns
-
Promisethe promise from MLSearchContext#locationChange
parseExtraURLParams() → Boolean
UNIMPLEMENTED EXTENSION METHOD
implement to support extra URL params that can trigger a search;
should read extra URL params, and update the controller state
- Returns
-
Booleanshould a search be triggered
reset() → Promise
clear qtext, facet selections, boost queries, and additional queries. Then, run a search.
- Returns
-
Promisethe promise from MLSearchController#_search
search([qtext]) → Promise
the primary search method, for use with any user-triggered searches (for instance, from an input control)
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
qtext |
String |
Yes |
if present, updates the state of MLSearchController#qtext |
- Returns
-
Promisethe promise from MLSearchController#_search
showMoreFacets(facet, facetName[, step]) → Promise
Appends additional facet values to the provided facet object.
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
facet |
Object |
|
a facet object from MLSearchController#response |
|
facetName |
String |
|
facet name |
|
step |
Number |
Yes |
the number of additional facet values to retrieve (defaults to |
- Returns
-
Promisethe promise from MLSearchContext#showMoreFacets
suggest(qtext[, options]) → Promise
Gets search phrase suggestions based on the current state. This method can be passed directly to the ui-bootstrap typeahead directive.
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
-
Promisethe promise from MLSearchContext#suggest
toggleFacet(facetName, value) → Promise
toggle the selection state of the specified facet value
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
facetName |
String |
|
the name of the facet to toggle |
|
value |
String |
|
the value of the facet to toggle |
- Returns
-
Promisethe promise from MLSearchController#_search
toggleNegatedFacet(facetName, value) → Promise
toggle the selection state of the specified NEGATED facet value
Parameters
| Name | Type | Optional | Description |
|---|---|---|---|
|
facetName |
String |
|
the name of the NEGATED facet to toggle |
|
value |
String |
|
the value of the NEGATED facet to toggle |
- Returns
-
Promisethe promise from MLSearchController#_search
updateExtraURLParams()
UNIMPLEMENTED EXTENSION METHOD
implement to support additional URL params that can trigger a search;
should update extra URL params from the controller state
updateSearchResults(data) → MLSearchController
updates controller state with search results
sets MLSearchController#searchPending to true, sets MLSearchController#response, MLSearchController#qtext, and MLSearchController#page to values from the response
Parameter
| Name | Type | Optional | Description |
|---|---|---|---|
|
data |
Object |
|
the response from MLSearchContext#search |
- Returns
-
MLSearchControllerthis
updateURLParams() → MLSearchController
updates URL params based on the current MLSearchContext state, preserving any additional params. invokes the child controller's updateExtraURLParams() method, if available
- Returns
-
MLSearchControllerthis