Changeset 1817832
- Timestamp:
- 02/08/2018 03:45:29 AM (8 years ago)
- Location:
- mroonga/trunk
- Files:
-
- 2 added
- 2 edited
-
languages (added)
-
languages/mroonga-ja.mo (added)
-
mroonga.php (modified) (8 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mroonga/trunk/mroonga.php
r1714411 r1817832 4 4 Plugin URI: https://github.com/mroonga/wordpress-mroonga 5 5 Description: 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. 06 Version: 0.1.1 7 7 Author: Yasuhiro Horimoto 8 8 Author URI: https://www.clear-code.com/ … … 12 12 class MroongaSearch 13 13 { 14 15 private $textdomain = "mroonga"; 16 private $mroonga_install_doc = "http://mroonga.org/docs/install.html"; 17 14 18 public function table_name() 15 19 { … … 17 21 18 22 return $wpdb->prefix . "mrn_posts"; 23 } 24 25 public function __construct() 26 { 27 load_plugin_textdomain( $this->textdomain, false, dirname( plugin_basename( __FILE__ ) ) . "/languages" ); 19 28 } 20 29 … … 36 45 global $wpdb; 37 46 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 ); 41 58 } 42 43 $wpdb->query("INSTALL PLUGIN Mroonga SONAME 'ha_mroonga.so'");44 // TODO Report error on failure45 59 } 46 60 … … 62 76 global $wpdb; 63 77 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 } 69 88 } 70 89 … … 83 102 global $wpdb; 84 103 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 ); 86 111 } 87 112 … … 90 115 global $wpdb; 91 116 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 } 96 126 } 97 127 98 128 public function fulltext_search($search, $wp_query) 99 129 { 100 return '';130 return ""; 101 131 } 102 132 … … 129 159 if (strlen($search_query) > 0) 130 160 { 131 $orderby = 'score DESC';161 $orderby = "score DESC"; 132 162 } 133 163 return $orderby; 134 164 } 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 135 172 } 136 173 137 174 $MroongaSearch = new MroongaSearch(); 138 175 139 register_activation_hook(__FILE__, array($MroongaSearch, 'activate'));140 register_deactivation_hook(__FILE__, array($MroongaSearch, 'deactivate'));176 register_activation_hook(__FILE__, array($MroongaSearch, "activate")); 177 register_deactivation_hook(__FILE__, array($MroongaSearch, "deactivate")); 141 178 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); 179 add_action("wp_insert_post", array($MroongaSearch, "update_post"), 10, 2); 180 add_filter("posts_search", array($MroongaSearch, "fulltext_search"), 10, 2); 181 add_filter("posts_join", array($MroongaSearch, "fulltext_search_join"), 10, 2); 182 add_filter("posts_search_orderby", array($MroongaSearch, "fulltext_search_orderby"), 10, 2); 183 184 add_action("after_delete_post", array($MroongaSearch, "after_delete_post"), 100, 1 ); -
mroonga/trunk/readme.txt
r1714411 r1817832 1 1 === Mroonga === 2 Contributors: k tou2 Contributors: komainu8, ktou 3 3 Tags: full-text-search 4 4 Requires at least: 4.8.1 … … 60 60 == Changelog == 61 61 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 = 63 71 64 72 * Initial release. … … 66 74 == Upgrade Notice == 67 75 76 = 0.1.1 = 77 78 None. 79 68 80 = 0.1.0 = 69 81
Note: See TracChangeset
for help on using the changeset viewer.