Changeset 1992175
- Timestamp:
- 12/11/2018 09:25:03 PM (7 years ago)
- Location:
- relevant-search/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (3 diffs)
-
relevant-search.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
relevant-search/trunk/readme.txt
r477391 r1992175 3 3 Tags: search, relevant, results, post types, mysql, myisam 4 4 Requires at least: 3.0 5 Tested up to: 3.36 Stable tag: 1. 0.15 Tested up to: 5.0 6 Stable tag: 1.2.0 7 7 8 8 Relevant Search replaces the default WordPress search with relevant results. … … 15 15 16 16 = MySQL Documentation = 17 * [Full-Text Search Functions](http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html) 18 * [Natural Language Full-Text Searches](http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html) 19 * [Regular Expressions](http://dev.mysql.com/doc/refman/5.1/en/regexp.html) 20 21 = Developers = 22 * [GitHub](https://github.com/niftycode/relevant-search) 17 * [Full-Text Search Functions](http://dev.mysql.com/doc/refman/5.6/en/fulltext-search.html) 18 * [Natural Language Full-Text Searches](http://dev.mysql.com/doc/refman/5.6/en/fulltext-natural-language.html) 19 * [Regular Expressions](http://dev.mysql.com/doc/refman/5.6/en/regexp.html) 23 20 24 21 == Installation == … … 31 28 == Changelog == 32 29 30 = 1.2.0 = 31 * Code cleanup 32 * Tested up to 5.0 33 33 34 = 1.0.1 = 34 35 * Rebuild the Full-Text Index when needed -
relevant-search/trunk/relevant-search.php
r477391 r1992175 2 2 /** 3 3 * Plugin Name: Relevant Search 4 * Plugin URI: http ://snippets-tricks.org/proyecto/relevant-search/4 * Plugin URI: https://wordpress.org/plugins/relevant-search/ 5 5 * Description: Relevant Search will provide contextual search and listing the results based on relevance. It automatically replaces the default WordPress search. 6 * Version: 1. 0.17 * Author: Luis A lberto Ochoa Esparza8 * Author URI: http ://luisalberto.org6 * Version: 1.2.0 7 * Author: Luis A. Ochoa 8 * Author URI: https://gitlab.com/albertochoa 9 9 * 10 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU 11 * General Public License version 2, as published by the Free Software Foundation. You may NOT assume 12 * that you can use any other version of the GPL. 10 * Relevant Search will provide contextual search and listing the results based on relevance. 11 * Copyright (C) 2011-2018 Luis A. Ochoa 13 12 * 14 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 15 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or 16 * (at your option) any later version. 16 17 * 17 * You should have received a copy of the GNU General Public License along with this program; if not, write 18 * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 19 22 * 20 * @package Relevant Search 21 * @version 1.0.1 22 * @link http://snippets-tricks.org/proyecto/relevant-search/ 23 * @author Luis Alberto Ochoa Esparza <[email protected]> 24 * @copyright Copyright (C) 2011, Luis Alberto Ochoa Esparza 25 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 23 * You should have received a copy of the GNU General Public License along 24 * with this program; if not, write to the Free Software Foundation, Inc., 25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 26 26 */ 27 27 … … 37 37 { 38 38 /** 39 * The single instance of the class. 40 * 41 * @since 1.2.0 42 */ 43 protected static $instance = null; 44 45 /** 39 46 * The main Relevant Search loader. 40 47 * 41 48 * @since 1.0.0 42 49 */ 43 p ublicfunction __construct() {50 private function __construct() { 44 51 45 52 /* Filter the query in 'posts_request' */ … … 56 63 57 64 /** 65 * 66 * @since 1.2.0 67 */ 68 public static function getInstance() { 69 70 if (is_null( self::$instance ) ) { 71 self::$instance = new Relevant_Search(); 72 } 73 74 return self::$instance; 75 } 76 77 /** 58 78 * Creates a query that retrieves the posts depending on search terms 59 79 * and sorts by relevance. … … 64 84 65 85 /* If not the search page returns $request */ 66 if ( !is_search() ) return $request; 86 if ( !is_search() ) { 87 return $request; 88 } 67 89 68 90 global $wpdb, $wp_query; … … 71 93 $s = stripslashes( $wp_query->query_vars['s'] ); 72 94 73 if ( !empty( $wp_query->query_vars['sentence'] ) ) 95 if ( !empty( $wp_query->query_vars['sentence'] ) ) { 74 96 $terminos = array( $s ); 75 76 else { 97 } else { 77 98 preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches ); 78 99 $terminos = array_map( 'rs_search_terms_tidy', $matches[0] ); 79 100 } 80 101 81 foreach( $terminos as $termino ) 102 foreach( $terminos as $termino ) { 82 103 $regexp[] = "[[:<:]]{$termino}[[:>:]]"; 104 } 83 105 84 106 $regexp = join( '|', $regexp ); … … 88 110 89 111 /* Add the post that have no password if the user is not logged */ 90 if ( !is_user_logged_in() ) 112 if ( !is_user_logged_in() ) { 91 113 $query[] = "AND post_password = ''"; 114 } 92 115 93 116 /* Set the post types not excluded from search */ … … 132 155 global $wpdb; 133 156 134 if ( false == $wpdb->query( "SHOW INDEX FROM {$wpdb->posts} WHERE key_name = 'search';" ) ) 157 if ( false == $wpdb->query( "SHOW INDEX FROM {$wpdb->posts} WHERE key_name = 'search';" ) ) { 135 158 $wpdb->query( "CREATE FULLTEXT INDEX search ON {$wpdb->posts} (post_title, post_content);" ); 159 } 136 160 } 137 161 … … 144 168 global $wpdb; 145 169 146 if ( $wpdb->query( "SHOW INDEX FROM {$wpdb->posts} WHERE key_name = 'search';" ) ) 170 if ( $wpdb->query( "SHOW INDEX FROM {$wpdb->posts} WHERE key_name = 'search';" ) ) { 147 171 $wpdb->query( "ALTER TABLE {$wpdb->posts} DROP INDEX search;" ); 172 } 148 173 } 149 150 /**151 * @since 1.0.0152 * @deprecated 1.0.1153 */154 function rs_post_request( $request ) {}155 156 /**157 * @since 1.0.0158 * @deprecated 1.0.1159 */160 function rs_activation() {}161 162 /**163 * @since 1.0.0164 * @deprecated 1.0.1165 */166 function rs_desactivation() {}167 174 } 168 175 169 176 /* Creates a new instance. */ 170 $GLOBAL['relevat_search'] = new Relevant_Search();177 $GLOBAL['relevat_search'] = Relevant_Search::getInstance(); 171 178 172 179 /** 173 180 * Used internally to tidy up the search terms. 174 181 * 175 * T ODO: This function has been copied in WordPress Core182 * This function has been copied in WordPress Core 176 183 * 177 184 * @since 1.0.0
Note: See TracChangeset
for help on using the changeset viewer.