Plugin Directory

Changeset 1817832


Ignore:
Timestamp:
02/08/2018 03:45:29 AM (8 years ago)
Author:
ktou
Message:

Import 0.1.1

Location:
mroonga/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • mroonga/trunk/mroonga.php

    r1714411 r1817832  
    44Plugin URI: https://github.com/mroonga/wordpress-mroonga
    55Description: This plugin provides fast and rich full text search features based on Mroonga. Mroonga is a MySQL/MariaDB plugin. You don't need to add a new server only for full text search. You can use existing MySQL/MariaDB server. It reduces maintainance cost.
    6 Version: 0.1.0
     6Version: 0.1.1
    77Author: Yasuhiro Horimoto
    88Author URI: https://www.clear-code.com/
     
    1212class MroongaSearch
    1313{
     14
     15  private $textdomain = "mroonga";
     16  private $mroonga_install_doc = "http://mroonga.org/docs/install.html";
     17
    1418  public function table_name()
    1519  {
     
    1721
    1822    return $wpdb->prefix . "mrn_posts";
     23  }
     24
     25  public function __construct()
     26  {
     27    load_plugin_textdomain( $this->textdomain, false, dirname( plugin_basename( __FILE__ ) ) . "/languages"  );
    1928  }
    2029
     
    3645    global $wpdb;
    3746
    38     if ($wpdb->query("SELECT name FROM mysql.plugin "
    39                      . "WHERE name = 'Mroonga'") > 0) {
    40       return;
     47    $is_mroonga_installed =
     48      $wpdb->get_var( "SELECT COUNT(*) FROM INFORMATION_SCHEMA.PLUGINS "
     49                      . " WHERE PLUGIN_NAME = 'Mroonga'" );
     50    if ( ! $is_mroonga_installed ) {
     51      $message  = __( "Mroonga is not installed on your DB Server.",
     52                      $this->textdomain );
     53      $message .= " ";
     54      $message .= sprintf( __( "Please install Mroonga refer to %s.",
     55                               $this->textdomain ),
     56                           $this->mroonga_install_doc );
     57      exit( $messagee );
    4158    }
    42 
    43     $wpdb->query("INSTALL PLUGIN Mroonga SONAME 'ha_mroonga.so'");
    44     // TODO Report error on failure
    4559  }
    4660
     
    6276    global $wpdb;
    6377
    64     $wpdb->query("INSERT INTO {$this->table_name()} "
    65                  . "(post_id, post_title, post_content) "
    66                  . "SELECT ID, post_title, post_content "
    67                  . "FROM {$wpdb->posts} "
    68                  . "WHERE post_status = 'publish'");
     78    if ( $post_types = $this->get_search_post_types() ) {
     79      $post_types = esc_sql( $post_types );
     80      $post_type_in_string = "'" . implode( "','", $post_types ) . "'";
     81      $wpdb->query("INSERT INTO {$this->table_name()} "
     82                   . "(post_id, post_title, post_content) "
     83                   . "SELECT ID, post_title, post_content "
     84                   . "FROM {$wpdb->posts} "
     85                   . "WHERE post_status IN ('publish', 'private') "
     86                   . "AND post_type IN ($post_type_in_string)");
     87    }
    6988  }
    7089
     
    83102    global $wpdb;
    84103
    85     $wpdb->query("DROP TABLE {$this->table_name()}");
     104    $wpdb->query("DROP TABLE IF EXISTS {$this->table_name()}");
     105  }
     106
     107  private function get_search_post_types ()
     108  {
     109    $post_types = get_post_types( array( "exclude_from_search" => false ) );
     110    return apply_filters( "mroonga_search_post_types", $post_types );
    86111  }
    87112
     
    90115    global $wpdb;
    91116
    92     $wpdb->replace($this->table_name(),
    93                    array("post_id" => $post_id,
    94                          "post_title" => $post->post_title,
    95                          "post_content" => $post->post_content));
     117    if ( in_array( $post->post_status, array( "publish", "private" ) ) && in_array( $post->post_type, $this->get_search_post_types() ) ) {
     118      $wpdb->replace($this->table_name(),
     119        array(
     120          "post_id" => $post_id,
     121          "post_title" => $post->post_title,
     122          "post_content" => $post->post_content
     123        )
     124      );
     125    }
    96126  }
    97127
    98128  public function fulltext_search($search, $wp_query)
    99129  {
    100     return '';
     130    return "";
    101131  }
    102132
     
    129159    if (strlen($search_query) > 0)
    130160    {
    131       $orderby = 'score DESC';
     161      $orderby = "score DESC";
    132162    }
    133163    return $orderby;
    134164  }
     165
     166  public function after_delete_post ( $post_id )
     167  {
     168    global $wpdb;
     169    $wpdb->delete( $this->table_name(), array( "post_id" => $post_id ) );
     170  }
     171
    135172}
    136173
    137174$MroongaSearch = new MroongaSearch();
    138175
    139 register_activation_hook(__FILE__, array($MroongaSearch, 'activate'));
    140 register_deactivation_hook(__FILE__, array($MroongaSearch, 'deactivate'));
     176register_activation_hook(__FILE__, array($MroongaSearch, "activate"));
     177register_deactivation_hook(__FILE__, array($MroongaSearch, "deactivate"));
    141178
    142 add_action('publish_post', array($MroongaSearch, 'update_post'), 10, 2);
    143 add_filter('posts_search', array($MroongaSearch, 'fulltext_search'), 10, 2);
    144 add_filter('posts_join', array($MroongaSearch, 'fulltext_search_join'), 10, 2);
    145 add_filter('posts_search_orderby', array($MroongaSearch, 'fulltext_search_orderby'), 10, 2);
     179add_action("wp_insert_post", array($MroongaSearch, "update_post"), 10, 2);
     180add_filter("posts_search", array($MroongaSearch, "fulltext_search"), 10, 2);
     181add_filter("posts_join", array($MroongaSearch, "fulltext_search_join"), 10, 2);
     182add_filter("posts_search_orderby", array($MroongaSearch, "fulltext_search_orderby"), 10, 2);
     183
     184add_action("after_delete_post", array($MroongaSearch, "after_delete_post"), 100, 1 );
  • mroonga/trunk/readme.txt

    r1714411 r1817832  
    11=== Mroonga ===
    2 Contributors: ktou
     2Contributors: komainu8, ktou
    33Tags: full-text-search
    44Requires at least: 4.8.1
     
    6060== Changelog ==
    6161
    62 = 0.1.0 =
     62= 0.1.1 - 2018-02-09 =
     63
     64* Stopped to index needless contents.
     65  [GitHub#2][Patch by Yuya Tajima]
     66
     67* Added Japanese error messages.
     68  [GitHub#2][Patch by Yuya Tajima]
     69
     70= 0.1.0 - 2017-08-16 =
    6371
    6472* Initial release.
     
    6674== Upgrade Notice ==
    6775
     76= 0.1.1 =
     77
     78None.
     79
    6880= 0.1.0 =
    6981
Note: See TracChangeset for help on using the changeset viewer.