Plugin Directory

Changeset 3147520


Ignore:
Timestamp:
09/06/2024 11:04:22 AM (18 months ago)
Author:
wpengine
Message:

Tagging version 0.2.57

Location:
atlas-search
Files:
12 added
6 deleted
32 edited
1 copied

Legend:

Unmodified
Added
Removed
  • atlas-search/tags/0.2.57/README.txt

    r3143797 r3147520  
    33Tested up to: 6.6
    44Requires PHP: 7.4
    5 Stable tag: 0.2.56
     5Stable tag: 0.2.57
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4848
    4949== Changelog ==
     50= 0.2.57 =
     51* **Added:** Bulk indexing support.
     52* **Updated:** wp-cli command which now takes into account multisite
     53* **Added:** Improved WP_Meta_Query mappings for the LIKE operator.
     54
    5055= 0.2.56 =
    5156* **Added:** WP_Meta_Query support.
  • atlas-search/tags/0.2.57/atlas-search.php

    r3143797 r3147520  
    1616 * Plugin URI:        https://developers.wpengine.com/
    1717 * Description:       Searching WordPress data with WP Engine Smart Search.
    18  * Version:           0.2.56
     18 * Version:           0.2.57
    1919 * Author:            WP Engine
    2020 * Author URI:        https://wpengine.com/
     
    4141 * Rename this for your plugin and update it as you release new versions.
    4242 */
    43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.56' );
     43define( 'WPE_SMART_SEARCH_VERSION', '0.2.57' );
    4444
    4545/**
  • atlas-search/tags/0.2.57/commands/class-wpe-content-engine-sync-data.php

    r3075724 r3147520  
    55}
    66
    7 use Wpe_Content_Engine\Core_Wp_Wrapper\Wp_Progress_Bar;
    8 use Wpe_Content_Engine\Helper\Progress_Bar_Info_Trait;
    9 use Wpe_Content_Engine\Helper\Sync\Batches\Batch_Sync_Factory;
    10 use Wpe_Content_Engine\Helper\Sync\Batches\Options\Batch_Options;
    11 use Wpe_Content_Engine\Helper\Sync\Batches\Options\Resume_Options;
    12 use Wpe_Content_Engine\Helper\Sync\Batches\Sync_Lock_Manager;
    13 use Wpe_Content_Engine\Helper\Sync\Batches\Batch_Sync_Interface;
    14 use const AtlasSearch\Index\MANUAL_INDEX;
    15 use const Wpe_Content_Engine\Helper\Notifications\WPE_CONTENT_ENGINE_RE_SYNC_HAS_OCCURRED;
    16 
    17 // @codingStandardsIgnoreStart
     7use Wpe_Content_Engine\WPSettings;
    188
    199/**
     
    2111 */
    2212class Wpe_Content_Engine_Sync_Data {
    23 
     13    private $start_time;
    2414    /**
    2515     * Syncs all data to Smart Search.
    2616     *
    2717     * ## EXAMPLES
    28      *    wp wpe-smart-search sync-data --size=10 --no-resume
    29      *    or
    3018     *    wp wpe-smart-search sync-data
    3119     *    or
    3220     *    wp wpe-smart-search sync-data --reset
    33      *
    34      * [--size=<batch-size>]
    35      * : Used to sync ALL data in batches of <batch-size>. Batch size should be a positive integer.
    36      * If is set to a very big integer the system might run out of memory or fail to sync all data.
    37      * If no value is specified then defaults to 20
    38      *
    39      * [--no-resume]
    40      * : Start sync from the start and not from last error
    41      * default: true
    4221     *
    4322     * [--reset]
     
    4524     * default: false
    4625     *
     26     * [--site-id]
     27     * : Site ID to sync data for
     28     * default: current site or network admin if in multi-site mode
     29     * options: <site-id> | network
     30     *
    4731     * @subcommand sync-data
    4832     * @when after_wp_load
    4933     *
     34     * @param array $args    Command arguments.
     35     * @param array $assoc_args Command associative arguments.
    5036     */
     37    public function _sync_data( $args, $assoc_args ) {
     38        try {
     39            $this->start_time = time();
     40            $client           = new \Wpe_Content_Engine\Helper\Sync\GraphQL\Client( Wpe_Content_Engine::get_plugin_name(), Wpe_Content_Engine::get_version() );
     41            $controller       = new \Wpe_Content_Engine\Helper\API\Sync_Data\Sync_Data_Controller( $client, new WPSettings() );
    5142
    52     public function _sync_data( $args, $assoc_args ) {
    53         $batch_size = (int) ( $assoc_args['size'] ?? Batch_Options::DEFAULT_BATCH_SIZE );
     43            $reset = $assoc_args['reset'] ?? false;
     44            if ( $reset ) {
     45                WP_CLI::line( 'Clearing all data.' );
     46                $result = $controller->delete_sync_data( new WP_REST_Request( 'DELETE' ) );
     47                if ( 200 !== $result->status ) {
     48                    WP_CLI::error( 'Failed to clear data.' );
     49                }
     50                WP_CLI::line( $result->data['message'] );
     51            }
    5452
    55         if ( $batch_size <= 0 ) {
    56             WP_CLI::error( 'Batch size should be an integer greater than zero' );
    57             return;
     53            $site_id_arg = $assoc_args['site-id'] ?? false;
     54            $site_id     = $this->parse_site_id( $site_id_arg );
     55            $uuid        = '';
     56            /**
     57             * @var \Wpe_Content_Engine\Helper\API\Sync_Data\Response $result
     58             */
     59            $result = $this->perform_index( $controller, $uuid, $site_id );
     60
     61            $this->display_progress_bar( $result->message ?? '', $result->progress, 100 );
     62
     63            while ( \Wpe_Content_Engine\Helper\Constants\Sync_Response_Status::PENDING === $result->status ) {
     64                $result = $this->perform_index( $controller, $result->uuid, $site_id );
     65                if ( \Wpe_Content_Engine\Helper\Constants\Sync_Response_Status::COMPLETED === $result->status ) {
     66                    break;
     67                } else {
     68                    $this->display_progress_bar( $result->message ?? '', $result->progress, 100 );
     69                }
     70            }
     71            WP_CLI::log( "\r\nIndexing completed!" );
     72        } catch ( \Exception $e ) {
     73            WP_CLI::error( $e->getMessage() );
     74        }
     75    }
     76
     77    private function perform_index( $controller, $uuid, $site_id ) {
     78        $rest_request = new WP_REST_Request( 'POST', '/wpe-content-engine/v1/sync-data' );
     79            $rest_request->set_body(
     80                wp_json_encode(
     81                    array(
     82                        'uuid'   => $uuid,
     83                        'siteId' => $site_id,
     84                    )
     85                )
     86            );
     87            $rest_request->set_headers(
     88                array(
     89                    'Content-Type' => 'application/json',
     90                ),
     91            );
     92            return $controller->sync_data( $rest_request );
     93    }
     94
     95    private function parse_site_id( $site_id ) {
     96        if ( 'network' === $site_id ) {
     97            return \AtlasSearch\Support\WordPress\NETWORK_ADMIN;
     98        } elseif ( $site_id ) {
     99            return $site_id;
     100        } elseif ( is_multisite() ) {
     101            return \AtlasSearch\Support\WordPress\NETWORK_ADMIN;
     102        } else {
     103            return (string) get_current_blog_id();
     104        }
     105    }
     106
     107    private function display_progress_bar( string $message, int $current, int $total, int $length = 50 ) {
     108        if ( 0 === $current ) {
     109            $current = 1;
    58110        }
    59111
    60         $with_reset = $assoc_args['reset'] ?? false;
    61         $with_resume = $assoc_args['resume'] ?? true;
     112        $percent      = floor( ( $current * 100 ) / $total );
     113        $progress_bar = floor( ( $length * $percent ) / 100 );
    62114
    63         $batch_options = new Batch_Options(
    64             $batch_size,
    65             1,
    66             Batch_Sync_Factory::DATA_TO_SYNC,
    67             array( get_current_blog_id() )
     115        // Calculate elapsed time.
     116        $elapsed_time = time() - $this->start_time;
     117
     118        // Estimate remaining time.
     119        $estimated_total_time = ( $elapsed_time / $current ) * $total;
     120        $remaining_time       = $estimated_total_time - $elapsed_time;
     121
     122        // Format remaining time.
     123        $remaining_minutes        = floor( $remaining_time / 60 );
     124        $remaining_seconds        = $remaining_time % 60;
     125        $remaining_time_formatted = sprintf( '%02d:%02d', $remaining_minutes, $remaining_seconds );
     126
     127        printf(
     128            "  %s%% [%s>%s] %s/%s | ETA: %s | %s\r",
     129            esc_html( $percent ),
     130            esc_html( str_repeat( '=', $progress_bar ) ),
     131            esc_html( str_repeat( ' ', $length - $progress_bar ) ),
     132            esc_html( $current ),
     133            esc_html( $total ),
     134            esc_html( $remaining_time_formatted ),
     135            esc_html( $message . str_repeat( ' ', 20 ) ),
    68136        );
     137    }
    69138
    70         /** @var Resume_Options|null $resume_options */
    71         $resume_options = get_option( Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME, null );
     139}
    72140
    73         if ( $with_resume && !$with_reset && !empty( $resume_options ) && ( $resume_options instanceof Resume_Options ) ) {
    74             $batch_options->calculate_with_resume( $resume_options );
    75 
    76             WP_CLI::log(
    77                 "Resume started! Starting with these parameters --> Table:{$resume_options->get_entity()}, "
    78                 . " Page: {$batch_options->get_page()}, Batch Size: {$batch_options->get_batch_size()}"
    79             );
    80         }
    81 
    82         $sync_lock_manager = new Sync_Lock_Manager();
    83         $uuid = null;
    84 
    85         try {
    86             $time_start = new DateTime();
    87             $start = microtime(true);
    88 
    89             $moment = new DateTime();
    90             $can_start = $sync_lock_manager->can_start( $moment );
    91             $cannot_start_text = !$can_start ? 'yes' : 'no';
    92             WP_CLI::log( "Init check, lock present: {$cannot_start_text}" );
    93 
    94             if ( $can_start ) {
    95                 // activate
    96                 WP_CLI::log( "No lock present, starting sync..." );
    97                 $uuid = $sync_lock_manager->start( $moment, null );
    98                 WP_CLI::log( "Sync lock acquired. Sync lock ID: {$uuid}" );
    99             }
    100             else {
    101                 WP_CLI::log( "Lock active! Cannot start a new sync! Exiting..." );
    102                 return;
    103             }
    104 
    105             delete_option( Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME );
    106 
    107             if ( $with_reset ) {
    108                 WP_CLI::log( "'--reset' flag was provided. Deleting all.");
    109                 \AtlasSearch\Index\delete_all( MANUAL_INDEX );
    110             }
    111 
    112             foreach ( $batch_options->get_data_to_be_synced() as $short_name => $class ) {
    113 
    114                 /** @var Batch_Sync_Interface| Progress_Bar_Info_Trait $obj ,
    115                  * @var string $class
    116                  */
    117                 $obj = Batch_Sync_Factory::build( $class );
    118                 $page = $batch_options->get_page();
    119                 WP_CLI::log( "Sync started : {$short_name}" );
    120 
    121                 do {
    122                     try {
    123                         $items = $obj->get_items( $page, $batch_size );
    124 
    125                         if ( empty( $items ) ) {
    126                             continue;
    127                         }
    128 
    129                         $obj->format_items( $items, $page );
    130                         $obj->set_progress_bar( new Wp_Progress_Bar( count( $items ) ) );
    131                         $obj->sync( $items );
    132                         $page ++;
    133                     } catch ( ErrorException $e ) {
    134                         WP_CLI::error( "Something went wrong. Error message: {$e->getMessage()}", false );
    135                     } finally {
    136                         update_option(
    137                             Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME,
    138                             new Resume_Options( $short_name, $batch_size, $page )
    139                         );
    140 
    141                         if ( isset( $e ) && ( $e instanceof ErrorException ) ) {
    142                             /** @var ErrorException|null $e */
    143                             throw $e;
    144                         }
    145                     }
    146                 } while ( count( $items ) >= $batch_size );
    147 
    148                 $batch_options->set_page( 1 );
    149 
    150                 WP_CLI::log(
    151                     empty( $obj->get_items( 1, $batch_size ) ) ? "No {$short_name} data to sync" : "Sync Success: {$short_name}"
    152                 );
    153 
    154                 update_option( WPE_CONTENT_ENGINE_RE_SYNC_HAS_OCCURRED, true );
    155             }
    156 
    157             delete_option( Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME );
    158             WP_CLI::log( 'Success syncing all data' );
    159 
    160             $fd = ( new DateTime() )->diff( $time_start );
    161             WP_CLI::log( WP_CLI::colorize( "%GTotal time: {$fd->format('%H:%i:%s.%f')}%n " ) );
    162         } catch ( ErrorException $e ) {
    163             WP_CLI::error( "There was an error during sync. Error message: {$e->getMessage()}", false );
    164         }
    165         finally {
    166             // make sure that we always release the lock if we acquired one this run.
    167             if ( !empty( $uuid ) ) {
    168                 $moment = new DateTime();
    169                 $sync_lock_manager->finish( $moment, $uuid );
    170                 WP_CLI::log( "Sync lock ID {$uuid} released!" );
    171             }
    172             else {
    173                 WP_CLI::log( 'No sync lock acquired this run.!' );
    174             }
    175         }
    176     }
    177 }
    178141WP_CLI::add_command( 'wpe-smart-search', 'Wpe_Content_Engine_Sync_Data' );
    179 
    180 // @codingStandardsIgnoreEnd
  • atlas-search/tags/0.2.57/helper/api/sync-data/sync-data-controller.php

    r3116529 r3147520  
    106106        $site_ids      = $this->get_site_ids( \AtlasSearch\Support\WordPress\NETWORK_ADMIN === $json['siteId'] );
    107107        $batch_options = new Batch_Options(
    108             Batch_Options::DEFAULT_BATCH_SIZE,
     108            \AtlasSearch\Index\get_batch_size(),
    109109            1,
    110110            Batch_Sync_Factory::DATA_TO_SYNC,
     
    290290            $obj        = Batch_Sync_Factory::build( $current_data['class'], \AtlasSearch\Support\WordPress\NETWORK_ADMIN === $json['siteId'], $site_id );
    291291            $page       = $batch_options->get_page();
    292             $items      = $obj->get_items( $page, Batch_Options::DEFAULT_BATCH_SIZE );
     292            $items      = $obj->get_items( $page, \AtlasSearch\Index\get_batch_size() );
    293293        }
    294294
     
    333333            \AtlasSearch\Support\WordPress\update_option(
    334334                Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME,
    335                 new Resume_Options( $next_short_name, Batch_Options::DEFAULT_BATCH_SIZE, 1, $site_id, $progress )
     335                new Resume_Options( $next_short_name, \AtlasSearch\Index\get_batch_size(), 1, $site_id, $progress )
    336336            );
    337337
     
    362362                \AtlasSearch\Support\WordPress\update_option(
    363363                    Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME,
    364                     new Resume_Options( $short_name, Batch_Options::DEFAULT_BATCH_SIZE, $page, $batch_options->get_current_site_id(), $progress )
     364                    new Resume_Options( $short_name, \AtlasSearch\Index\get_batch_size(), $page, $batch_options->get_current_site_id(), $progress )
    365365                );
    366366
  • atlas-search/tags/0.2.57/helper/exceptions/client-query-exception.php

    r3029933 r3147520  
    55class ClientQueryException extends \ErrorException {}
    66
    7 class ClientQueryGraphqlErrorsException extends ClientQueryException {}
     7class ClientQueryGraphqlErrorsException extends ClientQueryException {
     8    public function is_access_ai_powered_search_error(): bool {
     9        return strpos( $this->getMessage(), 'To access this feature, you must upgrade to AI-Powered Search.' ) !== false;
     10    }
     11}
  • atlas-search/tags/0.2.57/helper/multisite-network-sync.php

    r3075724 r3147520  
    55use Wpe_Content_Engine\Helper\Sync\Batches\Batch_Sync_Interface;
    66
     7use const AtlasSearch\Index\BULK_INDEX_GRAPHQL;
     8use const AtlasSearch\Index\MANUAL_INDEX;
     9
    710abstract class Multisite_Network_Sync implements Batch_Sync_Interface {
     11    use Progress_Bar_Info_Trait;
    812
    913    /**
     
    3438     */
    3539    abstract protected function _get_items( $offset, $number );
    36     abstract protected function _sync( $items );
     40
     41    private function bulk_sync( $posts ) {
     42        $this->tick();
     43        \AtlasSearch\Index\bulk_index_posts( $posts );
     44        $this->finish();
     45    }
     46
     47    protected function _sync( $posts ) {
     48        if ( count( $posts ) <= 0 ) {
     49            return;
     50        }
     51
     52        $this->bulk_sync( $posts );
     53    }
    3754
    3855    /**
  • atlas-search/tags/0.2.57/helper/sync/batches/custom-post-type.php

    r3075724 r3147520  
    4040    }
    4141
    42     /**
    43      * @param WP_Post[] $custom_post_type_posts WordPress custom post types that are flagged to be showed in graphql.
    44      *
    45      * @throws ErrorException Exception.
    46      */
    47     protected function _sync( $custom_post_type_posts ) {
    48         if ( count( $custom_post_type_posts ) <= 0 ) {
    49             return;
    50         }
    51 
    52         foreach ( $custom_post_type_posts as $cpt_post ) {
    53             \AtlasSearch\Index\index_post( $cpt_post, $cpt_post->ID, \AtlasSearch\Index\MANUAL_INDEX );
    54             $this->tick();
    55         }
    56         $this->finish();
    57     }
    5842
    5943    /**
  • atlas-search/tags/0.2.57/helper/sync/batches/options/batch-options.php

    r3075724 r3147520  
    1515     * @var int
    1616     */
    17     public const DEFAULT_BATCH_SIZE = 20;
     17    public const DEFAULT_BATCH_SIZE = 10;
    1818
    1919    /**
  • atlas-search/tags/0.2.57/helper/sync/batches/page.php

    r3075724 r3147520  
    33namespace Wpe_Content_Engine\Helper\Sync\Batches;
    44
    5 use ErrorException;
    65use WP_CLI;
    76use WP_Query;
     
    1413use Wpe_Content_Engine\Helper\Progress_Bar_Info_Trait;
    1514
    16 use const AtlasSearch\Index\MANUAL_INDEX;
    1715
    1816class Page extends Multisite_Network_Sync {
     
    4139
    4240    /**
    43      * @param WP_Post[] $pages Pages.
    44      *
    45      * @throws ErrorException Exception.
    46      */
    47     protected function _sync( $pages ) {
    48         if ( count( $pages ) <= 0 ) {
    49             return;
    50         }
    51 
    52         foreach ( $pages as $page ) {
    53             \AtlasSearch\Index\index_post( $page, $page->ID, MANUAL_INDEX );
    54             $this->tick();
    55         }
    56         $this->finish();
    57     }
    58 
    59     /**
    6041     * @param mixed $items Items.
    6142     * @param mixed $page Page.
  • atlas-search/tags/0.2.57/helper/sync/batches/post.php

    r3075724 r3147520  
    33namespace Wpe_Content_Engine\Helper\Sync\Batches;
    44
    5 use ErrorException;
    65use WP_CLI;
    76use WP_Query;
     
    1110use Wpe_Content_Engine\Helper\Multisite_Network_Sync;
    1211use Wpe_Content_Engine\Helper\Progress_Bar_Info_Trait;
    13 
    14 use const AtlasSearch\Index\MANUAL_INDEX;
    1512
    1613class Post extends Multisite_Network_Sync {
     
    3633    }
    3734
    38     /**
    39      * @param WP_Post[] $posts Posts.
    40      *
    41      * @throws ErrorException Exception.
    42      */
    43     protected function _sync( $posts ) {
    44         if ( count( $posts ) <= 0 ) {
    45             return;
    46         }
    47 
    48         foreach ( $posts as $post ) {
    49             \AtlasSearch\Index\index_post( $post, $post->ID, MANUAL_INDEX );
    50             $this->tick();
    51 
    52         }
    53         $this->finish();
    54     }
    5535
    5636    /**
  • atlas-search/tags/0.2.57/helper/sync/graphql/client.php

    r3042698 r3147520  
    100100            array(
    101101                'headers'       => $headers,
    102                 'timeout'       => 20,
     102                'timeout'       => 30,
    103103                'ignore_errors' => true,
    104104                'body'          => wp_json_encode(
  • atlas-search/tags/0.2.57/includes/class-wpe-content-engine.php

    r3143797 r3147520  
    225225        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/index/post.php';
    226226        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/index/semantic-search.php';
     227        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/index/batch.php';
    227228        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/hooks/filters.php';
    228229        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/migrations/rename-post-keys-config.php';
  • atlas-search/tags/0.2.57/includes/smart-search-settings/build/asset-manifest.json

    r3143797 r3147520  
    22  "files": {
    33    "main.css": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.751d9a0b.css",
    4     "main.js": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.d2b1874d.js",
     4    "main.js": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.2259e6a0.js",
    55    "static/media/wpengine-logo.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/wpengine-logo.40f3a1215fbea4708a6a4bff9624fece.svg",
    66    "static/media/content-copy.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/content-copy.e50f17791e757794684afc63d5d4cb00.svg",
     
    1818    "index.html": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/index.html",
    1919    "main.751d9a0b.css.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.751d9a0b.css.map",
    20     "main.d2b1874d.js.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.d2b1874d.js.map"
     20    "main.2259e6a0.js.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.2259e6a0.js.map"
    2121  },
    2222  "entrypoints": [
    2323    "static/css/main.751d9a0b.css",
    24     "static/js/main.d2b1874d.js"
     24    "static/js/main.2259e6a0.js"
    2525  ]
    2626}
  • atlas-search/tags/0.2.57/includes/smart-search-settings/build/index.html

    r3143797 r3147520  
    1 <head><script defer="defer" src="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.d2b1874d.js"></script><link href="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.751d9a0b.css" rel="stylesheet"></head>
     1<head><script defer="defer" src="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.2259e6a0.js"></script><link href="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.751d9a0b.css" rel="stylesheet"></head>
  • atlas-search/tags/0.2.57/src/index/post.php

    r3143797 r3147520  
    4747GRAPHQL;
    4848
     49const BULK_INDEX_GRAPHQL = <<<'GRAPHQL'
     50mutation BulkIndex($docs: [DocumentInput!], $meta: MetaInput) {
     51  bulkIndex(input: {
     52    documents: $docs
     53    meta: $meta
     54  }) {
     55    code
     56  }
     57}
     58GRAPHQL;
     59
    4960
    5061function format_date( $date ) {
     
    6475 */
    6576function index_post( WP_Post $post, int $post_id, string $index_type = AUTOMATIC_INDEX ) {
    66     // bring the blocking states.
     77    $data = prepare_post( $post, $post_id, $index_type );
     78
     79    if ( false === $data ) {
     80        return false;
     81    }
     82    return graphql( INDEX_GRAPHQL, $data );
     83}
     84
     85/**
     86 * Indexes a list of WP_Posts
     87 *
     88 * @param WP_Post[] $posts The posts.
     89 * @return mixed
     90 */
     91function bulk_index_posts( $posts ) {
     92    $posts_to_index = array();
     93
     94    foreach ( $posts as $post ) {
     95        $posts_to_index[] = prepare_post( $post, $post->ID, MANUAL_INDEX )['input'];
     96    }
     97
     98    // Index the posts.
     99    $variables = array(
     100        'docs' => $posts_to_index,
     101        'meta' => array(
     102            'system' => \AtlasSearch\Meta\get_system_version(),
     103            'action' => MANUAL_INDEX . ':bulk-index:' . $post->post_type . ':count=' . count( $posts_to_index ),
     104            'source' => \AtlasSearch\Meta\get_domain_name(),
     105        ),
     106    );
     107
     108    return graphql( BULK_INDEX_GRAPHQL, $variables );
     109}
     110
     111/**
     112 * Prepare a post for indexing.
     113 *
     114 * @param WP_Post $post The post.
     115 * @param int     $post_id The post id.
     116 * @param string  $index_type The index operation type.
     117 * @return array|bool
     118 */
     119function prepare_post( WP_Post $post, int $post_id, string $index_type = AUTOMATIC_INDEX ) {
    67120    if ( false === is_allowed( $post ) ) {
    68121        return false;
     
    98151    $post_array = \AtlasSearch\Hooks\filter_extra_fields( $post_array, $post );
    99152
    100     $variables = array(
     153    return array(
    101154        'input' => array(
    102155            'id'   => \AtlasSearch\Hooks\filter_index_id( $post->post_type, $post_id ),
     
    109162        ),
    110163    );
    111 
    112     return graphql( INDEX_GRAPHQL, $variables );
    113164}
    114165
  • atlas-search/tags/0.2.57/src/query/meta.php

    r3143797 r3147520  
    141141
    142142    if ( 'LIKE' === $compare || 'NOT LIKE' === $compare ) {
    143         return '*' . $value . '*';
     143        switch ( str_word_count( $value ) ) {
     144            case 1:
     145                return '*' . $value . '*';
     146            default:
     147                return '"*' . $value . '*"';
     148        }
    144149    }
    145150
  • atlas-search/trunk/README.txt

    r3143797 r3147520  
    33Tested up to: 6.6
    44Requires PHP: 7.4
    5 Stable tag: 0.2.56
     5Stable tag: 0.2.57
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4848
    4949== Changelog ==
     50= 0.2.57 =
     51* **Added:** Bulk indexing support.
     52* **Updated:** wp-cli command which now takes into account multisite
     53* **Added:** Improved WP_Meta_Query mappings for the LIKE operator.
     54
    5055= 0.2.56 =
    5156* **Added:** WP_Meta_Query support.
  • atlas-search/trunk/atlas-search.php

    r3143797 r3147520  
    1616 * Plugin URI:        https://developers.wpengine.com/
    1717 * Description:       Searching WordPress data with WP Engine Smart Search.
    18  * Version:           0.2.56
     18 * Version:           0.2.57
    1919 * Author:            WP Engine
    2020 * Author URI:        https://wpengine.com/
     
    4141 * Rename this for your plugin and update it as you release new versions.
    4242 */
    43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.56' );
     43define( 'WPE_SMART_SEARCH_VERSION', '0.2.57' );
    4444
    4545/**
  • atlas-search/trunk/commands/class-wpe-content-engine-sync-data.php

    r3075724 r3147520  
    55}
    66
    7 use Wpe_Content_Engine\Core_Wp_Wrapper\Wp_Progress_Bar;
    8 use Wpe_Content_Engine\Helper\Progress_Bar_Info_Trait;
    9 use Wpe_Content_Engine\Helper\Sync\Batches\Batch_Sync_Factory;
    10 use Wpe_Content_Engine\Helper\Sync\Batches\Options\Batch_Options;
    11 use Wpe_Content_Engine\Helper\Sync\Batches\Options\Resume_Options;
    12 use Wpe_Content_Engine\Helper\Sync\Batches\Sync_Lock_Manager;
    13 use Wpe_Content_Engine\Helper\Sync\Batches\Batch_Sync_Interface;
    14 use const AtlasSearch\Index\MANUAL_INDEX;
    15 use const Wpe_Content_Engine\Helper\Notifications\WPE_CONTENT_ENGINE_RE_SYNC_HAS_OCCURRED;
    16 
    17 // @codingStandardsIgnoreStart
     7use Wpe_Content_Engine\WPSettings;
    188
    199/**
     
    2111 */
    2212class Wpe_Content_Engine_Sync_Data {
    23 
     13    private $start_time;
    2414    /**
    2515     * Syncs all data to Smart Search.
    2616     *
    2717     * ## EXAMPLES
    28      *    wp wpe-smart-search sync-data --size=10 --no-resume
    29      *    or
    3018     *    wp wpe-smart-search sync-data
    3119     *    or
    3220     *    wp wpe-smart-search sync-data --reset
    33      *
    34      * [--size=<batch-size>]
    35      * : Used to sync ALL data in batches of <batch-size>. Batch size should be a positive integer.
    36      * If is set to a very big integer the system might run out of memory or fail to sync all data.
    37      * If no value is specified then defaults to 20
    38      *
    39      * [--no-resume]
    40      * : Start sync from the start and not from last error
    41      * default: true
    4221     *
    4322     * [--reset]
     
    4524     * default: false
    4625     *
     26     * [--site-id]
     27     * : Site ID to sync data for
     28     * default: current site or network admin if in multi-site mode
     29     * options: <site-id> | network
     30     *
    4731     * @subcommand sync-data
    4832     * @when after_wp_load
    4933     *
     34     * @param array $args    Command arguments.
     35     * @param array $assoc_args Command associative arguments.
    5036     */
     37    public function _sync_data( $args, $assoc_args ) {
     38        try {
     39            $this->start_time = time();
     40            $client           = new \Wpe_Content_Engine\Helper\Sync\GraphQL\Client( Wpe_Content_Engine::get_plugin_name(), Wpe_Content_Engine::get_version() );
     41            $controller       = new \Wpe_Content_Engine\Helper\API\Sync_Data\Sync_Data_Controller( $client, new WPSettings() );
    5142
    52     public function _sync_data( $args, $assoc_args ) {
    53         $batch_size = (int) ( $assoc_args['size'] ?? Batch_Options::DEFAULT_BATCH_SIZE );
     43            $reset = $assoc_args['reset'] ?? false;
     44            if ( $reset ) {
     45                WP_CLI::line( 'Clearing all data.' );
     46                $result = $controller->delete_sync_data( new WP_REST_Request( 'DELETE' ) );
     47                if ( 200 !== $result->status ) {
     48                    WP_CLI::error( 'Failed to clear data.' );
     49                }
     50                WP_CLI::line( $result->data['message'] );
     51            }
    5452
    55         if ( $batch_size <= 0 ) {
    56             WP_CLI::error( 'Batch size should be an integer greater than zero' );
    57             return;
     53            $site_id_arg = $assoc_args['site-id'] ?? false;
     54            $site_id     = $this->parse_site_id( $site_id_arg );
     55            $uuid        = '';
     56            /**
     57             * @var \Wpe_Content_Engine\Helper\API\Sync_Data\Response $result
     58             */
     59            $result = $this->perform_index( $controller, $uuid, $site_id );
     60
     61            $this->display_progress_bar( $result->message ?? '', $result->progress, 100 );
     62
     63            while ( \Wpe_Content_Engine\Helper\Constants\Sync_Response_Status::PENDING === $result->status ) {
     64                $result = $this->perform_index( $controller, $result->uuid, $site_id );
     65                if ( \Wpe_Content_Engine\Helper\Constants\Sync_Response_Status::COMPLETED === $result->status ) {
     66                    break;
     67                } else {
     68                    $this->display_progress_bar( $result->message ?? '', $result->progress, 100 );
     69                }
     70            }
     71            WP_CLI::log( "\r\nIndexing completed!" );
     72        } catch ( \Exception $e ) {
     73            WP_CLI::error( $e->getMessage() );
     74        }
     75    }
     76
     77    private function perform_index( $controller, $uuid, $site_id ) {
     78        $rest_request = new WP_REST_Request( 'POST', '/wpe-content-engine/v1/sync-data' );
     79            $rest_request->set_body(
     80                wp_json_encode(
     81                    array(
     82                        'uuid'   => $uuid,
     83                        'siteId' => $site_id,
     84                    )
     85                )
     86            );
     87            $rest_request->set_headers(
     88                array(
     89                    'Content-Type' => 'application/json',
     90                ),
     91            );
     92            return $controller->sync_data( $rest_request );
     93    }
     94
     95    private function parse_site_id( $site_id ) {
     96        if ( 'network' === $site_id ) {
     97            return \AtlasSearch\Support\WordPress\NETWORK_ADMIN;
     98        } elseif ( $site_id ) {
     99            return $site_id;
     100        } elseif ( is_multisite() ) {
     101            return \AtlasSearch\Support\WordPress\NETWORK_ADMIN;
     102        } else {
     103            return (string) get_current_blog_id();
     104        }
     105    }
     106
     107    private function display_progress_bar( string $message, int $current, int $total, int $length = 50 ) {
     108        if ( 0 === $current ) {
     109            $current = 1;
    58110        }
    59111
    60         $with_reset = $assoc_args['reset'] ?? false;
    61         $with_resume = $assoc_args['resume'] ?? true;
     112        $percent      = floor( ( $current * 100 ) / $total );
     113        $progress_bar = floor( ( $length * $percent ) / 100 );
    62114
    63         $batch_options = new Batch_Options(
    64             $batch_size,
    65             1,
    66             Batch_Sync_Factory::DATA_TO_SYNC,
    67             array( get_current_blog_id() )
     115        // Calculate elapsed time.
     116        $elapsed_time = time() - $this->start_time;
     117
     118        // Estimate remaining time.
     119        $estimated_total_time = ( $elapsed_time / $current ) * $total;
     120        $remaining_time       = $estimated_total_time - $elapsed_time;
     121
     122        // Format remaining time.
     123        $remaining_minutes        = floor( $remaining_time / 60 );
     124        $remaining_seconds        = $remaining_time % 60;
     125        $remaining_time_formatted = sprintf( '%02d:%02d', $remaining_minutes, $remaining_seconds );
     126
     127        printf(
     128            "  %s%% [%s>%s] %s/%s | ETA: %s | %s\r",
     129            esc_html( $percent ),
     130            esc_html( str_repeat( '=', $progress_bar ) ),
     131            esc_html( str_repeat( ' ', $length - $progress_bar ) ),
     132            esc_html( $current ),
     133            esc_html( $total ),
     134            esc_html( $remaining_time_formatted ),
     135            esc_html( $message . str_repeat( ' ', 20 ) ),
    68136        );
     137    }
    69138
    70         /** @var Resume_Options|null $resume_options */
    71         $resume_options = get_option( Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME, null );
     139}
    72140
    73         if ( $with_resume && !$with_reset && !empty( $resume_options ) && ( $resume_options instanceof Resume_Options ) ) {
    74             $batch_options->calculate_with_resume( $resume_options );
    75 
    76             WP_CLI::log(
    77                 "Resume started! Starting with these parameters --> Table:{$resume_options->get_entity()}, "
    78                 . " Page: {$batch_options->get_page()}, Batch Size: {$batch_options->get_batch_size()}"
    79             );
    80         }
    81 
    82         $sync_lock_manager = new Sync_Lock_Manager();
    83         $uuid = null;
    84 
    85         try {
    86             $time_start = new DateTime();
    87             $start = microtime(true);
    88 
    89             $moment = new DateTime();
    90             $can_start = $sync_lock_manager->can_start( $moment );
    91             $cannot_start_text = !$can_start ? 'yes' : 'no';
    92             WP_CLI::log( "Init check, lock present: {$cannot_start_text}" );
    93 
    94             if ( $can_start ) {
    95                 // activate
    96                 WP_CLI::log( "No lock present, starting sync..." );
    97                 $uuid = $sync_lock_manager->start( $moment, null );
    98                 WP_CLI::log( "Sync lock acquired. Sync lock ID: {$uuid}" );
    99             }
    100             else {
    101                 WP_CLI::log( "Lock active! Cannot start a new sync! Exiting..." );
    102                 return;
    103             }
    104 
    105             delete_option( Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME );
    106 
    107             if ( $with_reset ) {
    108                 WP_CLI::log( "'--reset' flag was provided. Deleting all.");
    109                 \AtlasSearch\Index\delete_all( MANUAL_INDEX );
    110             }
    111 
    112             foreach ( $batch_options->get_data_to_be_synced() as $short_name => $class ) {
    113 
    114                 /** @var Batch_Sync_Interface| Progress_Bar_Info_Trait $obj ,
    115                  * @var string $class
    116                  */
    117                 $obj = Batch_Sync_Factory::build( $class );
    118                 $page = $batch_options->get_page();
    119                 WP_CLI::log( "Sync started : {$short_name}" );
    120 
    121                 do {
    122                     try {
    123                         $items = $obj->get_items( $page, $batch_size );
    124 
    125                         if ( empty( $items ) ) {
    126                             continue;
    127                         }
    128 
    129                         $obj->format_items( $items, $page );
    130                         $obj->set_progress_bar( new Wp_Progress_Bar( count( $items ) ) );
    131                         $obj->sync( $items );
    132                         $page ++;
    133                     } catch ( ErrorException $e ) {
    134                         WP_CLI::error( "Something went wrong. Error message: {$e->getMessage()}", false );
    135                     } finally {
    136                         update_option(
    137                             Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME,
    138                             new Resume_Options( $short_name, $batch_size, $page )
    139                         );
    140 
    141                         if ( isset( $e ) && ( $e instanceof ErrorException ) ) {
    142                             /** @var ErrorException|null $e */
    143                             throw $e;
    144                         }
    145                     }
    146                 } while ( count( $items ) >= $batch_size );
    147 
    148                 $batch_options->set_page( 1 );
    149 
    150                 WP_CLI::log(
    151                     empty( $obj->get_items( 1, $batch_size ) ) ? "No {$short_name} data to sync" : "Sync Success: {$short_name}"
    152                 );
    153 
    154                 update_option( WPE_CONTENT_ENGINE_RE_SYNC_HAS_OCCURRED, true );
    155             }
    156 
    157             delete_option( Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME );
    158             WP_CLI::log( 'Success syncing all data' );
    159 
    160             $fd = ( new DateTime() )->diff( $time_start );
    161             WP_CLI::log( WP_CLI::colorize( "%GTotal time: {$fd->format('%H:%i:%s.%f')}%n " ) );
    162         } catch ( ErrorException $e ) {
    163             WP_CLI::error( "There was an error during sync. Error message: {$e->getMessage()}", false );
    164         }
    165         finally {
    166             // make sure that we always release the lock if we acquired one this run.
    167             if ( !empty( $uuid ) ) {
    168                 $moment = new DateTime();
    169                 $sync_lock_manager->finish( $moment, $uuid );
    170                 WP_CLI::log( "Sync lock ID {$uuid} released!" );
    171             }
    172             else {
    173                 WP_CLI::log( 'No sync lock acquired this run.!' );
    174             }
    175         }
    176     }
    177 }
    178141WP_CLI::add_command( 'wpe-smart-search', 'Wpe_Content_Engine_Sync_Data' );
    179 
    180 // @codingStandardsIgnoreEnd
  • atlas-search/trunk/helper/api/sync-data/sync-data-controller.php

    r3116529 r3147520  
    106106        $site_ids      = $this->get_site_ids( \AtlasSearch\Support\WordPress\NETWORK_ADMIN === $json['siteId'] );
    107107        $batch_options = new Batch_Options(
    108             Batch_Options::DEFAULT_BATCH_SIZE,
     108            \AtlasSearch\Index\get_batch_size(),
    109109            1,
    110110            Batch_Sync_Factory::DATA_TO_SYNC,
     
    290290            $obj        = Batch_Sync_Factory::build( $current_data['class'], \AtlasSearch\Support\WordPress\NETWORK_ADMIN === $json['siteId'], $site_id );
    291291            $page       = $batch_options->get_page();
    292             $items      = $obj->get_items( $page, Batch_Options::DEFAULT_BATCH_SIZE );
     292            $items      = $obj->get_items( $page, \AtlasSearch\Index\get_batch_size() );
    293293        }
    294294
     
    333333            \AtlasSearch\Support\WordPress\update_option(
    334334                Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME,
    335                 new Resume_Options( $next_short_name, Batch_Options::DEFAULT_BATCH_SIZE, 1, $site_id, $progress )
     335                new Resume_Options( $next_short_name, \AtlasSearch\Index\get_batch_size(), 1, $site_id, $progress )
    336336            );
    337337
     
    362362                \AtlasSearch\Support\WordPress\update_option(
    363363                    Batch_Options::OPTIONS_WPE_CONTENT_ENGINE_SYNC_RESUME,
    364                     new Resume_Options( $short_name, Batch_Options::DEFAULT_BATCH_SIZE, $page, $batch_options->get_current_site_id(), $progress )
     364                    new Resume_Options( $short_name, \AtlasSearch\Index\get_batch_size(), $page, $batch_options->get_current_site_id(), $progress )
    365365                );
    366366
  • atlas-search/trunk/helper/exceptions/client-query-exception.php

    r3029933 r3147520  
    55class ClientQueryException extends \ErrorException {}
    66
    7 class ClientQueryGraphqlErrorsException extends ClientQueryException {}
     7class ClientQueryGraphqlErrorsException extends ClientQueryException {
     8    public function is_access_ai_powered_search_error(): bool {
     9        return strpos( $this->getMessage(), 'To access this feature, you must upgrade to AI-Powered Search.' ) !== false;
     10    }
     11}
  • atlas-search/trunk/helper/multisite-network-sync.php

    r3075724 r3147520  
    55use Wpe_Content_Engine\Helper\Sync\Batches\Batch_Sync_Interface;
    66
     7use const AtlasSearch\Index\BULK_INDEX_GRAPHQL;
     8use const AtlasSearch\Index\MANUAL_INDEX;
     9
    710abstract class Multisite_Network_Sync implements Batch_Sync_Interface {
     11    use Progress_Bar_Info_Trait;
    812
    913    /**
     
    3438     */
    3539    abstract protected function _get_items( $offset, $number );
    36     abstract protected function _sync( $items );
     40
     41    private function bulk_sync( $posts ) {
     42        $this->tick();
     43        \AtlasSearch\Index\bulk_index_posts( $posts );
     44        $this->finish();
     45    }
     46
     47    protected function _sync( $posts ) {
     48        if ( count( $posts ) <= 0 ) {
     49            return;
     50        }
     51
     52        $this->bulk_sync( $posts );
     53    }
    3754
    3855    /**
  • atlas-search/trunk/helper/sync/batches/custom-post-type.php

    r3075724 r3147520  
    4040    }
    4141
    42     /**
    43      * @param WP_Post[] $custom_post_type_posts WordPress custom post types that are flagged to be showed in graphql.
    44      *
    45      * @throws ErrorException Exception.
    46      */
    47     protected function _sync( $custom_post_type_posts ) {
    48         if ( count( $custom_post_type_posts ) <= 0 ) {
    49             return;
    50         }
    51 
    52         foreach ( $custom_post_type_posts as $cpt_post ) {
    53             \AtlasSearch\Index\index_post( $cpt_post, $cpt_post->ID, \AtlasSearch\Index\MANUAL_INDEX );
    54             $this->tick();
    55         }
    56         $this->finish();
    57     }
    5842
    5943    /**
  • atlas-search/trunk/helper/sync/batches/options/batch-options.php

    r3075724 r3147520  
    1515     * @var int
    1616     */
    17     public const DEFAULT_BATCH_SIZE = 20;
     17    public const DEFAULT_BATCH_SIZE = 10;
    1818
    1919    /**
  • atlas-search/trunk/helper/sync/batches/page.php

    r3075724 r3147520  
    33namespace Wpe_Content_Engine\Helper\Sync\Batches;
    44
    5 use ErrorException;
    65use WP_CLI;
    76use WP_Query;
     
    1413use Wpe_Content_Engine\Helper\Progress_Bar_Info_Trait;
    1514
    16 use const AtlasSearch\Index\MANUAL_INDEX;
    1715
    1816class Page extends Multisite_Network_Sync {
     
    4139
    4240    /**
    43      * @param WP_Post[] $pages Pages.
    44      *
    45      * @throws ErrorException Exception.
    46      */
    47     protected function _sync( $pages ) {
    48         if ( count( $pages ) <= 0 ) {
    49             return;
    50         }
    51 
    52         foreach ( $pages as $page ) {
    53             \AtlasSearch\Index\index_post( $page, $page->ID, MANUAL_INDEX );
    54             $this->tick();
    55         }
    56         $this->finish();
    57     }
    58 
    59     /**
    6041     * @param mixed $items Items.
    6142     * @param mixed $page Page.
  • atlas-search/trunk/helper/sync/batches/post.php

    r3075724 r3147520  
    33namespace Wpe_Content_Engine\Helper\Sync\Batches;
    44
    5 use ErrorException;
    65use WP_CLI;
    76use WP_Query;
     
    1110use Wpe_Content_Engine\Helper\Multisite_Network_Sync;
    1211use Wpe_Content_Engine\Helper\Progress_Bar_Info_Trait;
    13 
    14 use const AtlasSearch\Index\MANUAL_INDEX;
    1512
    1613class Post extends Multisite_Network_Sync {
     
    3633    }
    3734
    38     /**
    39      * @param WP_Post[] $posts Posts.
    40      *
    41      * @throws ErrorException Exception.
    42      */
    43     protected function _sync( $posts ) {
    44         if ( count( $posts ) <= 0 ) {
    45             return;
    46         }
    47 
    48         foreach ( $posts as $post ) {
    49             \AtlasSearch\Index\index_post( $post, $post->ID, MANUAL_INDEX );
    50             $this->tick();
    51 
    52         }
    53         $this->finish();
    54     }
    5535
    5636    /**
  • atlas-search/trunk/helper/sync/graphql/client.php

    r3042698 r3147520  
    100100            array(
    101101                'headers'       => $headers,
    102                 'timeout'       => 20,
     102                'timeout'       => 30,
    103103                'ignore_errors' => true,
    104104                'body'          => wp_json_encode(
  • atlas-search/trunk/includes/class-wpe-content-engine.php

    r3143797 r3147520  
    225225        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/index/post.php';
    226226        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/index/semantic-search.php';
     227        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/index/batch.php';
    227228        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/hooks/filters.php';
    228229        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'src/migrations/rename-post-keys-config.php';
  • atlas-search/trunk/includes/smart-search-settings/build/asset-manifest.json

    r3143797 r3147520  
    22  "files": {
    33    "main.css": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.751d9a0b.css",
    4     "main.js": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.d2b1874d.js",
     4    "main.js": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.2259e6a0.js",
    55    "static/media/wpengine-logo.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/wpengine-logo.40f3a1215fbea4708a6a4bff9624fece.svg",
    66    "static/media/content-copy.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/content-copy.e50f17791e757794684afc63d5d4cb00.svg",
     
    1818    "index.html": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/index.html",
    1919    "main.751d9a0b.css.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.751d9a0b.css.map",
    20     "main.d2b1874d.js.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.d2b1874d.js.map"
     20    "main.2259e6a0.js.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.2259e6a0.js.map"
    2121  },
    2222  "entrypoints": [
    2323    "static/css/main.751d9a0b.css",
    24     "static/js/main.d2b1874d.js"
     24    "static/js/main.2259e6a0.js"
    2525  ]
    2626}
  • atlas-search/trunk/includes/smart-search-settings/build/index.html

    r3143797 r3147520  
    1 <head><script defer="defer" src="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.d2b1874d.js"></script><link href="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.751d9a0b.css" rel="stylesheet"></head>
     1<head><script defer="defer" src="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.2259e6a0.js"></script><link href="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.751d9a0b.css" rel="stylesheet"></head>
  • atlas-search/trunk/src/index/post.php

    r3143797 r3147520  
    4747GRAPHQL;
    4848
     49const BULK_INDEX_GRAPHQL = <<<'GRAPHQL'
     50mutation BulkIndex($docs: [DocumentInput!], $meta: MetaInput) {
     51  bulkIndex(input: {
     52    documents: $docs
     53    meta: $meta
     54  }) {
     55    code
     56  }
     57}
     58GRAPHQL;
     59
    4960
    5061function format_date( $date ) {
     
    6475 */
    6576function index_post( WP_Post $post, int $post_id, string $index_type = AUTOMATIC_INDEX ) {
    66     // bring the blocking states.
     77    $data = prepare_post( $post, $post_id, $index_type );
     78
     79    if ( false === $data ) {
     80        return false;
     81    }
     82    return graphql( INDEX_GRAPHQL, $data );
     83}
     84
     85/**
     86 * Indexes a list of WP_Posts
     87 *
     88 * @param WP_Post[] $posts The posts.
     89 * @return mixed
     90 */
     91function bulk_index_posts( $posts ) {
     92    $posts_to_index = array();
     93
     94    foreach ( $posts as $post ) {
     95        $posts_to_index[] = prepare_post( $post, $post->ID, MANUAL_INDEX )['input'];
     96    }
     97
     98    // Index the posts.
     99    $variables = array(
     100        'docs' => $posts_to_index,
     101        'meta' => array(
     102            'system' => \AtlasSearch\Meta\get_system_version(),
     103            'action' => MANUAL_INDEX . ':bulk-index:' . $post->post_type . ':count=' . count( $posts_to_index ),
     104            'source' => \AtlasSearch\Meta\get_domain_name(),
     105        ),
     106    );
     107
     108    return graphql( BULK_INDEX_GRAPHQL, $variables );
     109}
     110
     111/**
     112 * Prepare a post for indexing.
     113 *
     114 * @param WP_Post $post The post.
     115 * @param int     $post_id The post id.
     116 * @param string  $index_type The index operation type.
     117 * @return array|bool
     118 */
     119function prepare_post( WP_Post $post, int $post_id, string $index_type = AUTOMATIC_INDEX ) {
    67120    if ( false === is_allowed( $post ) ) {
    68121        return false;
     
    98151    $post_array = \AtlasSearch\Hooks\filter_extra_fields( $post_array, $post );
    99152
    100     $variables = array(
     153    return array(
    101154        'input' => array(
    102155            'id'   => \AtlasSearch\Hooks\filter_index_id( $post->post_type, $post_id ),
     
    109162        ),
    110163    );
    111 
    112     return graphql( INDEX_GRAPHQL, $variables );
    113164}
    114165
  • atlas-search/trunk/src/query/meta.php

    r3143797 r3147520  
    141141
    142142    if ( 'LIKE' === $compare || 'NOT LIKE' === $compare ) {
    143         return '*' . $value . '*';
     143        switch ( str_word_count( $value ) ) {
     144            case 1:
     145                return '*' . $value . '*';
     146            default:
     147                return '"*' . $value . '*"';
     148        }
    144149    }
    145150
Note: See TracChangeset for help on using the changeset viewer.