-
Notifications
You must be signed in to change notification settings - Fork 10
Description
In a couple demos, I have wanted to perform a temporary search expansion that does not have any side effects (like adding additional constraints or qtext in the UI). Both are semantic search extensions. In one case, I wanted to expand the qtext with shotgun 'or'; in another, I want to add additional json-property constraints with a shotgun 'or'.
In both cases, I changed ml-search-ng.js, but I think we could support this kind of use-case with a hook in mlSearch.search(): just before calling mlRest.search(), call a user-defined function if it exists. So, right here we could add code like:
if ( manipulateParams ) {
params = manipulateParams(params);
}The user could pass their custom manipulation function into mlSearch.search as an optional parameter, in the search controller:
function expandQuery(searchParams) {
console.log('now I can manipulate the searchParams for expansion or whatever');
return searchParams;
}
ctrl._search = function() {
this.searchPending = true;
var promise;
if (ctrl.shouldExpand) {
promise = this.mlSearch.search(null, expandQuery);
} else {
promise = this.mlSearch.search();
}
this.updateURLParams();
return promise.then( this.updateSearchResults.bind(this) );
};Or, if want to make it easier, without requiring ctrl._search to be rewritten, mlSearch could have a setter function for the param-manipulation function. But that would then require the user to remove the manipulation in case they don't want it, so not sure which is better.
Also, I don't really understand if this would interact with the combined part of mlSearch.search.