Plugin Directory

Changeset 1992175


Ignore:
Timestamp:
12/11/2018 09:25:03 PM (7 years ago)
Author:
albertochoa
Message:

Version 1.2.0

Location:
relevant-search/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • relevant-search/trunk/readme.txt

    r477391 r1992175  
    33Tags: search, relevant, results, post types, mysql, myisam
    44Requires at least: 3.0
    5 Tested up to: 3.3
    6 Stable tag: 1.0.1
     5Tested up to: 5.0
     6Stable tag: 1.2.0
    77
    88Relevant Search replaces the default WordPress search with relevant results.
     
    1515
    1616= 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)
    2320
    2421== Installation ==
     
    3128== Changelog ==
    3229
     30= 1.2.0 =
     31* Code cleanup
     32* Tested up to 5.0
     33
    3334= 1.0.1 =
    3435* Rebuild the Full-Text Index when needed
  • relevant-search/trunk/relevant-search.php

    r477391 r1992175  
    22/**
    33 * Plugin Name: Relevant Search
    4  * Plugin URI: http://snippets-tricks.org/proyecto/relevant-search/
     4 * Plugin URI: https://wordpress.org/plugins/relevant-search/
    55 * 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.1
    7  * Author: Luis Alberto Ochoa Esparza
    8  * Author URI: http://luisalberto.org
     6 * Version: 1.2.0
     7 * Author: Luis A. Ochoa
     8 * Author URI: https://gitlab.com/albertochoa
    99 *
    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
    1312 *
    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.
    1617 *
    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.
    1922 *
    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.
    2626 */
    2727
     
    3737{
    3838    /**
     39     * The single instance of the class.
     40     *
     41     * @since 1.2.0
     42     */
     43    protected static $instance = null;
     44
     45    /**
    3946     * The main Relevant Search loader.
    4047     *
    4148     * @since 1.0.0
    4249     */
    43     public function __construct() {
     50    private function __construct() {
    4451
    4552        /* Filter the query in 'posts_request' */
     
    5663
    5764    /**
     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    /**
    5878     * Creates a query that retrieves the posts depending on search terms
    5979     * and sorts by relevance.
     
    6484
    6585        /* If not the search page returns $request */
    66         if ( !is_search() ) return $request;
     86        if ( !is_search() ) {
     87            return $request;
     88        }
    6789
    6890        global $wpdb, $wp_query;
     
    7193        $s = stripslashes( $wp_query->query_vars['s'] );
    7294
    73         if ( !empty( $wp_query->query_vars['sentence'] ) )
     95        if ( !empty( $wp_query->query_vars['sentence'] ) ) {
    7496            $terminos = array( $s );
    75 
    76         else {
     97        } else {
    7798            preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
    7899            $terminos = array_map( 'rs_search_terms_tidy', $matches[0] );
    79100        }
    80101
    81         foreach( $terminos as $termino )
     102        foreach( $terminos as $termino ) {
    82103            $regexp[] = "[[:<:]]{$termino}[[:>:]]";
     104        }
    83105
    84106        $regexp = join( '|', $regexp );
     
    88110
    89111        /* 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() ) {
    91113            $query[] = "AND post_password = ''";
     114        }
    92115
    93116        /* Set the post types not excluded from search */
     
    132155        global $wpdb;
    133156
    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';" ) ) {
    135158            $wpdb->query( "CREATE FULLTEXT INDEX search ON {$wpdb->posts} (post_title, post_content);" );
     159        }
    136160    }
    137161
     
    144168        global $wpdb;
    145169
    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';" ) ) {
    147171            $wpdb->query( "ALTER TABLE {$wpdb->posts} DROP INDEX search;" );
     172        }
    148173    }
    149 
    150     /**
    151      * @since 1.0.0
    152      * @deprecated 1.0.1
    153      */
    154     function rs_post_request( $request ) {}
    155 
    156     /**
    157      * @since 1.0.0
    158      * @deprecated 1.0.1
    159      */
    160     function rs_activation() {}
    161 
    162     /**
    163      * @since 1.0.0
    164      * @deprecated 1.0.1
    165      */
    166     function rs_desactivation() {}
    167174}
    168175
    169176/* Creates a new instance. */
    170 $GLOBAL['relevat_search'] = new Relevant_Search();
     177$GLOBAL['relevat_search'] = Relevant_Search::getInstance();
    171178
    172179/**
    173180 * Used internally to tidy up the search terms.
    174181 *
    175  * TODO: This function has been copied in WordPress Core
     182 * This function has been copied in WordPress Core
    176183 *
    177184 * @since 1.0.0
Note: See TracChangeset for help on using the changeset viewer.