@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
62 lines (48 loc) • 1.82 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
import SearchDocument from './SearchDocument';
import SignalData from './SignalData';
import FetchUtils from '../util/FetchUtils';
/**
* Encapsulates the default Attivio search behavior.
*/
var Signals = function () {
/**
* Construct a Signals object.
*
* @param baseUri the base URI for the Attivio instance to call when searching
* (including the protocol, hostname or IP address, and port number,
* with no trailing slash)
*/
function Signals(baseUri) {
_classCallCheck(this, Signals);
this.baseUri = baseUri;
}
/**
* Add a signal for the given document. If the document has no signal information
* inside it, this method does nothing.
*/
Signals.prototype.addSignal = function addSignal(doc) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'click';
var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
if (doc.signal) {
var updatedSignal = SignalData.fromJson(Object.assign({}, doc.signal, { type: type, weight: weight }));
this.addRawSignal(updatedSignal);
}
};
/**
* Add a signal for the given SignalData.
*/
Signals.prototype.addRawSignal = function addRawSignal(signal) {
if (signal) {
var uri = this.baseUri + '/rest/signals/add';
var callback = function callback(response, error) {
if (error) {
console.warn('Failed to submit signal', signal, error);
}
};
FetchUtils.fetch(uri, signal, callback, 'POST', 'Failed to submit signal');
}
};
return Signals;
}();
export { Signals as default };