(window.webpackJsonp=window.webpackJsonp||[]).push([[50],{562:function(e,r,t){"use strict";t.r(r),t.d(r,"SearchAdapter",(function(){return j}));var n=t(0),o=t(782),s=t(10),i=t(1);function u(){if(!i.elasticsearch.hasOwnProperty("searchScoring"))return!1;var e,r,t,n=[],o=i.elasticsearch.searchScoring.attributes;if(!Object.keys(o).length)return!1;for(var s=0,u=Object.keys(o);s<u.length;s++)for(var a=u[s],c=0,l=Object.keys(o[a].scoreValues);c<l.length;c++){var h=l[c],f={filter:{match:(e={},r=a,t=h,r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e)},weight:o[a].scoreValues[h].weight};n.push(f)}return!!n.length&&{functions:n,score_mode:i.score_mode?i.score_mode:"multiply",boost_mode:i.boost_mode?i.boost_mode:"multiply",max_boost:i.max_boost?i.max_boost:100,min_score:i.function_min_score?i.function_min_score:1}}function a(e){return function(e){var r=i.elasticsearch.hasOwnProperty("searchScoring")?i.elasticsearch.searchScoring:{},t=r.hasOwnProperty("minimum_should_match")?r.minimum_should_match:"75%";"GET"===i.elasticsearch.queryMethod&&(t=encodeURIComponent(t));var n={query:e,operator:r.operator?r.operator:"or",fuzziness:r.fuzziness?r.fuzziness:"2",cutoff_frequency:r.cutoff_frequency?r.cutoff_frequency:"0.01",max_expansions:r.max_expansions?r.max_expansions:"3",prefix_length:r.prefix_length?r.prefix_length:"1",minimum_should_match:t,tie_breaker:r.tie_breaker?r.tie_breaker:"1"};return r.hasOwnProperty("analyzer")&&(n.analyzer=r.analyzer),n}(e)}function c(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=[];return i.elasticsearch.hasOwnProperty("searchableAttributes")&&i.elasticsearch.searchableAttributes[e]&&(r=i.elasticsearch.searchableAttributes[e]),r.hasOwnProperty("boost")?r.boost:1}function l(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"products",t=[];return i.hasOwnProperty(r)&&i[r].hasOwnProperty("filterFieldMapping")&&(t=i[r].filterFieldMapping),t.hasOwnProperty(e)?t[e]:e}var h=t(42);function f(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(!e)return;if("string"==typeof e)return y(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return y(e,r)}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,i=!0,u=!1;return{s:function(){t=e[Symbol.iterator]()},n:function(){var e=t.next();return i=e.done,e},e:function(e){u=!0,s=e},f:function(){try{i||null==t.return||t.return()}finally{if(u)throw s}}}}function y(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function p(e,r,t,n,o,s,i){try{var u=e[s](i),a=u.value}catch(e){return void t(e)}u.done?r(a):Promise.resolve(a).then(n,o)}function g(e){return function(){var r=this,t=arguments;return new Promise((function(n,o){var s=e.apply(r,t);function i(e){p(s,n,o,i,u,"next",e)}function u(e){p(s,n,o,i,u,"throw",e)}i(void 0)}))}}function d(e){return b.apply(this,arguments)}function b(){return(b=g(regeneratorRuntime.mark((function e(r){var n,o,s,y,p,g,d,b,m,_,v,w,P,O,q,x,j,E,k,T,S=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=S.length>1&&void 0!==S[1]?S[1]:null,e.next=3,t.e(18).then(t.t.bind(null,2002,7));case 3:if(o=e.sent,s="_options",y=r.getSearchText(),p=["gt","lt","gte","lte","moreq","from","to"],g=o.default(),(d=Object(h.a)(r.getAppliedFilters())).length>0&&(b=!1,d.forEach((function(e){"default"===e.scope?Object.keys(e.value).every((function(e){return p.includes(e)}))?g=g.filter("range",e.attribute,e.value):(e.value=e.value[Object.keys(e.value)[0]],Array.isArray(e.value)||(e.value=[e.value]),g=g.filter("terms",l(e.attribute),e.value)):"catalog"===e.scope&&(b=!0)})),m=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return d.forEach((function(t){var n=Object.keys(t.value);if("catalog"===t.scope&&n.length)if(n.filter((function(e){return-1!==p.indexOf(e)})).length){var o=t.attribute;"price"===o&&(o=i.products.priceFilterKey),e=e.andFilter("range",o,t.value)}else{var s=t.value[Object.keys(t.value)[0]];Array.isArray(s)||(s=[s]),e=""===r?e.andFilter("terms",l(t.attribute),s):e.andFilter("terms",t.attribute+r,s)}})),e},b&&(g=g.filterMinimumShouldMatch(1).orFilter("bool",m).orFilter("bool",(function(e){return m(e,s).filter("match","type_id","configurable")})))),(_=r.getAvailableFilters()).length>0){v=f(_);try{for(v.s();!(w=v.n()).done;)"catalog"===(P=w.value).scope&&("price"!==P.field?(O={size:i.products.filterAggregationSize[P.field]||i.products.filterAggregationSize.default},g=(g=g.aggregation("terms",l(P.field),O)).aggregation("terms",P.field+s,O)):(g=g.aggregation("terms",P.field)).aggregation("range","price",i.products.priceFilters))}catch(e){v.e(e)}finally{v.f()}}return q=function(e){for(var r=i.elasticsearch.hasOwnProperty("searchableAttributes")?i.elasticsearch.searchableAttributes:{name:{boost:1}},t=[],n=0,o=Object.keys(r);n<o.length;n++){var s=o[n];t.push(s+"^"+c(s))}return e.orQuery("multi_match","fields",t,a(y)).orQuery("bool",(function(e){return e.orQuery("terms","configurable_children.sku",y.split("-")).orQuery("match_phrase","sku",{query:y,boost:1}).orQuery("match_phrase","configurable_children.sku",{query:y,boost:1})}))},""!==y&&(x=u(),g=x?g.query("function_score",x,q):g.query("bool",q)),null!==n&&"product"===n.type&&"position"===(j=n.sort.split(":",2))[0]&&(E=r.getAppliedFilters().find((function(e){return"category_ids"===e.attribute})),k=null,E&&E.value&&(k=E.value.in[0])&&g.sort("category.position",{order:j[1]||"asc",nested_path:"category",nested_filter:{terms:{"category.category_id":[k]}}})),T=g.build(),r.suggest&&(T.suggest=r.suggest),e.abrupt("return",T);case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var m=t(18),_=t.n(m),v=t(3),w=t(179),P=t.n(w),O=t(8),q=t(20),x=t(5),j=function(){function e(){this.entities=[],this.initBaseTypes()}return e.prototype.search=function(e){return Object(n.b)(this,void 0,void 0,(function(){var r,t,o,u,a;return Object(n.d)(this,(function(n){switch(n.label){case 0:if(e.searchQuery&&e.searchQuery._appliedFilters&&e.searchQuery._appliedFilters.length>3&&!e.searchQuery._searchText&&"product"==e.type&&e.searchQuery._availableFilters&&e.searchQuery._availableFilters.length>0&&x.b.$emit("notification-progress-start",{msg:s.a.t("Please wait ..."),from:"category_Filter"}),!this.entities[e.type])throw new Error("No entity type registered for "+e.type);return r={},e.searchQuery instanceof q.a?[4,d(e.searchQuery,e)]:[3,2];case 1:return r=n.sent(),""!==e.searchQuery.getSearchText()&&(r.min_score=i.elasticsearch.min_score),[3,3];case 2:r=e.searchQuery,n.label=3;case 3:return e.hasOwnProperty("groupId")&&null!==e.groupId&&(r.groupId=e.groupId),e.hasOwnProperty("groupToken")&&null!==e.groupToken&&(r.groupToken=e.groupToken),null!==e.store?[3,4]:(o=Object(O.b)(),[3,6]);case 4:return[4,Object(O.f)(e.store)];case 5:o=n.sent(),n.label=6;case 6:if(t=o,e.index=t.elasticsearch.index,u=Object(v.l)(t.elasticsearch.host),this.entities[e.type].url&&(u=this.entities[e.type].url),a={size:e.size,from:e.from,sort:e.sort},e._sourceExclude&&(a._source_exclude=e._sourceExclude.join(",")),e._sourceInclude&&(a._source_include=e._sourceInclude.join(",")),e.q&&(a.q=e.q),!e.index||!e.type)throw new Error("Query.index and Query.type are required arguments for executing ElasticSearch query");return"GET"===i.elasticsearch.queryMethod&&(a.request=JSON.stringify(r)),u=(u=u+"/"+encodeURIComponent(e.index)+"/"+encodeURIComponent(e.type)+"/_search")+"?"+P.a.stringify(a),[2,_()(u,{method:i.elasticsearch.queryMethod,mode:"cors",headers:{Accept:"application/json","Content-Type":"application/json"},body:"POST"===i.elasticsearch.queryMethod?JSON.stringify(r):null}).then((function(e){return x.b.$emit("notification-progress-stop",s.a.t("Please wait...")),e.json()})).catch((function(e){throw new Error("FetchError in request to ES: "+e.toString())}))]}}))}))},e.prototype.handleResult=function(e,r,t,n){if(void 0===t&&(t=0),void 0===n&&(n=50),null===e)throw new Error("Invalid ES result - null not exepcted");if(e.hasOwnProperty("hits"))return{items:Object(o.a)(e.hits.hits,(function(e){return Object.assign(e._source,{_score:e._score,slug:e._source.slug?e._source.slug:e._source.hasOwnProperty("url_key")&&i.products.useMagentoUrlKeys?e._source.url_key:e._source.hasOwnProperty("name")?Object(v.p)(e._source.name)+"-"+e._source.id:""})})),total:e.hits.total,start:t,perPage:n,aggregations:e.aggregations,suggestions:e.suggest};throw e.error?new Error(JSON.stringify(e.error)):new Error("Unknown error with elasticsearch result in resultPorcessor for entity type '"+r+"'")},e.prototype.registerEntityType=function(e,r){var t=r.url,n=void 0===t?"":t,o=r.queryProcessor,s=r.resultPorcessor;return this.entities[e]={queryProcessor:o,resultPorcessor:s},""!==n&&(this.entities[e].url=n),this},e.prototype.initBaseTypes=function(){var e=this;this.registerEntityType("product",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"product",t,n)}}),this.registerEntityType("attribute",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"attribute",t,n)}}),this.registerEntityType("category",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"category",t,n)}}),this.registerEntityType("taxrule",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"taxrule",t,n)}}),this.registerEntityType("review",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"review",t,n)}}),this.registerEntityType("cms_page",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"cms_page",t,n)}}),this.registerEntityType("cookie",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"cookie",t,n)}}),this.registerEntityType("cms_block",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"cms_block",t,n)}}),this.registerEntityType("promotion",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"promotion",t,n)}}),this.registerEntityType("banners",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"banners",t,n)}}),this.registerEntityType("cms_hierarchy",{queryProcessor:function(e){return e},resultPorcessor:function(r,t,n){return e.handleResult(r,"cms_hierarchy",t,n)}})},e}()},782:function(e,r,t){"use strict";var n=t(37),o=t(15),s=t(165),i=t(66);var u=function(e,r){var t=-1,n=Object(i.a)(e)?Array(e.length):[];return Object(s.a)(e,(function(e,o,s){n[++t]=r(e,o,s)})),n},a=t(23);r.a=function(e,r){return(Object(a.a)(e)?n.a:u)(e,Object(o.a)(r,3))}}}]); //# sourceMappingURL=vsf-search-adapter-0.56c1b3df03a7533fb193.js.map