coveo-search-ui
Version:
Coveo JavaScript Search Framework
2 lines • 6.22 kB
JavaScript
webpackJsonpCoveo__temporary([69],{295:function(e,t,r){"use strict";var n=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();Object.defineProperty(t,"__esModule",{value:!0}),r(702);var i=r(20),s=r(3),o=r(10),a=r(7),u=r(8),c=r(207),l=r(208),p=r(0),m=r(74),h=function(e){function t(r,n,i,s){var o=e.call(this,r,t.ID,i)||this;return o.element=r,o.options=n,o.result=s,o.options=u.ComponentOptions.initComponentOptions(r,t,n),o.addMissingTerms(),o}return n(t,e),Object.defineProperty(t.prototype,"allResultTerms",{get:function(){var e=this.result.absentTerms;return this.result.attachments&&(e=this.intersectAbsentTerms(e,this.result.attachments)),this.result.childResults&&(e=this.intersectAbsentTerms(e,this.result.childResults)),e},enumerable:!0,configurable:!0}),t.prototype.intersectAbsentTerms=function(e,t){return p.intersection.apply(void 0,[e].concat(t.map(function(e){return e.absentTerms})))},Object.defineProperty(t.prototype,"missingTerms",{get:function(){return this.absentTerms.concat(this.absentPhrases)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"absentTerms",{get:function(){for(var e=this,t=[],r=this.allResultTerms.filter(function(t){return!e.isMissingPhrase(t)}),n=0,i=r;n<i.length;n++){var s=i[n],o=this.queryMatch(s);o&&t.push(o)}return t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"absentPhrases",{get:function(){for(var e=this,t=[],r=this.allResultTerms.filter(function(t){return e.isMissingPhrase(t)}),n=0,i=r;n<i.length;n++){var s=i[n],o=s.slice(1,-1),a=this.queryMatch(o,!0);a&&t.push(a)}return t},enumerable:!0,configurable:!0}),t.prototype.isMissingPhrase=function(e){return m.Utils.stringStartsWith(e,'"')&&m.Utils.stringEndsWith(e,'"')},t.prototype.queryMatch=function(e,t){void 0===t&&(t=!1);var r=this.createWordBoundaryDelimitedRegex(e),n=this.queryStateModel.get("q"),i=t?n.replace(l(this.breakingCharacters,"gi")," "):n,s=r.exec(i);if(s){return s[4]}return null},t.prototype.addTermForcedToAppear=function(e){if(-1===this.missingTerms.indexOf(e))return void this.logger.warn('Method execution aborted because the term to inject in aq ("'+e+'") is not a missing term.',"Allowed missing terms: "+this.missingTerms.toString()+".");this.updateTermForcedToAppear(),this.termForcedToAppear.push(e),this.queryStateModel.set("missingTerms",this.termForcedToAppear.slice())},t.prototype.updateTermForcedToAppear=function(){this.termForcedToAppear=this.queryStateModel.get("missingTerms").slice()},t.prototype.addMissingTerms=function(){var e=this;if(0!==this.missingTerms.length){var t=this.buildContainer();t.length>1&&(this.hideMissingTermsOverTheNumberOfResults(t),t.map(function(t){i.$$(e.element).append(t)}))}},t.prototype.buildContainer=function(){var e=[];return e.push(this.buildCaption().el),this.buildMissingTerms().forEach(function(t){t&&e.push(t.el)}),e},t.prototype.buildCaption=function(){return i.$$("span",{className:"coveo-field-caption"},this.options.caption)},t.prototype.buildMissingTerms=function(){var e=this,t=this.absentTerms.filter(function(t){return e.isValidTerm(t)}),r=this.absentPhrases.filter(function(r){return e.isValidPhrase(r,t)});return t.concat(r).map(function(t){return e.makeTermClickableIfEnabled(t)})},t.prototype.executeNewQuery=function(e){void 0===e&&(e=this.queryStateModel.get("q")),this.queryController.executeQuery()},t.prototype.makeTermClickableIfEnabled=function(e){var t=this;if(this.options.clickable){var r=i.$$("button",{className:"coveo-missing-term coveo-clickable",type:"button"},e);return r.on("click",function(){t.addTermForcedToAppear(e),t.logAnalyticsAddMissingTerm(e),t.executeNewQuery(e)}),r}return i.$$("span",{className:"coveo-missing-term"},e)},t.prototype.createWordBoundaryDelimitedRegex=function(e){return l(c.MissingTermManager.wordBoundary+"("+e+")"+c.MissingTermManager.wordBoundary,"gi")},t.prototype.containsFeaturedResults=function(e){return this.updateTermForcedToAppear(),-1!==this.termForcedToAppear.indexOf(e)},t.prototype.hideMissingTermsOverTheNumberOfResults=function(e){var t=this,r=e.filter(function(e){return"BUTTON"===e.tagName});if(!(r.length<=this.options.numberOfTerms)){for(var n=this.options.numberOfTerms;n<r.length;n++)i.$$(r[n]).hide();var s=r.length-this.options.numberOfTerms,o=i.$$("button",{className:"coveo-missing-term-show-more coveo-clickable",type:"button"},i.l("NMore",[s]));o.on("click",function(){t.showAllHiddenMissingTerms()}),e.push(o.el)}},t.prototype.showAllHiddenMissingTerms=function(){var e=i.$$(this.element).find(".coveo-missing-term-show-more");e.parentNode.removeChild(e);for(var t=i.$$(this.element).findAll(".coveo-missing-term"),r=this.options.numberOfTerms;r<t.length;r++)i.$$(t[r]).show(),t[r].removeAttribute("style")},t.prototype.isValidTerm=function(e){return this.isNonBoundaryTerm(e)&&!this.containsFeaturedResults(e)},t.prototype.isValidPhrase=function(e,t){var r=this;return t.every(function(t){return!r.createWordBoundaryDelimitedRegex(t).exec(e)})},Object.defineProperty(t.prototype,"breakingCharacters",{get:function(){return"[-'?*’.~=,/\\\\:`;_!&()]+"},enumerable:!0,configurable:!0}),t.prototype.isNonBoundaryTerm=function(e){var t="\\p{L}*"+this.breakingCharacters+"\\p{L}*",r=l(t,"gi");return(this.queryStateModel.get("q").match(r)||[]).every(function(t){return-1===t.indexOf(e)})},t.prototype.logAnalyticsAddMissingTerm=function(e){this.usageAnalytics.logSearchEvent(o.analyticsActionCauseList.addMissingTerm,{missingTerm:e})},t.ID="MissingTerms",t.options={clickable:u.ComponentOptions.buildBooleanOption({defaultValue:!0}),caption:u.ComponentOptions.buildLocalizedStringOption({localizedString:function(){return i.l("Missing")}}),numberOfTerms:u.ComponentOptions.buildNumberOption({defaultValue:5,min:1})},t.doExport=function(){s.exportGlobally({MissingTerms:t})},t}(a.Component);t.MissingTerms=h,i.Initialization.registerAutoCreateComponent(h)},702:function(e,t){}});
//# sourceMappingURL=MissingTerms.min__cf4c4f4dd6c8a707e936.js.map