Changeset 3264568
- Timestamp:
- 03/31/2025 03:56:40 PM (12 months ago)
- Location:
- atlas-search
- Files:
-
- 18 edited
- 1 copied
-
tags/0.2.76 (copied) (copied from atlas-search/trunk)
-
tags/0.2.76/README.txt (modified) (2 diffs)
-
tags/0.2.76/atlas-search.php (modified) (2 diffs)
-
tags/0.2.76/build/recommendations-block/index.asset.php (modified) (1 diff)
-
tags/0.2.76/build/recommendations-block/index.js (modified) (1 diff)
-
tags/0.2.76/build/recommendations-block/query-loop.php (modified) (5 diffs)
-
tags/0.2.76/helper/search/search.php (modified) (1 diff)
-
tags/0.2.76/src/blocks/recommendations-block/index.js (modified) (2 diffs)
-
tags/0.2.76/src/blocks/recommendations-block/index.test.js (modified) (1 diff)
-
tags/0.2.76/src/blocks/recommendations-block/query-loop.php (modified) (5 diffs)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/atlas-search.php (modified) (2 diffs)
-
trunk/build/recommendations-block/index.asset.php (modified) (1 diff)
-
trunk/build/recommendations-block/index.js (modified) (1 diff)
-
trunk/build/recommendations-block/query-loop.php (modified) (5 diffs)
-
trunk/helper/search/search.php (modified) (1 diff)
-
trunk/src/blocks/recommendations-block/index.js (modified) (2 diffs)
-
trunk/src/blocks/recommendations-block/index.test.js (modified) (1 diff)
-
trunk/src/blocks/recommendations-block/query-loop.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
atlas-search/tags/0.2.76/README.txt
r3261003 r3264568 3 3 Tested up to: 6.7.1 4 4 Requires PHP: 7.4 5 Stable tag: 0.2.7 55 Stable tag: 0.2.76 6 6 License: GPLv2 or later 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 56 56 57 57 == Changelog == 58 = 0.2.76 = 59 * **Updated:** Recommendations Block Options 60 * **Fixed:** Recommendations block error handling 61 * **Fixed:** Set limit for posts 62 58 63 = 0.2.75 = 59 64 * **Added:** Semantic & Hybrid Search allows multiple fields to be selected -
atlas-search/tags/0.2.76/atlas-search.php
r3261003 r3264568 16 16 * Plugin URI: https://developers.wpengine.com/ 17 17 * Description: Searching WordPress data with WP Engine Smart Search. 18 * Version: 0.2.7 518 * Version: 0.2.76 19 19 * Author: WP Engine 20 20 * Author URI: https://wpengine.com/ … … 41 41 * Rename this for your plugin and update it as you release new versions. 42 42 */ 43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.7 5' );43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.76' ); 44 44 45 45 /** -
atlas-search/tags/0.2.76/build/recommendations-block/index.asset.php
r3247243 r3264568 1 <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-hooks', 'wp-i18n'), 'version' => ' 42d78a282262aad644fb');1 <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-hooks', 'wp-i18n'), 'version' => '16bbceb5ee694ae1f81f'); -
atlas-search/tags/0.2.76/build/recommendations-block/index.js
r3247243 r3264568 1 (()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=window.React;var a=e.n(i);const c=window.wp.i18n,s=window.wp.blocks,l=window.wp.hooks,p=window.wp.compose,m=window.wp.blockEditor,u=window.wp.components, d="wpengine-smart-search/recommendations";(0,s.registerBlockVariation)("core/query",{name:d,title:(0,c.__)("Smart Search Recommendations","wpengine-smart-search"),description:(0,c.__)("Fetches recommended posts from WP Engine Smart Search","wpengine-smart-search"),icon:"database",attributes:{namespace:d,query:{postType:"post",perPage:3,pages:1,order:"asc",orderBy:"title",offset:0,exclude:[],inherit:!1},postLimit:5,recommendationsType:"trending"},scope:["inserter"],isActive:["namespace"],innerBlocks:[["core/post-template",{layout:{type:"grid",columnCount:3}},[["core/post-featured-image"],["core/post-title",{level:3,isLink:!0}]]]]}),(0,l.addFilter)("blocks.registerBlockType",d,((e,t)=>("core/query"===t&&(e.attributes=o(o({},e.attributes),{},{postLimit:{type:"number",default:5},recommendationsType:{type:"string",default:"trending"}})),e))),(0,l.addFilter)("editor.BlockEdit","core/query",(0,p.createHigherOrderComponent)((e=>t=>{if("wpengine-smart-search/recommendations"!==t.attributes.namespace)return a().createElement(e,t);const{attributes:r,setAttributes:n}=t,{postLimit:o,recommendationsType:i}=r;return a().createElement(a().Fragment,null,a().createElement(m.InspectorControls,null,a().createElement(u.PanelBody,{title:(0,c.__)("Recommendation Settings","wpengine-smart-search"),initialOpen:!0},a().createElement(u.RangeControl,{title:"PostLimit",label:(0,c.__)("Count","wpengine-smart-search"),value:o,onChange:e=>n({postLimit:e}),min:1,max:20}),a().createElement(u.SelectControl,{title:"RecommendationsType",label:(0,c.__)("RecommendationsType","wpengine-smart-search"),value:i,options:[{label:"Trending Posts",value:"trending"},{label:"Related Posts",value:"related"}],onChange:e=>n({recommendationsType:e})}))),a().createElement(e,t))}),"withQueryLoopControls"))})();1 (()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=window.React;var a=e.n(i);const c=window.wp.i18n,s=window.wp.blocks,l=window.wp.hooks,p=window.wp.compose,m=window.wp.blockEditor,u=window.wp.components,y="wpengine-smart-search/recommendations";(0,s.registerBlockVariation)("core/query",{name:y,title:(0,c.__)("Smart Search Recommendations","wpengine-smart-search"),description:(0,c.__)("Fetches recommended posts from WP Engine Smart Search","wpengine-smart-search"),icon:"database",attributes:{namespace:y,query:{postType:"post",offset:0,exclude:[],inherit:!1,perPage:5,sticky:"exclude"},postLimit:5,recommendationsType:"trending"},allowedControls:["postType","sticky","taxQuery"],scope:["inserter"],isActive:["namespace"],innerBlocks:[["core/post-template",{layout:{type:"grid",columnCount:3}},[["core/post-featured-image"],["core/post-title",{level:3,isLink:!0}]]]]}),(0,l.addFilter)("blocks.registerBlockType",y,((e,t)=>("core/query"===t&&(e.attributes=o(o({},e.attributes),{},{postLimit:{type:"number",default:5},recommendationsType:{type:"string",default:"trending"}})),e))),(0,l.addFilter)("editor.BlockEdit","core/query",(0,p.createHigherOrderComponent)((e=>t=>{if("wpengine-smart-search/recommendations"!==t.attributes.namespace)return a().createElement(e,t);const{attributes:r,setAttributes:n}=t,{postLimit:i,recommendationsType:s}=r;return a().createElement(a().Fragment,null,a().createElement(m.InspectorControls,null,a().createElement(u.PanelBody,{title:(0,c.__)("Recommendation Settings","wpengine-smart-search"),initialOpen:!0},a().createElement(u.RangeControl,{title:"PostLimit",label:(0,c.__)("Count","wpengine-smart-search"),value:i,onChange:e=>{n({postLimit:e,query:o(o({},r.query),{},{perPage:e})})},min:1,max:20}),a().createElement(u.SelectControl,{title:"RecommendationsType",label:(0,c.__)("RecommendationsType","wpengine-smart-search"),value:s,options:[{label:"Trending Posts",value:"trending"},{label:"Related Posts",value:"related"}],onChange:e=>n({recommendationsType:e})}))),a().createElement(e,t))}),"withQueryLoopControls"))})(); -
atlas-search/tags/0.2.76/build/recommendations-block/query-loop.php
r3261003 r3264568 21 21 $GLOBALS['rec_block'] = $block; 22 22 23 if ( isset( $block['attrs']['query'] ) ) { 24 $block['attrs']['query']['postsPerPage'] = (int) ( $block['attrs']['postLimit'] ?? 5 ); 25 } 26 23 27 add_filter( 24 28 'query_loop_block_query_vars', … … 37 41 do_action( 'qm/debug', $block['attrs'] ); 38 42 39 $post_limit = (int) ( $block['attrs']['postLimit'] ?? 6);43 $post_limit = (int) ( $block['attrs']['postLimit'] ?? 5 ); 40 44 $recommendations_type = (string) ( $block['attrs']['recommendationsType'] ?? 'trending' ); 41 45 if ( 'trending' === $recommendations_type ) { … … 55 59 } 56 60 61 if ( empty( $popular_ids ) ) { 62 return $query; 63 } 64 57 65 $query['post__in'] = $popular_ids; 58 $query['orderby'] = 'post__in';59 66 60 // Remove the filter after it has been applied to avoid affecting other query loops. 67 $query['orderby'] = 'post__in'; 68 $query['posts_per_page'] = $post_limit; 69 61 70 remove_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\modify_query_vars' ); 62 71 … … 90 99 function get_trending_posts( $count ) { 91 100 $vars = array( 'count' => $count ); 92 $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars ); 93 $docs = $data['data']['recommendations']['trendingDocuments']; 94 return format_docs_as_ids( $docs ); 101 102 try { 103 $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars ); 104 105 if ( isset( $data['errors'] ) ) { 106 return array(); 107 } 108 109 $docs = $data['data']['recommendations']['trendingDocuments'] ?? array(); 110 111 return format_docs_as_ids( $docs ); 112 113 } catch ( \Exception $e ) { 114 return array(); 115 } 95 116 } 96 117 118 119 97 120 function format_docs_as_ids( $docs ) { 121 if ( empty( $docs ) ) { 122 return array(); 123 } 98 124 $ids = array(); 99 125 … … 111 137 'doc_id' => $post_type . ':' . $post_id, 112 138 ); 113 $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars ); 114 $docs = $data['data']['recommendations']['relatedDocuments']; 115 return format_docs_as_ids( $docs ); 139 140 try { 141 $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars ); 142 143 $docs = $data['data']['recommendations']['relatedDocuments'] ?? array(); 144 if ( isset( $data['errors'] ) ) { 145 return array(); 146 } 147 148 return format_docs_as_ids( $docs ); 149 150 } catch ( \Exception $e ) { 151 return array(); 152 } 116 153 } -
atlas-search/tags/0.2.76/helper/search/search.php
r3239389 r3264568 294 294 * Sometimes WP plugin developers calling with negative number expect to get all posts 295 295 */ 296 $posts_per_page = ( $posts_per_page < 0 ) ? 1000 : $posts_per_page; 297 $query_offset = $query->get( 'offset', false ); 298 $offset = false !== $query_offset ? $query_offset : self::get_offset( $page_number, $posts_per_page ); 299 $filter = $this->generate_filters( $post_types, $query, $excluded_post_types ); 296 $posts_per_page = ( $posts_per_page < 0 || $posts_per_page > 1000 ) ? 1000 : $posts_per_page; 297 $query->set( 'posts_per_page', $posts_per_page ); 298 $query_offset = $query->get( 'offset', false ); 299 $offset = false !== $query_offset ? $query_offset : self::get_offset( $page_number, $posts_per_page ); 300 $filter = $this->generate_filters( $post_types, $query, $excluded_post_types ); 300 301 301 302 if ( 0 == $posts_per_page ) { -
atlas-search/tags/0.2.76/src/blocks/recommendations-block/index.js
r3247243 r3264568 23 23 query: { 24 24 postType: 'post', 25 perPage: 3,26 pages: 1,27 order: 'asc',28 orderBy: 'title',29 25 offset: 0, 30 26 exclude: [], 31 27 inherit: false, 28 perPage: 5, 29 sticky: 'exclude', 32 30 }, 33 31 postLimit: 5, 34 32 recommendationsType: 'trending', 35 33 }, 34 allowedControls: ['postType', 'sticky', 'taxQuery'], 36 35 scope: ['inserter'], 37 36 isActive: ['namespace'], … … 97 96 label={__('Count', 'wpengine-smart-search')} 98 97 value={postLimit} 99 onChange={(newPostLimit) => 100 setAttributes({ postLimit: newPostLimit }) 101 } 98 onChange={(newPostLimit) => { 99 setAttributes({ 100 postLimit: newPostLimit, 101 query: { ...attributes.query, perPage: newPostLimit }, 102 }); 103 }} 102 104 min={1} 103 105 max={20} -
atlas-search/tags/0.2.76/src/blocks/recommendations-block/index.test.js
r3247243 r3264568 67 67 }); 68 68 69 expect(setAttributes).toHaveBeenCalledWith({ postLimit: '10' }); 69 expect(setAttributes).toHaveBeenCalledWith({ 70 postLimit: '10', 71 query: { perPage: '10' }, 72 }); 70 73 }); 71 74 -
atlas-search/tags/0.2.76/src/blocks/recommendations-block/query-loop.php
r3261003 r3264568 21 21 $GLOBALS['rec_block'] = $block; 22 22 23 if ( isset( $block['attrs']['query'] ) ) { 24 $block['attrs']['query']['postsPerPage'] = (int) ( $block['attrs']['postLimit'] ?? 5 ); 25 } 26 23 27 add_filter( 24 28 'query_loop_block_query_vars', … … 37 41 do_action( 'qm/debug', $block['attrs'] ); 38 42 39 $post_limit = (int) ( $block['attrs']['postLimit'] ?? 6);43 $post_limit = (int) ( $block['attrs']['postLimit'] ?? 5 ); 40 44 $recommendations_type = (string) ( $block['attrs']['recommendationsType'] ?? 'trending' ); 41 45 if ( 'trending' === $recommendations_type ) { … … 55 59 } 56 60 61 if ( empty( $popular_ids ) ) { 62 return $query; 63 } 64 57 65 $query['post__in'] = $popular_ids; 58 $query['orderby'] = 'post__in';59 66 60 // Remove the filter after it has been applied to avoid affecting other query loops. 67 $query['orderby'] = 'post__in'; 68 $query['posts_per_page'] = $post_limit; 69 61 70 remove_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\modify_query_vars' ); 62 71 … … 90 99 function get_trending_posts( $count ) { 91 100 $vars = array( 'count' => $count ); 92 $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars ); 93 $docs = $data['data']['recommendations']['trendingDocuments']; 94 return format_docs_as_ids( $docs ); 101 102 try { 103 $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars ); 104 105 if ( isset( $data['errors'] ) ) { 106 return array(); 107 } 108 109 $docs = $data['data']['recommendations']['trendingDocuments'] ?? array(); 110 111 return format_docs_as_ids( $docs ); 112 113 } catch ( \Exception $e ) { 114 return array(); 115 } 95 116 } 96 117 118 119 97 120 function format_docs_as_ids( $docs ) { 121 if ( empty( $docs ) ) { 122 return array(); 123 } 98 124 $ids = array(); 99 125 … … 111 137 'doc_id' => $post_type . ':' . $post_id, 112 138 ); 113 $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars ); 114 $docs = $data['data']['recommendations']['relatedDocuments']; 115 return format_docs_as_ids( $docs ); 139 140 try { 141 $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars ); 142 143 $docs = $data['data']['recommendations']['relatedDocuments'] ?? array(); 144 if ( isset( $data['errors'] ) ) { 145 return array(); 146 } 147 148 return format_docs_as_ids( $docs ); 149 150 } catch ( \Exception $e ) { 151 return array(); 152 } 116 153 } -
atlas-search/trunk/README.txt
r3261003 r3264568 3 3 Tested up to: 6.7.1 4 4 Requires PHP: 7.4 5 Stable tag: 0.2.7 55 Stable tag: 0.2.76 6 6 License: GPLv2 or later 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 56 56 57 57 == Changelog == 58 = 0.2.76 = 59 * **Updated:** Recommendations Block Options 60 * **Fixed:** Recommendations block error handling 61 * **Fixed:** Set limit for posts 62 58 63 = 0.2.75 = 59 64 * **Added:** Semantic & Hybrid Search allows multiple fields to be selected -
atlas-search/trunk/atlas-search.php
r3261003 r3264568 16 16 * Plugin URI: https://developers.wpengine.com/ 17 17 * Description: Searching WordPress data with WP Engine Smart Search. 18 * Version: 0.2.7 518 * Version: 0.2.76 19 19 * Author: WP Engine 20 20 * Author URI: https://wpengine.com/ … … 41 41 * Rename this for your plugin and update it as you release new versions. 42 42 */ 43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.7 5' );43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.76' ); 44 44 45 45 /** -
atlas-search/trunk/build/recommendations-block/index.asset.php
r3247243 r3264568 1 <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-hooks', 'wp-i18n'), 'version' => ' 42d78a282262aad644fb');1 <?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-hooks', 'wp-i18n'), 'version' => '16bbceb5ee694ae1f81f'); -
atlas-search/trunk/build/recommendations-block/index.js
r3247243 r3264568 1 (()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=window.React;var a=e.n(i);const c=window.wp.i18n,s=window.wp.blocks,l=window.wp.hooks,p=window.wp.compose,m=window.wp.blockEditor,u=window.wp.components, d="wpengine-smart-search/recommendations";(0,s.registerBlockVariation)("core/query",{name:d,title:(0,c.__)("Smart Search Recommendations","wpengine-smart-search"),description:(0,c.__)("Fetches recommended posts from WP Engine Smart Search","wpengine-smart-search"),icon:"database",attributes:{namespace:d,query:{postType:"post",perPage:3,pages:1,order:"asc",orderBy:"title",offset:0,exclude:[],inherit:!1},postLimit:5,recommendationsType:"trending"},scope:["inserter"],isActive:["namespace"],innerBlocks:[["core/post-template",{layout:{type:"grid",columnCount:3}},[["core/post-featured-image"],["core/post-title",{level:3,isLink:!0}]]]]}),(0,l.addFilter)("blocks.registerBlockType",d,((e,t)=>("core/query"===t&&(e.attributes=o(o({},e.attributes),{},{postLimit:{type:"number",default:5},recommendationsType:{type:"string",default:"trending"}})),e))),(0,l.addFilter)("editor.BlockEdit","core/query",(0,p.createHigherOrderComponent)((e=>t=>{if("wpengine-smart-search/recommendations"!==t.attributes.namespace)return a().createElement(e,t);const{attributes:r,setAttributes:n}=t,{postLimit:o,recommendationsType:i}=r;return a().createElement(a().Fragment,null,a().createElement(m.InspectorControls,null,a().createElement(u.PanelBody,{title:(0,c.__)("Recommendation Settings","wpengine-smart-search"),initialOpen:!0},a().createElement(u.RangeControl,{title:"PostLimit",label:(0,c.__)("Count","wpengine-smart-search"),value:o,onChange:e=>n({postLimit:e}),min:1,max:20}),a().createElement(u.SelectControl,{title:"RecommendationsType",label:(0,c.__)("RecommendationsType","wpengine-smart-search"),value:i,options:[{label:"Trending Posts",value:"trending"},{label:"Related Posts",value:"related"}],onChange:e=>n({recommendationsType:e})}))),a().createElement(e,t))}),"withQueryLoopControls"))})();1 (()=>{"use strict";var e={};function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function r(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}e.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=window.React;var a=e.n(i);const c=window.wp.i18n,s=window.wp.blocks,l=window.wp.hooks,p=window.wp.compose,m=window.wp.blockEditor,u=window.wp.components,y="wpengine-smart-search/recommendations";(0,s.registerBlockVariation)("core/query",{name:y,title:(0,c.__)("Smart Search Recommendations","wpengine-smart-search"),description:(0,c.__)("Fetches recommended posts from WP Engine Smart Search","wpengine-smart-search"),icon:"database",attributes:{namespace:y,query:{postType:"post",offset:0,exclude:[],inherit:!1,perPage:5,sticky:"exclude"},postLimit:5,recommendationsType:"trending"},allowedControls:["postType","sticky","taxQuery"],scope:["inserter"],isActive:["namespace"],innerBlocks:[["core/post-template",{layout:{type:"grid",columnCount:3}},[["core/post-featured-image"],["core/post-title",{level:3,isLink:!0}]]]]}),(0,l.addFilter)("blocks.registerBlockType",y,((e,t)=>("core/query"===t&&(e.attributes=o(o({},e.attributes),{},{postLimit:{type:"number",default:5},recommendationsType:{type:"string",default:"trending"}})),e))),(0,l.addFilter)("editor.BlockEdit","core/query",(0,p.createHigherOrderComponent)((e=>t=>{if("wpengine-smart-search/recommendations"!==t.attributes.namespace)return a().createElement(e,t);const{attributes:r,setAttributes:n}=t,{postLimit:i,recommendationsType:s}=r;return a().createElement(a().Fragment,null,a().createElement(m.InspectorControls,null,a().createElement(u.PanelBody,{title:(0,c.__)("Recommendation Settings","wpengine-smart-search"),initialOpen:!0},a().createElement(u.RangeControl,{title:"PostLimit",label:(0,c.__)("Count","wpengine-smart-search"),value:i,onChange:e=>{n({postLimit:e,query:o(o({},r.query),{},{perPage:e})})},min:1,max:20}),a().createElement(u.SelectControl,{title:"RecommendationsType",label:(0,c.__)("RecommendationsType","wpengine-smart-search"),value:s,options:[{label:"Trending Posts",value:"trending"},{label:"Related Posts",value:"related"}],onChange:e=>n({recommendationsType:e})}))),a().createElement(e,t))}),"withQueryLoopControls"))})(); -
atlas-search/trunk/build/recommendations-block/query-loop.php
r3261003 r3264568 21 21 $GLOBALS['rec_block'] = $block; 22 22 23 if ( isset( $block['attrs']['query'] ) ) { 24 $block['attrs']['query']['postsPerPage'] = (int) ( $block['attrs']['postLimit'] ?? 5 ); 25 } 26 23 27 add_filter( 24 28 'query_loop_block_query_vars', … … 37 41 do_action( 'qm/debug', $block['attrs'] ); 38 42 39 $post_limit = (int) ( $block['attrs']['postLimit'] ?? 6);43 $post_limit = (int) ( $block['attrs']['postLimit'] ?? 5 ); 40 44 $recommendations_type = (string) ( $block['attrs']['recommendationsType'] ?? 'trending' ); 41 45 if ( 'trending' === $recommendations_type ) { … … 55 59 } 56 60 61 if ( empty( $popular_ids ) ) { 62 return $query; 63 } 64 57 65 $query['post__in'] = $popular_ids; 58 $query['orderby'] = 'post__in';59 66 60 // Remove the filter after it has been applied to avoid affecting other query loops. 67 $query['orderby'] = 'post__in'; 68 $query['posts_per_page'] = $post_limit; 69 61 70 remove_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\modify_query_vars' ); 62 71 … … 90 99 function get_trending_posts( $count ) { 91 100 $vars = array( 'count' => $count ); 92 $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars ); 93 $docs = $data['data']['recommendations']['trendingDocuments']; 94 return format_docs_as_ids( $docs ); 101 102 try { 103 $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars ); 104 105 if ( isset( $data['errors'] ) ) { 106 return array(); 107 } 108 109 $docs = $data['data']['recommendations']['trendingDocuments'] ?? array(); 110 111 return format_docs_as_ids( $docs ); 112 113 } catch ( \Exception $e ) { 114 return array(); 115 } 95 116 } 96 117 118 119 97 120 function format_docs_as_ids( $docs ) { 121 if ( empty( $docs ) ) { 122 return array(); 123 } 98 124 $ids = array(); 99 125 … … 111 137 'doc_id' => $post_type . ':' . $post_id, 112 138 ); 113 $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars ); 114 $docs = $data['data']['recommendations']['relatedDocuments']; 115 return format_docs_as_ids( $docs ); 139 140 try { 141 $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars ); 142 143 $docs = $data['data']['recommendations']['relatedDocuments'] ?? array(); 144 if ( isset( $data['errors'] ) ) { 145 return array(); 146 } 147 148 return format_docs_as_ids( $docs ); 149 150 } catch ( \Exception $e ) { 151 return array(); 152 } 116 153 } -
atlas-search/trunk/helper/search/search.php
r3239389 r3264568 294 294 * Sometimes WP plugin developers calling with negative number expect to get all posts 295 295 */ 296 $posts_per_page = ( $posts_per_page < 0 ) ? 1000 : $posts_per_page; 297 $query_offset = $query->get( 'offset', false ); 298 $offset = false !== $query_offset ? $query_offset : self::get_offset( $page_number, $posts_per_page ); 299 $filter = $this->generate_filters( $post_types, $query, $excluded_post_types ); 296 $posts_per_page = ( $posts_per_page < 0 || $posts_per_page > 1000 ) ? 1000 : $posts_per_page; 297 $query->set( 'posts_per_page', $posts_per_page ); 298 $query_offset = $query->get( 'offset', false ); 299 $offset = false !== $query_offset ? $query_offset : self::get_offset( $page_number, $posts_per_page ); 300 $filter = $this->generate_filters( $post_types, $query, $excluded_post_types ); 300 301 301 302 if ( 0 == $posts_per_page ) { -
atlas-search/trunk/src/blocks/recommendations-block/index.js
r3247243 r3264568 23 23 query: { 24 24 postType: 'post', 25 perPage: 3,26 pages: 1,27 order: 'asc',28 orderBy: 'title',29 25 offset: 0, 30 26 exclude: [], 31 27 inherit: false, 28 perPage: 5, 29 sticky: 'exclude', 32 30 }, 33 31 postLimit: 5, 34 32 recommendationsType: 'trending', 35 33 }, 34 allowedControls: ['postType', 'sticky', 'taxQuery'], 36 35 scope: ['inserter'], 37 36 isActive: ['namespace'], … … 97 96 label={__('Count', 'wpengine-smart-search')} 98 97 value={postLimit} 99 onChange={(newPostLimit) => 100 setAttributes({ postLimit: newPostLimit }) 101 } 98 onChange={(newPostLimit) => { 99 setAttributes({ 100 postLimit: newPostLimit, 101 query: { ...attributes.query, perPage: newPostLimit }, 102 }); 103 }} 102 104 min={1} 103 105 max={20} -
atlas-search/trunk/src/blocks/recommendations-block/index.test.js
r3247243 r3264568 67 67 }); 68 68 69 expect(setAttributes).toHaveBeenCalledWith({ postLimit: '10' }); 69 expect(setAttributes).toHaveBeenCalledWith({ 70 postLimit: '10', 71 query: { perPage: '10' }, 72 }); 70 73 }); 71 74 -
atlas-search/trunk/src/blocks/recommendations-block/query-loop.php
r3261003 r3264568 21 21 $GLOBALS['rec_block'] = $block; 22 22 23 if ( isset( $block['attrs']['query'] ) ) { 24 $block['attrs']['query']['postsPerPage'] = (int) ( $block['attrs']['postLimit'] ?? 5 ); 25 } 26 23 27 add_filter( 24 28 'query_loop_block_query_vars', … … 37 41 do_action( 'qm/debug', $block['attrs'] ); 38 42 39 $post_limit = (int) ( $block['attrs']['postLimit'] ?? 6);43 $post_limit = (int) ( $block['attrs']['postLimit'] ?? 5 ); 40 44 $recommendations_type = (string) ( $block['attrs']['recommendationsType'] ?? 'trending' ); 41 45 if ( 'trending' === $recommendations_type ) { … … 55 59 } 56 60 61 if ( empty( $popular_ids ) ) { 62 return $query; 63 } 64 57 65 $query['post__in'] = $popular_ids; 58 $query['orderby'] = 'post__in';59 66 60 // Remove the filter after it has been applied to avoid affecting other query loops. 67 $query['orderby'] = 'post__in'; 68 $query['posts_per_page'] = $post_limit; 69 61 70 remove_filter( 'query_loop_block_query_vars', __NAMESPACE__ . '\modify_query_vars' ); 62 71 … … 90 99 function get_trending_posts( $count ) { 91 100 $vars = array( 'count' => $count ); 92 $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars ); 93 $docs = $data['data']['recommendations']['trendingDocuments']; 94 return format_docs_as_ids( $docs ); 101 102 try { 103 $data = \AtlasSearch\Index\graphql( TRENDING_GRAPHQL, $vars ); 104 105 if ( isset( $data['errors'] ) ) { 106 return array(); 107 } 108 109 $docs = $data['data']['recommendations']['trendingDocuments'] ?? array(); 110 111 return format_docs_as_ids( $docs ); 112 113 } catch ( \Exception $e ) { 114 return array(); 115 } 95 116 } 96 117 118 119 97 120 function format_docs_as_ids( $docs ) { 121 if ( empty( $docs ) ) { 122 return array(); 123 } 98 124 $ids = array(); 99 125 … … 111 137 'doc_id' => $post_type . ':' . $post_id, 112 138 ); 113 $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars ); 114 $docs = $data['data']['recommendations']['relatedDocuments']; 115 return format_docs_as_ids( $docs ); 139 140 try { 141 $data = \AtlasSearch\Index\graphql( RELATED_GRAPHQL, $vars ); 142 143 $docs = $data['data']['recommendations']['relatedDocuments'] ?? array(); 144 if ( isset( $data['errors'] ) ) { 145 return array(); 146 } 147 148 return format_docs_as_ids( $docs ); 149 150 } catch ( \Exception $e ) { 151 return array(); 152 } 116 153 }
Note: See TracChangeset
for help on using the changeset viewer.