diff --git a/CHANGELOG.md b/CHANGELOG.md index 388b3af0f6..84c0da185e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,24 @@ All notable changes to this project will be documented in this file, per [the Keep a Changelog standard](http://keepachangelog.com/). +## [3.5.1] + +A bug fix release. + +Bug fixes: +* Fixes highlighting so that full content is returned instead of only snippets. +* Fix empty synonym bug. +* Only highlight post content, excerpt, and title. + +Enhancements: +* Track CLI index in a headless fashion + ## [3.5.0] Version 3.5 is a very exciting release as it contains two major new features: a synonym dashboard and search term result highlighting. The synonym dashboard empowerers users to create synonym lists for searches. For example. searching "New York City" would return contain with "NYC". Search term highlighting will underline and add a CSS class to keywords within content that matches the current search. +The new version also includes a revamp of the search algorithm. This is a backwards compatibility break. If you'd like to revert to the old search algorithm, you can use the following code: `add_filter( 'ep_search_algorithm_version', function() { return '3.4'; } );`. The new algorithm offers much more relevant search results and removes fuzziness which results in mostly unwanted results for most people. If you are hooking in and modifying the search query directly, it's possible this code might break and you might need to tweak it. + Bug fixes: * Fix default autosuggest selector. * Fix facet feature $_GET parameter naming collision. @@ -22,6 +36,7 @@ Bug fixes: Enhancements: * Synonym dashboard. Props [christianc1](https://github.com/christianc1). * Search term highlighting. Props [oscarsanchez](https://github.com/oscarsanchez). +* Search algorithm improvements. * Improved WP Acceptance tests. Props [asharirfan](https://github.com/asharirfan). * Rename ElasticPress submenu to "Features". Props [helen](https://github.com/helen). * Add functionality for skipping ElasticPress install. diff --git a/README.md b/README.md index 6a350538c3..53b448a87b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ **Please note:** master is the stable branch -**Upgrade Notice:** Versions 1.6.1, 1.6.2, 1.7, 1.8, 2.1, 2.1.2, 2.2, 2.7, 3.0, 3.1, and 3.3 require re-syncing. +**Search Algorithm Upgrade Notice:** Version 3.5 includes a revamp of the search algorithm. This is a backwards compatibility break. If you'd like to revert to the old search algorithm, you can use the following code: `add_filter( 'ep_search_algorithm_version', function() { return '3.4'; } );`. The new algorithm offers much more relevant search results and removes fuzziness which results in mostly unwanted results for most people. If you are hooking in and modifying the search query directly, it's possible this code might break and you might need to tweak it. * Check out the [ElasticPress Docs](http://10up.github.io/ElasticPress/) diff --git a/assets/js/autosuggest.js b/assets/js/autosuggest.js index 76846efcd4..cdec535540 100644 --- a/assets/js/autosuggest.js +++ b/assets/js/autosuggest.js @@ -240,16 +240,16 @@ function updateAutosuggestBox(options, input) { const searchParts = value.trim().split(' '); let resultsText = escapedText; - // uses some regex magic to match upper/lower/capital case - searchParts.forEach((word) => { - const regex = new RegExp(`(${word.trim()})`, 'gi'); - if (word.length > 1) { - resultsText = resultsText.replace( - regex, - '$1', - ); - } - }); + + if (epas.highlightingEnabled) { + // uses some regex magic to match upper/lower/capital case + const regex = new RegExp(`\\b(${searchParts.join('|')})`, 'gi'); + resultsText = resultsText.replace( + regex, + (word) => + `<${epas.highlightingTag} class="${epas.highlightingClass} ep-autosuggest-highlight">${word}`, + ); + } itemString += `
  • @@ -265,10 +265,10 @@ function updateAutosuggestBox(options, input) { suggestList.addEventListener('click', (event) => { event.preventDefault(); - const { srcElement } = event; + const { target } = event; - if (autosuggestItems.includes(srcElement)) { - selectItem(input, srcElement); + if (autosuggestItems.includes(target)) { + selectItem(input, target); } }); @@ -578,14 +578,16 @@ function init() { */ const handleKeyup = (event) => { event.preventDefault(); - if (event.key === 'Escape' || event.key === 'Esc' || event.keyCode === 27) { + const { target, key, keyCode } = event; + + if (key === 'Escape' || key === 'Esc' || keyCode === 27) { hideAutosuggestBox(); - toggleInputAria(false, event.target); - setInputActiveDescendant('', event.target); + toggleInputAria(false, target); + setInputActiveDescendant('', target); return; } - if (keyCodes.includes(event.keyCode)) { + if (keyCodes.includes(keyCode) && target.value !== '') { handleUpDown(event); return; } @@ -607,6 +609,8 @@ function init() { */ epInputs.forEach((input) => { input.addEventListener('keyup', handleKeyup); - input.addEventListener('blur', hideAutosuggestBox); + input.addEventListener('blur', function () { + window.setTimeout(hideAutosuggestBox, 200); + }); }); } diff --git a/assets/js/synonyms/components/editors/AlternativesEditor.js b/assets/js/synonyms/components/editors/AlternativesEditor.js index 49cb171e83..51adea667b 100644 --- a/assets/js/synonyms/components/editors/AlternativesEditor.js +++ b/assets/js/synonyms/components/editors/AlternativesEditor.js @@ -25,7 +25,7 @@ export default function AlterativesEditor({ alternatives }) { */ const handleClick = (e) => { const [lastItem] = state.alternatives.slice(-1); - if (!alternatives || lastItem.synonyms.filter(({ value }) => value.length).length) { + if (!alternatives.length || lastItem.synonyms.filter(({ value }) => value.length).length) { dispatch({ type: 'ADD_ALTERNATIVE' }); } e.preventDefault(); diff --git a/dist/js/autosuggest-script.min.js b/dist/js/autosuggest-script.min.js index b87994bceb..bee2e88492 100644 --- a/dist/js/autosuggest-script.min.js +++ b/dist/js/autosuggest-script.min.js @@ -1,2 +1,2 @@ -!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"===typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=426)}([,,function(t,e,r){(function(e){var r=function(t){return t&&t.Math==Math&&t};t.exports=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof e&&e)||Function("return this")()}).call(this,r(51))},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,r){var n=r(2),o=r(34),i=r(6),a=r(35),c=r(37),u=r(65),s=o("wks"),f=n.Symbol,l=u?f:f&&f.withoutSetter||a;t.exports=function(t){return i(s,t)||(c&&i(f,t)?s[t]=f[t]:s[t]=l("Symbol."+t)),s[t]}},function(t,e,r){var n=r(2),o=r(28).f,i=r(10),a=r(17),c=r(23),u=r(68),s=r(53);t.exports=function(t,e){var r,f,l,p,h,d=t.target,v=t.global,y=t.stat;if(r=v?n:y?n[d]||c(d,{}):(n[d]||{}).prototype)for(f in e){if(p=e[f],l=t.noTargetGet?(h=o(r,f))&&h.value:r[f],!s(v?f:d+(y?".":"#")+f,t.forced)&&void 0!==l){if(typeof p===typeof l)continue;u(p,l)}(t.sham||l&&l.sham)&&i(p,"sham",!0),a(r,f,p,t)}}},function(t,e){var r={}.hasOwnProperty;t.exports=function(t,e){return r.call(t,e)}},function(t,e){t.exports=function(t){return"object"===typeof t?null!==t:"function"===typeof t}},function(t,e,r){var n=r(7);t.exports=function(t){if(!n(t))throw TypeError(String(t)+" is not an object");return t}},function(t,e,r){var n=r(3);t.exports=!n((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}))},function(t,e,r){var n=r(9),o=r(11),i=r(21);t.exports=n?function(t,e,r){return o.f(t,e,i(1,r))}:function(t,e,r){return t[e]=r,t}},function(t,e,r){var n=r(9),o=r(38),i=r(8),a=r(25),c=Object.defineProperty;e.f=n?c:function(t,e,r){if(i(t),e=a(e,!0),i(r),o)try{return c(t,e,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported");return"value"in r&&(t[e]=r.value),t}},function(t,e,r){var n=r(19),o=Math.min;t.exports=function(t){return t>0?o(n(t),9007199254740991):0}},function(t,e,r){var n=r(27),o=r(14);t.exports=function(t){return n(o(t))}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,r){var n=r(14);t.exports=function(t){return Object(n(t))}},function(t,e){var r={}.toString;t.exports=function(t){return r.call(t).slice(8,-1)}},function(t,e,r){var n=r(2),o=r(10),i=r(6),a=r(23),c=r(33),u=r(41),s=u.get,f=u.enforce,l=String(String).split("String");(t.exports=function(t,e,r,c){var u=!!c&&!!c.unsafe,s=!!c&&!!c.enumerable,p=!!c&&!!c.noTargetGet;"function"==typeof r&&("string"!=typeof e||i(r,"name")||o(r,"name",e),f(r).source=l.join("string"==typeof e?e:"")),t!==n?(u?!p&&t[e]&&(s=!0):delete t[e],s?t[e]=r:o(t,e,r)):s?t[e]=r:a(e,r)})(Function.prototype,"toString",(function(){return"function"==typeof this&&s(this).source||c(this)}))},function(t,e,r){var n=r(63),o=r(2),i=function(t){return"function"==typeof t?t:void 0};t.exports=function(t,e){return arguments.length<2?i(n[t])||i(o[t]):n[t]&&n[t][e]||o[t]&&o[t][e]}},function(t,e){var r=Math.ceil,n=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?n:r)(t)}},function(t,e,r){var n=r(9),o=r(3),i=r(6),a=Object.defineProperty,c={},u=function(t){throw t};t.exports=function(t,e){if(i(c,t))return c[t];e||(e={});var r=[][t],s=!!i(e,"ACCESSORS")&&e.ACCESSORS,f=i(e,0)?e[0]:u,l=i(e,1)?e[1]:void 0;return c[t]=!!r&&!o((function(){if(s&&!n)return!0;var t={length:-1};s?a(t,1,{enumerable:!0,get:u}):t[1]=1,r.call(t,f,l)}))}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,r){var n=r(107),o=r(108),i=r(109);t.exports=function(t){return n(t)||o(t)||i()}},function(t,e,r){var n=r(2),o=r(10);t.exports=function(t,e){try{o(n,t,e)}catch(r){n[t]=e}return e}},function(t,e){t.exports={}},function(t,e,r){var n=r(7);t.exports=function(t,e){if(!n(t))return t;var r,o;if(e&&"function"==typeof(r=t.toString)&&!n(o=r.call(t)))return o;if("function"==typeof(r=t.valueOf)&&!n(o=r.call(t)))return o;if(!e&&"function"==typeof(r=t.toString)&&!n(o=r.call(t)))return o;throw TypeError("Can't convert object to primitive value")}},function(t,e){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},function(t,e,r){var n=r(3),o=r(16),i="".split;t.exports=n((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==o(t)?i.call(t,""):Object(t)}:Object},function(t,e,r){var n=r(9),o=r(57),i=r(21),a=r(13),c=r(25),u=r(6),s=r(38),f=Object.getOwnPropertyDescriptor;e.f=n?f:function(t,e){if(t=a(t),e=c(e,!0),s)try{return f(t,e)}catch(t){}if(u(t,e))return i(!o.f.call(t,e),t[e])}},function(t,e,r){var n=r(34),o=r(35),i=n("keys");t.exports=function(t){return i[t]||(i[t]=o(t))}},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t}},function(t,e,r){var n=r(49),o=r(27),i=r(15),a=r(12),c=r(45),u=[].push,s=function(t){var e=1==t,r=2==t,s=3==t,f=4==t,l=6==t,p=5==t||l;return function(h,d,v,y){for(var g,m,x=i(h),b=o(x),w=n(d,v,3),E=a(b.length),_=0,T=y||c,S=e?T(h,E):r?T(h,0):void 0;E>_;_++)if((p||_ in b)&&(m=w(g=b[_],_,x),t))if(e)S[_]=m;else if(m)switch(t){case 3:return!0;case 5:return g;case 6:return _;case 2:u.call(S,g)}else if(f)return!1;return l?-1:s||f?f:S}};t.exports={forEach:s(0),map:s(1),filter:s(2),some:s(3),every:s(4),find:s(5),findIndex:s(6)}},,function(t,e,r){var n=r(40),o=Function.toString;"function"!=typeof n.inspectSource&&(n.inspectSource=function(t){return o.call(t)}),t.exports=n.inspectSource},function(t,e,r){var n=r(42),o=r(40);(t.exports=function(t,e){return o[t]||(o[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.5",mode:n?"pure":"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})},function(t,e){var r=0,n=Math.random();t.exports=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++r+n).toString(36)}},function(t,e,r){var n=r(16);t.exports=Array.isArray||function(t){return"Array"==n(t)}},function(t,e,r){var n=r(3);t.exports=!!Object.getOwnPropertySymbols&&!n((function(){return!String(Symbol())}))},function(t,e,r){var n=r(9),o=r(3),i=r(39);t.exports=!n&&!o((function(){return 7!=Object.defineProperty(i("div"),"a",{get:function(){return 7}}).a}))},function(t,e,r){var n=r(2),o=r(7),i=n.document,a=o(i)&&o(i.createElement);t.exports=function(t){return a?i.createElement(t):{}}},function(t,e,r){var n=r(2),o=r(23),i=n["__core-js_shared__"]||o("__core-js_shared__",{});t.exports=i},function(t,e,r){var n,o,i,a=r(67),c=r(2),u=r(7),s=r(10),f=r(6),l=r(29),p=r(24),h=c.WeakMap;if(a){var d=new h,v=d.get,y=d.has,g=d.set;n=function(t,e){return g.call(d,t,e),e},o=function(t){return v.call(d,t)||{}},i=function(t){return y.call(d,t)}}else{var m=l("state");p[m]=!0,n=function(t,e){return s(t,m,e),e},o=function(t){return f(t,m)?t[m]:{}},i=function(t){return f(t,m)}}t.exports={set:n,get:o,has:i,enforce:function(t){return i(t)?o(t):n(t,{})},getterFor:function(t){return function(e){var r;if(!u(e)||(r=o(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return r}}}},function(t,e){t.exports=!1},function(t,e,r){var n=r(6),o=r(13),i=r(52).indexOf,a=r(24);t.exports=function(t,e){var r,c=o(t),u=0,s=[];for(r in c)!n(a,r)&&n(c,r)&&s.push(r);for(;e.length>u;)n(c,r=e[u++])&&(~i(s,r)||s.push(r));return s}},function(t,e,r){var n=r(3),o=r(4),i=r(59),a=o("species");t.exports=function(t){return i>=51||!n((function(){var e=[];return(e.constructor={})[a]=function(){return{foo:1}},1!==e[t](Boolean).foo}))}},function(t,e,r){var n=r(7),o=r(36),i=r(4)("species");t.exports=function(t,e){var r;return o(t)&&("function"!=typeof(r=t.constructor)||r!==Array&&!o(r.prototype)?n(r)&&null===(r=r[i])&&(r=void 0):r=void 0),new(void 0===r?Array:r)(0===e?0:e)}},function(t,e,r){"use strict";var n=r(60),o=r(85),i=RegExp.prototype.exec,a=String.prototype.replace,c=i,u=function(){var t=/a/,e=/b*/g;return i.call(t,"a"),i.call(e,"a"),0!==t.lastIndex||0!==e.lastIndex}(),s=o.UNSUPPORTED_Y||o.BROKEN_CARET,f=void 0!==/()??/.exec("")[1];(u||f||s)&&(c=function(t){var e,r,o,c,l=this,p=s&&l.sticky,h=n.call(l),d=l.source,v=0,y=t;return p&&(-1===(h=h.replace("y","")).indexOf("g")&&(h+="g"),y=String(t).slice(l.lastIndex),l.lastIndex>0&&(!l.multiline||l.multiline&&"\n"!==t[l.lastIndex-1])&&(d="(?: "+d+")",y=" "+y,v++),r=new RegExp("^(?:"+d+")",h)),f&&(r=new RegExp("^"+d+"$(?!\\s)",h)),u&&(e=l.lastIndex),o=i.call(p?r:l,y),p?o?(o.input=o.input.slice(v),o[0]=o[0].slice(v),o.index=l.lastIndex,l.lastIndex+=o[0].length):l.lastIndex=0:u&&o&&(l.lastIndex=l.global?o.index+o[0].length:e),f&&o&&o.length>1&&a.call(o[0],r,(function(){for(c=1;cf;)if((c=u[f++])!=c)return!0}else for(;s>f;f++)if((t||f in u)&&u[f]===r)return t||f||0;return!t&&-1}};t.exports={includes:a(!0),indexOf:a(!1)}},function(t,e,r){var n=r(3),o=/#|\.prototype\./,i=function(t,e){var r=c[a(t)];return r==s||r!=u&&("function"==typeof e?n(e):!!e)},a=i.normalize=function(t){return String(t).replace(o,".").toLowerCase()},c=i.data={},u=i.NATIVE="N",s=i.POLYFILL="P";t.exports=i},function(t,e,r){"use strict";var n=r(25),o=r(11),i=r(21);t.exports=function(t,e,r){var a=n(e);a in t?o.f(t,a,i(0,r)):t[a]=r}},,function(t,e,r){"use strict";var n=r(3);t.exports=function(t,e){var r=[][t];return!!r&&n((function(){r.call(null,e||function(){throw 1},1)}))}},function(t,e,r){"use strict";var n={}.propertyIsEnumerable,o=Object.getOwnPropertyDescriptor,i=o&&!n.call({1:2},1);e.f=i?function(t){var e=o(this,t);return!!e&&e.enumerable}:n},function(t,e,r){var n,o=r(8),i=r(79),a=r(26),c=r(24),u=r(73),s=r(39),f=r(29),l=f("IE_PROTO"),p=function(){},h=function(t){return"