diff --git a/factories/docFactory.js b/factories/docFactory.js index 2be4e82..4c2cea8 100644 --- a/factories/docFactory.js +++ b/factories/docFactory.js @@ -8,55 +8,65 @@ function DocFactory() { var Doc = function(doc, opts) { - var self = this; - + var self = this; angular.copy(doc, self); + self.doc = doc; + self.opts = opts; + }; - self.doc = doc; - - self.groupedBy = groupedBy; - self.group = group; - self.options = options; - self.version = version; - self.fieldsAttrName = fieldsAttrName; - self.fieldsProperty = fieldsProperty; + Doc.prototype = {}; + Doc.prototype.groupedBy = groupedBy; + Doc.prototype.group = group; + Doc.prototype.options = options; + Doc.prototype.version = version; + Doc.prototype.fieldsAttrName = fieldsAttrName; + Doc.prototype.fieldsProperty = fieldsProperty; - function groupedBy () { - if (opts.groupedBy === undefined) { - return null; - } else { - return opts.groupedBy; - } + function groupedBy() { + /*jslint validthis:true*/ + var self = this; + if (this.opts.groupedBy === undefined) { + return null; + } else { + return this.opts.groupedBy; } + } - function options() { - return opts; - } + function options() { + /*jslint validthis:true*/ + var self = this; + return this.opts; + } - function group () { - if (opts.group === undefined) { - return null; - } else { - return opts.group; - } + function group() { + /*jslint validthis:true*/ + var self = this; + if (this.opts.group === undefined) { + return null; + } else { + return this.opts.group; } + } - function version () { - if (opts.version === undefined) { - return null; - } else { - return opts.version; - } + function version() { + /*jslint validthis:true*/ + var self = this; + if (this.opts.version === undefined) { + return null; + } else { + return this.opts.version; } + } - function fieldsAttrName() { - return '_source'; - } + function fieldsAttrName() { + return '_source'; + } - function fieldsProperty() { - return self[self.fieldsAttrName()]; - } - }; + function fieldsProperty() { + /*jslint validthis:true*/ + var self = this; + return self[self.fieldsAttrName()]; + } // Return factory object return Doc; diff --git a/factories/esDocFactory.js b/factories/esDocFactory.js index 25f90e7..d34f5a6 100644 --- a/factories/esDocFactory.js +++ b/factories/esDocFactory.js @@ -33,11 +33,12 @@ Doc.prototype = Object.create(DocFactory.prototype); Doc.prototype.constructor = Doc; // Reset the constructor - Doc.prototype._url = _url; - Doc.prototype.explain = explain; - Doc.prototype.snippet = snippet; - Doc.prototype.origin = origin; - Doc.prototype.highlight = highlight; + Doc.prototype._url = _url; + Doc.prototype.fieldsProperty = fieldsProperty; + Doc.prototype.explain = explain; + Doc.prototype.snippet = snippet; + Doc.prototype.origin = origin; + Doc.prototype.highlight = highlight; function _url () { /*jslint validthis:true*/ @@ -49,6 +50,12 @@ return esUrlSvc.buildDocUrl(uri, doc); } + function fieldsProperty() { + /*jslint validthis:true*/ + var self = this; + return Object.assign({}, self['_source'], self['fields']); + } + function explain () { /*jslint validthis:true*/ var self = this; diff --git a/services/esSearcherPreprocessorSvc.js b/services/esSearcherPreprocessorSvc.js index f5eaa44..253c17f 100644 --- a/services/esSearcherPreprocessorSvc.js +++ b/services/esSearcherPreprocessorSvc.js @@ -101,10 +101,6 @@ angular.module('o19s.splainer-search') } }; - var setFieldsParamName = function() { - self.fieldsParamNames = [ '_source']; - }; - function prepare (searcher) { if (searcher.config === undefined) { searcher.config = defaultESConfig; @@ -114,8 +110,6 @@ angular.module('o19s.splainer-search') searcher.config = angular.merge({}, defaultESConfig, searcher.config); } - setFieldsParamName(searcher); - if ( searcher.config.apiMethod === 'post') { preparePostRequest(searcher); } else if ( searcher.config.apiMethod === 'get') {