Автор: Mikael Mattsson (mikael@wallmanderco.se)
Пример #1
0
 /**
  * @param int|null $blogID
  *
  * @return string
  */
 public function getIndexName($blogID = null)
 {
     if ($blogID === null) {
         $blogID = $this->blogID;
     }
     return Config::getIndexName($blogID);
 }
 /**
  * Hooked on plugin activation.
  */
 public static function actionActivate()
 {
     $logDir = ESI_PATH . '../../uploads/logs/';
     if (!file_exists($logDir)) {
         mkdir($logDir, 0777, true);
     }
     Config::getIndexName(get_current_blog_id());
     // Will generate a name if not set.
 }
 /**
  * Send a simple put request to the Elasticsearch server.
  *
  * @param $uri
  * @param array $data
  *
  * @return \Guzzle\Http\Message\Response
  */
 public static function httpPut($uri, $data = null)
 {
     $client = new HttpClient();
     $host = Config::getFirstHost();
     if ($data) {
         $data = json_encode($data);
     }
     return $client->put($host . '/' . $uri, null, $data)->send();
 }
 /**
  * Filter query string used for get_posts(). Search for posts and save for later.
  * Return a query that will return nothing.
  *
  * @param string    $request
  * @param \WP_Query $query
  *
  * @return string
  */
 public static function filterPostsRequest($request, WP_Query $query)
 {
     if (apply_filters('esi_skip_query_integration', false, $query)) {
         return $request;
     }
     if (!$query->is_search() && !Config::enabledFullIntegration()) {
         $query->is_elasticsearch_compatible = false;
         return $request;
     }
     if (!WpConverter::isCompatible($query)) {
         $query->is_elasticsearch_compatible = false;
         return $request;
     }
     $query->is_elasticsearch_compatible = true;
     global $wpdb;
     return "SELECT * FROM {$wpdb->posts} WHERE 1=0";
 }
<?php

/*
 * This file is part of Elasticsearch Indexer.
 *
 * (c) Wallmander & Co <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use Wallmander\ElasticsearchIndexer\Model\Config;
return ['index' => ['number_of_shards' => (int) Config::option('shards'), 'number_of_replicas' => (int) Config::option('replicas')], 'analysis' => ['analyzer' => ['esi_search_analyzer' => ['type' => 'custom', 'tokenizer' => 'standard', 'filter' => ['standard', 'lowercase', 'stop', 'esi_ngram', 'esi_snowball'], 'language' => apply_filters('esi_analyzer_language', 'English')], 'esi_index_analyzer' => ['type' => 'custom', 'tokenizer' => 'keyword', 'filter' => ['standard', 'lowercase']], 'esi_simple_analyzer' => ['type' => 'custom', 'tokenizer' => 'standard', 'filter' => ['standard', 'lowercase', 'keyword_repeat', 'porter_stem']]], 'filter' => ['esi_ngram' => ['type' => 'nGram', 'min_gram' => 3, 'max_gram' => 20], 'esi_snowball' => ['type' => 'snowball', 'language' => apply_filters('esi_analyzer_language', 'English')]]]];
Пример #6
0
 private static function getStatusText()
 {
     if (!Elasticsearch::isAvailable()) {
         return ['Unable to connect', '#e14d43'];
     }
     if (Config::option('user_index_version') < Config::option('plugin_index_version')) {
         return ['Reindex required', '#e14d43'];
     }
     if ($time = Config::option('is_indexing')) {
         if ($time + 20 < time()) {
             return ['Indexing process interrupted', '#e14d43'];
         }
         return ['Indexing...', '#ccaf0b'];
     }
     if (!Config::option('enable_integration')) {
         return ['Disabled Integration', '#999'];
     }
     return ['Enabled', '#a3b745'];
 }
Пример #7
0
 /**
  * @return array
  */
 public static function getIndexablePostStati()
 {
     if (Config::option('index_private_post_types')) {
         return get_post_stati();
     }
     return get_post_stati(['exclude_from_search' => false]);
 }
Пример #8
0
 /**
  * Setup WooCommerceAdmin hooks.
  */
 public static function setupWooCommerceAdmin()
 {
     if (!class_exists('WooCommerce') || !Config::option('index_private_post_types')) {
         return;
     }
     $class = __NAMESPACE__ . '\\Controller\\WooCommerceAdmin';
     $class = apply_filters('esi_controller_woocommerceadmin', $class);
     add_filter('esi_post_sync_args', [$class, 'filterPostSyncArgs'], 10, 2);
     if (Config::enabledFullIntegration()) {
         static::forceRemoveAction('parse_query', 'shop_order_search_custom_fields');
         add_action('esi_after_format_args', [$class, 'actionOrderSearch']);
     }
 }
Пример #9
0
                </td>
            </tr>
            <tr valign="top">
                <th>Enable Profiler Admin</th>
                <td>
                    <input type="hidden" name="<?php 
echo Config::optionKey('profile_admin');
?>
"
                           value="0"/>
                    <input type="checkbox" name="<?php 
echo Config::optionKey('profile_admin');
?>
"
                           value="1" <?php 
echo Config::option('profile_admin') ? 'checked="checked"' : '';
?>
/>

                    <p class="description"></p>
                </td>
            </tr>
        </table>

        <?php 
submit_button();
?>

    </form>
</div>