diff --git a/.gitignore b/.gitignore index 7e47342..ee6e9df 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ node_modules tests tmp /vendor +/wordpress-testground diff --git a/19822348.png b/19822348.png new file mode 100644 index 0000000..5d2855e Binary files /dev/null and b/19822348.png differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..5be79bb --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ + +=== WP Search with Typesense === + +How to install and use the plugin + +* Make sure your Typesense server is up an running. +* Install WordPress in your system. +* Navigate to the plugins folder inside WordPress. Clone this repository in the folder. +* Now the plugin is ready to use. +* Open your WordPress dashboard and navigate to the Plugins menu. You would find “**WP Search with Typesense**” added to the list of plugins. Activate the plugin. +* A new menu for Typesense pops up in the dashboard. +* Click the menu and navigate to “**Settings**” submenu. +* Enter your Typesense API key and the server host and port where the Typesense server is running. +* Navigate to the “**Autocomplete**” submenu. +* Hit the reindex button for Posts and Categories to index all your existing data into Typesense. +* Hurrah!!Now you can open your blog page and search for posts to get the blazing fast search experience from Typesense. +* You can also create, update or delete posts and categories as you would always do in WordPress. The plugin takes care to update the changes in the Typesense server. + += 1.0.0 = +* Initial release. diff --git a/README.txt b/README.txt deleted file mode 100644 index df34c4d..0000000 --- a/README.txt +++ /dev/null @@ -1,153 +0,0 @@ - -=== WP Search with Algolia === -Contributors: WebDevStudios, williamsba1, gregrickaby, tw2113, richaber, mrasharirfan -Tags: Search, Algolia, Autocomplete, instant-search, relevant search, search highlight, faceted search, find-as-you-type search, suggest, search by category, ajax search, better search, custom search -Requires at least: 5.0 -Tested up to: 5.5 -Requires PHP: 7.2 -Stable tag: 1.6.0 -License: GNU General Public License v2.0, MIT License - -Improve search on your site. Autocomplete is included, along with full control over look, feel and relevance. - -== Description == - -Improve search on your site. Autocomplete is included, along with full control over look, feel and relevance. - -= Features = -* Relevant search results in milliseconds -* Native typo-tolerance -* Is language-agnostic -* Offers hooks and filters for easy customization -* Built by developers, for developers - -This plugin requires API keys from [Algolia](https://www.algolia.com/). API keys are free for small personal projects and non-commercial use. Learn more about [commercial use pricing](https://www.algolia.com/pricing/). - -= Links = -* [WebDevStudios](https://webdevstudios.com) -* [Algolia](https://algolia.com) -* [Documentation](https://community.algolia.com/wordpress/configuration.html) -* [Support](https://github.com/WebDevStudios/wp-search-with-algolia/issues) - -*This plugin is a derivative work of the code from the [Search by Algolia – Instant & Relevant results](https://wordpress.org/plugins/search-by-algolia-instant-relevant-results/) plugin for WordPress, which is licensed under the GPLv2.* - -== Installation == - -**If you have the *Search by Algolia – Instant & Relevant results* plugin installed, please deactivate it first.** - -From your WordPress dashboard: - -1. **Visit** Plugins > Add New -2. **Search** for "WP Search with Algolia" -3. **Activate** WP Search with Algolia from your Plugins page -4. **Click** on the new menu item "Algolia Search" and enter your API keys -5. **Read** the step by step [configuration guide](https://community.algolia.com/wordpress/configuration.html) - -== Frequently Asked Questions == - -= Is this plugin a fork? = - -Yes. The Algolia Team **[no longer supports their original plugin](https://community.algolia.com/wordpress/)**. The engineering team at WebDevStudios has forked the original plugin, and is now maintaining it. - -= Should I switch to this plugin? = - -Yes. Because Algolia no longer supports their plugin, you will no longer receive updates. WebDevStudios uses Algolia on many of it's projects, and is committed to maintaining this plugin for years to come. - -= How do I switch from the "Search by Algolia – Instant & Relevant results" plugin? = - -1. **Deactivate** the *Search by Algolia – Instant & Relevant results* plugin -2. **Follow** the [installation instructions](https://wordpress.org/plugins/wp-search-with-algolia/#installation) -3. **Activate** *WP Search with Algolia* -4. **Check** for your API Keys. They should already be there, if not, enter them and then save settings -5. **Delete** the *Search by Algolia – Instant & Relevant results* plugin - -= What are the minimum requirements? = - -* Requires WordPress 5.0+ -* PHP version 7.2 or greater (PHP 7.3 is recommended) -* MySQL version 5.0 or greater (MySQL 5.6 or greater is recommended) -* cURL PHP extension -* mbstring PHP extension -* OpenSSL greater than 1.0.1 -* Some payment gateways require fsockopen support (for IPN access) - -Visit the [Search by Algolia server requirements documentation](https://community.algolia.com/wordpress/installation.html) for a detailed list of server requirements. - -= Where can I find Algolia documentation and user guides? = - -- For help setting up and configuring Search by Algolia please refer to the [user guide](https://community.algolia.com/wordpress/installation.html). -- For extending or theming the Autocomplete dropdown, see the [Autocomplete Customization guide](https://community.algolia.com/wordpress/customize-autocomplete.html). -- For extending or theming the Instant Search results page, see the [Search Page Customization guide](https://community.algolia.com/wordpress/customize-search-page.html). - -= Will it work with my theme? = - -Yes. This plugin will work with any theme, but the Instant Search results page may require some styling to make it match nicely. See the [Search Page Customization](https://community.algolia.com/wordpress/customize-search-page.html). - -= Where can I report bugs, request features, or contribute to the project? = - -All development is handled on [GitHub](https://github.com/WebDevStudios/wp-search-with-algolia/issues). - -= About Algolia = - -Algolia offers its Search as a Service provider on a incremental payment program, including a free Community Plan which includes 10,000 records & 50,000 operations per month. Beyond that, [plans](https://www.algolia.com/pricing/) start at $29/month. - -*Note: there isn't a direct correlation between the number of posts in WordPress and the number of records in Algolia. Also note that we only offer support starting from the PRO plan.On average, you can expect to have about 10 times more records than you have posts, though this is not a golden rule and you could end up with more records.* - -= About WebDevStudios = - -WebDevStudios provides end-to-end WordPress opportunities from strategy and planning to website design and development, as well as full data migration, extensive API integrations, scalability, performance and long-term guidance and maintenance. We have service options and solutions for start-ups, small to mid-size businesses, enterprise organizations and marketing agencies. - -== Screenshots == - -1. Algolia Settings -2. Search Page Settings -3. Autocomplete Settings -4. InstantSearch Dropdown -5. Search Results - -== Changelog == - -Follow along with the changelog on [Github](https://github.com/WebDevStudios/wp-search-with-algolia/releases). - -= 1.6.0 = -* Fix deletion of post records created before indexing was enabled -* Update Algolia PHP Search Client to version 2.7.1. -* Add Algolia_Plugin_Factory to create and return a shared Algolia_Plugin instance -* Add Algolia_Search_Client_Factory to return a new Algolia\AlgoliaSearch\SearchClient instance -* Add Algolia_Http_Client_Interface_Factory to create and return a shared Php53HttpClient instance -* Add algolia_php_53_http_client_options filter to supply cURL options to Php53HttpClient instance -* Deprecate Algolia_Plugin:get_instance() which will be removed in an upcoming release - -= 1.5.0 = -* Fix an issue where Pinterest follows a link to the Algolia domain to source text and/or images - * Move Algolia scripts to footer by default - * Changes algolia_load_scripts_in_footer filter default argument to "true" - * Move autocomplete.php template output to footer by default - -= 1.4.0 = -* Update Algolia PHP Search Client version 2.7.0. -* Update Algolia JS libraries to most recent compatible (non-breaking) versions - * Updates autocomplete.js to 0.37.1 (current release as of 2020-01-27) - * Updates algoliasearch to 3.35.1 (last of the 3.x series) - * Updates instantsearch.js to 1.12.1 (last of the 1.x series) - -= 1.3.0 = -* Fix an issue where, under some circumstances, when a post with a featured image was deleted, the post might be accidentally re-indexed -* Fix bug that prevented reindex display notices -* Add algolia_load_scripts_in_footer filter to allow enqueueing the scripts in the footer instead of in the head -* Add new filters for multisite developers - -= 1.2.0 = -* Use filtered value of 'hitsPerPage' as 'posts_per_page' query param -* Fix broken SVG -* Add highlighting to backend search results - props @philipnewcomer - -= 1.1.0 = -* Minimum PHP version requirement is now PHP 7.2 -* Minimum WordPress version requirement is now WP 5.0 -* Internationalization/localization improvements, textdomain matches plugin slug -* Addressed a potential WSOD if minimum PHP and WP version requirements were not met -* Tested on WP 5.3 - -= 1.0.0 = -* Initial release. diff --git a/algolia.php b/algolia.php deleted file mode 100644 index 1db2afa..0000000 --- a/algolia.php +++ /dev/null @@ -1,137 +0,0 @@ - - * @since 1.1.0 - * - * @return bool - */ -function algolia_php_version_check() { - if ( version_compare( PHP_VERSION, ALGOLIA_MIN_PHP_VERSION, '<' ) ) { - return false; - } - return true; -} - -/** - * Check for required WordPress version. - * - * @author WebDevStudios - * @since 1.1.0 - * - * @return bool - */ -function algolia_wp_version_check() { - if ( version_compare( $GLOBALS['wp_version'], ALGOLIA_MIN_WP_VERSION, '<' ) ) { - return false; - } - return true; -} - -/** - * Admin notices if requirements aren't met. - * - * @author WebDevStudios - * @since 1.1.0 - */ -function algolia_requirements_error_notice() { - - $notices = []; - - if ( ! algolia_php_version_check() ) { - $notices[] = sprintf( - /* translators: placeholder 1 is minimum required PHP version, placeholder 2 is installed PHP version. */ - esc_html__( 'Algolia plugin requires PHP %1$s or higher. You’re still on %2$s.', 'wp-search-with-algolia' ), - esc_html( ALGOLIA_MIN_PHP_VERSION ), - esc_html( PHP_VERSION ) - ); - } - - if ( ! algolia_wp_version_check() ) { - $notices[] = sprintf( - /* translators: placeholder 1 is minimum required WordPress version, placeholder 2 is installed WordPress version. */ - esc_html__( 'Algolia plugin requires at least WordPress in version %1$s, You are on %2$s.', 'wp-search-with-algolia' ), - esc_html( ALGOLIA_MIN_WP_VERSION ), - esc_html( $GLOBALS['wp_version'] ) - ); - } - - foreach ( $notices as $notice ) { - echo '

' . esc_html( $notice ) . '

'; - } -} - -/** - * I18n. - * - * @author WebDevStudios - * @since 1.0.0 - */ -function algolia_load_textdomain() { - - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals -- This is a legitimate use of a global filter. - $locale = apply_filters( 'plugin_locale', get_locale(), 'wp-search-with-algolia' ); - - load_textdomain( 'wp-search-with-algolia', WP_LANG_DIR . '/wp-search-with-algolia/wp-search-with-algolia-' . $locale . '.mo' ); - - load_plugin_textdomain( 'wp-search-with-algolia', false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' ); -} - -add_action( 'init', 'algolia_load_textdomain' ); - -if ( algolia_php_version_check() && algolia_wp_version_check() ) { - require_once ALGOLIA_PATH . 'classmap.php'; - - $algolia = Algolia_Plugin_Factory::create(); - - if ( defined( 'WP_CLI' ) && WP_CLI ) { - include ALGOLIA_PATH . 'includes/class-algolia-cli.php'; - WP_CLI::add_command( 'algolia', new Algolia_CLI() ); - } -} else { - add_action( 'admin_notices', 'algolia_requirements_error_notice' ); -} diff --git a/assets/banner-1544x500.png b/assets/banner-1544x500.png deleted file mode 100644 index f71c566..0000000 Binary files a/assets/banner-1544x500.png and /dev/null differ diff --git a/assets/banner-772x250.png b/assets/banner-772x250.png deleted file mode 100644 index e68eda7..0000000 Binary files a/assets/banner-772x250.png and /dev/null differ diff --git a/assets/icon-128x128.png b/assets/icon-128x128.png deleted file mode 100644 index 48cdcef..0000000 Binary files a/assets/icon-128x128.png and /dev/null differ diff --git a/assets/icon-256x256.png b/assets/icon-256x256.png deleted file mode 100644 index e996386..0000000 Binary files a/assets/icon-256x256.png and /dev/null differ diff --git a/assets/screenshot-1.png b/assets/screenshot-1.png deleted file mode 100644 index cd3b91b..0000000 Binary files a/assets/screenshot-1.png and /dev/null differ diff --git a/assets/screenshot-2.png b/assets/screenshot-2.png deleted file mode 100644 index a69907c..0000000 Binary files a/assets/screenshot-2.png and /dev/null differ diff --git a/assets/screenshot-3.png b/assets/screenshot-3.png deleted file mode 100644 index bcba546..0000000 Binary files a/assets/screenshot-3.png and /dev/null differ diff --git a/assets/screenshot-4.png b/assets/screenshot-4.png deleted file mode 100644 index 8af5dfc..0000000 Binary files a/assets/screenshot-4.png and /dev/null differ diff --git a/assets/screenshot-5.png b/assets/screenshot-5.png deleted file mode 100644 index 2bae76f..0000000 Binary files a/assets/screenshot-5.png and /dev/null differ diff --git a/classmap.php b/classmap.php index cea8e5b..5c63835 100644 --- a/classmap.php +++ b/classmap.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -8,45 +8,51 @@ * @package WebDevStudios\WPSWA */ -if ( ! defined( 'ALGOLIA_PATH' ) ) { +if ( ! defined( 'TYPESENSE_PATH' ) ) { exit(); } -// The Algolia Search PHP API SearchClient. -if ( apply_filters( 'algolia_should_require_search_client', true ) ) { - require_once ALGOLIA_PATH . 'includes/libraries/algoliasearch-client-php/autoload.php'; -} -require_once ALGOLIA_PATH . 'includes/factories/class-algolia-http-client-interface-factory.php'; -require_once ALGOLIA_PATH . 'includes/factories/class-algolia-search-client-factory.php'; -require_once ALGOLIA_PATH . 'includes/factories/class-algolia-plugin-factory.php'; - -require_once ALGOLIA_PATH . 'includes/class-algolia-api.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-autocomplete-config.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-compatibility.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-plugin.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-search.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-settings.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-template-loader.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-utils.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-styles.php'; -require_once ALGOLIA_PATH . 'includes/class-algolia-scripts.php'; - -require_once ALGOLIA_PATH . 'includes/indices/class-algolia-index.php'; -require_once ALGOLIA_PATH . 'includes/indices/class-algolia-index-replica.php'; -require_once ALGOLIA_PATH . 'includes/indices/class-algolia-searchable-posts-index.php'; -require_once ALGOLIA_PATH . 'includes/indices/class-algolia-posts-index.php'; -require_once ALGOLIA_PATH . 'includes/indices/class-algolia-terms-index.php'; -require_once ALGOLIA_PATH . 'includes/indices/class-algolia-users-index.php'; - -require_once ALGOLIA_PATH . 'includes/watchers/class-algolia-changes-watcher.php'; -require_once ALGOLIA_PATH . 'includes/watchers/class-algolia-post-changes-watcher.php'; -require_once ALGOLIA_PATH . 'includes/watchers/class-algolia-term-changes-watcher.php'; -require_once ALGOLIA_PATH . 'includes/watchers/class-algolia-user-changes-watcher.php'; +require_once TYPESENSE_PATH . 'includes/libraries/typesensesearch-client-php/vendor/autoload.php'; + + +require_once TYPESENSE_PATH . 'includes/factories/class-algolia-plugin-factory.php'; + +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-index.php'; +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-posts-index.php'; +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-terms-index.php'; + +require_once TYPESENSE_PATH . 'includes/watchers/class-algolia-changes-watcher.php'; +require_once TYPESENSE_PATH . 'includes/watchers/class-algolia-post-changes-watcher.php'; + +require_once TYPESENSE_PATH . 'includes/class-algolia-api.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-autocomplete-config.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-compatibility.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-plugin.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-search.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-settings.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-template-loader.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-utils.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-styles.php'; +require_once TYPESENSE_PATH . 'includes/class-algolia-scripts.php'; +/* +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-index.php'; +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-index-replica.php'; +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-searchable-posts-index.php'; +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-posts-index.php'; +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-terms-index.php'; +require_once TYPESENSE_PATH . 'includes/indices/class-algolia-users-index.php'; +*/ +/* +require_once TYPESENSE_PATH . 'includes/watchers/class-algolia-changes-watcher.php'; +require_once TYPESENSE_PATH . 'includes/watchers/class-algolia-post-changes-watcher.php'; +require_once TYPESENSE_PATH . 'includes/watchers/class-typesense-term-changes-watcher.php'; +require_once TYPESENSE_PATH . 'includes/watchers/class-typesense-user-changes-watcher.php'; +*/ if ( is_admin() ) { - require_once ALGOLIA_PATH . 'includes/admin/class-algolia-admin.php'; - require_once ALGOLIA_PATH . 'includes/admin/class-algolia-admin-page-autocomplete.php'; - require_once ALGOLIA_PATH . 'includes/admin/class-algolia-admin-page-native-search.php'; - require_once ALGOLIA_PATH . 'includes/admin/class-algolia-admin-page-settings.php'; + require_once TYPESENSE_PATH . 'includes/admin/class-algolia-admin.php'; + require_once TYPESENSE_PATH . 'includes/admin/class-algolia-admin-page-autocomplete.php'; + require_once TYPESENSE_PATH . 'includes/admin/class-algolia-admin-page-native-search.php'; + require_once TYPESENSE_PATH . 'includes/admin/class-algolia-admin-page-settings.php'; } diff --git a/css/algolia-instantsearch.css b/css/algolia-instantsearch.css index 99dec19..4656a36 100644 --- a/css/algolia-instantsearch.css +++ b/css/algolia-instantsearch.css @@ -71,11 +71,6 @@ vertical-align: middle; } -.ais-stats { - position: absolute; - top: 60px; - font-size: 14px; -} .ais-hits--item { /* hit item */ @@ -109,6 +104,36 @@ margin: 0; } + +/*own*/ + + + +.ais-Menu-count{ + background : #FBAE00; + margin-left: 5px; + border-radius: 25px; + height: auto; + width: auto; +} + +.ais-Menu-item--selected { + font-weight: 700; +} + +.ais-SearchBox-submit{ + display: none; +} + +.ais-SearchBox-reset{ + display: none; +} + +.ais-Pagination-item{ + display: inline; + margin-left: 25px; +} + .ais-pagination--item { /* pagination item */ display: inline-block; diff --git a/includes/admin/class-algolia-admin-page-autocomplete.php b/includes/admin/class-algolia-admin-page-autocomplete.php index 306687d..65d5d2e 100644 --- a/includes/admin/class-algolia-admin-page-autocomplete.php +++ b/includes/admin/class-algolia-admin-page-autocomplete.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -9,11 +9,11 @@ */ /** - * Class Algolia_Admin_Page_Autocomplete + * Class Typesense_Admin_Page_Autocomplete * * @since 1.0.0 */ -class Algolia_Admin_Page_Autocomplete { +class Typesense_Admin_Page_Autocomplete { /** * Admin page slug. @@ -23,7 +23,7 @@ class Algolia_Admin_Page_Autocomplete { * * @var string */ - private $slug = 'algolia'; + private $slug = 'typesense'; /** * Admin page capabilities. @@ -43,7 +43,7 @@ class Algolia_Admin_Page_Autocomplete { * * @var string */ - private $section = 'algolia_section_autocomplete'; + private $section = 'typesense_section_autocomplete'; /** * Admin page option group. @@ -53,43 +53,43 @@ class Algolia_Admin_Page_Autocomplete { * * @var string */ - private $option_group = 'algolia_autocomplete'; + private $option_group = 'typesense_autocomplete'; /** - * The Algolia_Settings object. + * The Typesense_Settings object. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Settings + * @var Typesense_Settings */ private $settings; /** - * The Algolia_Autocomplete_Config object. + * The Typesense_Autocomplete_Config object. * * @since 1.0.0 * - * @var Algolia_Autocomplete_Config + * @var Typesense_Autocomplete_Config */ private $autocomplete_config; /** - * Algolia_Admin_Page_Autocomplete constructor. + * Typesense_Admin_Page_Autocomplete constructor. * * @author WebDevStudios * @since 1.0.0 * - * @param Algolia_Settings $settings The Algolia_Settings object. - * @param Algolia_Autocomplete_Config $autocomplete_config The Algolia_Autocomplete_Config object. + * @param Typesense_Settings $settings The Typesense_Settings object. + * @param Typesense_Autocomplete_Config $autocomplete_config The Typesense_Autocomplete_Config object. */ - public function __construct( Algolia_Settings $settings, Algolia_Autocomplete_Config $autocomplete_config ) { + public function __construct(Typesense_Settings $settings, Typesense_Autocomplete_Config $autocomplete_config) { $this->settings = $settings; $this->autocomplete_config = $autocomplete_config; add_action( 'admin_menu', array( $this, 'add_page' ) ); add_action( 'admin_init', array( $this, 'add_settings' ) ); - add_action( 'admin_notices', array( $this, 'display_errors' ) ); + //add_action( 'admin_notices', array( $this, 'display_errors' ) ); // @todo: Listen for de-index to remove from autocomplete. } @@ -102,17 +102,17 @@ public function __construct( Algolia_Settings $settings, Algolia_Autocomplete_Co */ public function add_page() { add_menu_page( - 'Algolia Search', - esc_html__( 'Algolia Search', 'wp-search-with-algolia' ), + 'Typesense Search', + esc_html__( 'Typesense Search', 'wp-search-with-typesense' ), 'manage_options', - 'algolia', + 'typesense', array( $this, 'display_page' ), '' ); add_submenu_page( - 'algolia', - esc_html__( 'Autocomplete', 'wp-search-with-algolia' ), - esc_html__( 'Autocomplete', 'wp-search-with-algolia' ), + 'typesense', + esc_html__( 'Autocomplete', 'wp-search-with-typesense' ), + esc_html__( 'Autocomplete', 'wp-search-with-typesense' ), $this->capability, $this->slug, array( $this, 'display_page' ) @@ -132,25 +132,34 @@ public function add_settings() { array( $this, 'print_section_settings' ), $this->slug ); - add_settings_field( - 'algolia_autocomplete_enabled', - esc_html__( 'Enable autocomplete', 'wp-search-with-algolia' ), + 'typesense_autocomplete_enabled', + esc_html__( 'Enable autocomplete', 'wp-search-with-typesense' ), array( $this, 'autocomplete_enabled_callback' ), $this->slug, $this->section ); add_settings_field( - 'algolia_autocomplete_config', - esc_html__( 'Configuration', 'wp-search-with-algolia' ), + 'typesense_autocomplete_config', + esc_html__( 'Configuration', 'wp-search-with-typesense' ), array( $this, 'autocomplete_config_callback' ), $this->slug, $this->section ); - register_setting( $this->option_group, 'algolia_autocomplete_enabled', array( $this, 'sanitize_autocomplete_enabled' ) ); - register_setting( $this->option_group, 'algolia_autocomplete_config', array( $this, 'sanitize_autocomplete_config' ) ); + register_setting( $this->option_group, 'typesense_autocomplete_enabled', array( $this, 'sanitize_autocomplete_enabled' ) ); + register_setting( $this->option_group, 'typesense_autocomplete_config', array( $this, 'sanitize_autocomplete_config' ) ); + } + + /** + * Index Recorrds Callback. + * + * @author WebDevStudios + * @since 1.0.0 + */ + public function index_records_callback() { + require_once dirname( __FILE__ ) . '/partials/index-records.php'; } /** @@ -165,7 +174,7 @@ public function autocomplete_enabled_callback() { $checked = 'yes' === $value ? 'checked ' : ''; $disabled = empty( $indices ) ? 'disabled ' : ''; ?> - /> + /> option_group, 'autocomplete_enabled', - esc_html__( 'Autocomplete configuration has been saved. Make sure to hit the "re-index" buttons of the different indices that are not indexed yet.', 'wp-search-with-algolia' ), + esc_html__( 'Autocomplete configuration has been saved. Make sure to hit the "re-index" buttons of the different indices that are not indexed yet.', 'wp-search-with-typesense' ), 'updated' ); @@ -238,7 +247,7 @@ public function display_page() { public function display_errors() { settings_errors( $this->option_group ); - if ( defined( 'ALGOLIA_HIDE_HELP_NOTICES' ) && ALGOLIA_HIDE_HELP_NOTICES ) { + if ( defined( 'TYPESENSE_HIDE_HELP_NOTICES' ) && TYPESENSE_HIDE_HELP_NOTICES ) { return; } @@ -247,9 +256,9 @@ public function display_errors() { if ( true === $is_enabled && empty( $indices ) ) { /* translators: placeholder contains the URL to the autocomplete configuration page. */ - $message = sprintf( __( 'Please select one or multiple indices on the Algolia: Autocomplete configuration page.', 'wp-search-with-algolia' ), esc_url( admin_url( 'admin.php?page=' . $this->slug ) ) ); + $message = sprintf( __( 'Please select one or multiple indices on the Typesense: Autocomplete configuration page.', 'wp-search-with-typesense' ), esc_url( admin_url( 'admin.php?page=' . $this->slug ) ) ); echo '
-

' . esc_html__( 'You have enabled the Algolia Autocomplete feature but did not choose any index to search in.', 'wp-search-with-algolia' ) . '

+

' . esc_html__( 'You have enabled the Typesense Autocomplete feature but did not choose any index to search in.', 'wp-search-with-typesense' ) . '

' . wp_kses_post( $message ) . '

'; } @@ -262,6 +271,6 @@ public function display_errors() { * @since 1.0.0 */ public function print_section_settings() { - echo '

' . esc_html__( 'The autocomplete feature adds a find-as-you-type dropdown menu to your search bar(s).', 'wp-search-with-algolia' ) . '

'; + echo '

' . esc_html__( 'The autocomplete feature adds a find-as-you-type dropdown menu to your search bar(s).', 'wp-search-with-typesense' ) . '

'; } } diff --git a/includes/admin/class-algolia-admin-page-native-search.php b/includes/admin/class-algolia-admin-page-native-search.php index 89a1621..80f83a6 100644 --- a/includes/admin/class-algolia-admin-page-native-search.php +++ b/includes/admin/class-algolia-admin-page-native-search.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -9,11 +9,11 @@ */ /** - * Class Algolia_Admin_Page_Native_Search + * Class Typesense_Admin_Page_Native_Search * * @since 1.0.0 */ -class Algolia_Admin_Page_Native_Search { +class Typesense_Admin_Page_Native_Search { /** * Admin page slug. @@ -23,7 +23,7 @@ class Algolia_Admin_Page_Native_Search { * * @var string */ - private $slug = 'algolia-search-page'; + private $slug = 'typesense-search-page'; /** * Admin page capabilities. @@ -43,7 +43,7 @@ class Algolia_Admin_Page_Native_Search { * * @var string */ - private $section = 'algolia_section_native_search'; + private $section = 'typesense_section_native_search'; /** * Admin page option group. @@ -53,32 +53,32 @@ class Algolia_Admin_Page_Native_Search { * * @var string */ - private $option_group = 'algolia_native_search'; + private $option_group = 'typesense_native_search'; /** - * The Algolia_Plugin instance. + * The Typesense_Plugin instance. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Plugin + * @var Typesense_Plugin */ private $plugin; /** - * Algolia_Admin_Page_Native_Search constructor. + * Typesense_Admin_Page_Native_Search constructor. * * @author WebDevStudios * @since 1.0.0 * - * @param Algolia_Plugin $plugin The Algolia_Plugin instance. + * @param Typesense_Plugin $plugin The Typesense_Plugin instance. */ - public function __construct( Algolia_Plugin $plugin ) { + public function __construct( Typesense_Plugin $plugin ) { $this->plugin = $plugin; add_action( 'admin_menu', array( $this, 'add_page' ) ); add_action( 'admin_init', array( $this, 'add_settings' ) ); - add_action( 'admin_notices', array( $this, 'display_errors' ) ); + //add_action( 'admin_notices', array( $this, 'display_errors' ) ); } /** @@ -89,13 +89,14 @@ public function __construct( Algolia_Plugin $plugin ) { */ public function add_page() { add_submenu_page( - 'algolia', - esc_html__( 'Search Page', 'wp-search-with-algolia' ), - esc_html__( 'Search Page', 'wp-search-with-algolia' ), + 'typesense', + esc_html__( 'Search Page', 'wp-search-with-typesense' ), + esc_html__( 'Search Page', 'wp-search-with-typesense' ), $this->capability, $this->slug, array( $this, 'display_page' ) ); + } /** @@ -113,14 +114,14 @@ public function add_settings() { ); add_settings_field( - 'algolia_override_native_search', - esc_html__( 'Search results', 'wp-search-with-algolia' ), + 'typesense_override_native_search', + esc_html__( 'Search results', 'wp-search-with-typesense' ), array( $this, 'override_native_search_callback' ), $this->slug, $this->section ); - register_setting( $this->option_group, 'algolia_override_native_search', array( $this, 'sanitize_override_native_search' ) ); + register_setting( $this->option_group, 'typesense_override_native_search', array( $this, 'sanitize_override_native_search' ) ); } /** @@ -151,14 +152,14 @@ public function sanitize_override_native_search( $value ) { add_settings_error( $this->option_group, 'native_search_enabled', - esc_html__( 'WordPress search is now based on Algolia!', 'wp-search-with-algolia' ), + esc_html__( 'WordPress search is now based on Typesense!', 'wp-search-with-typesense' ), 'updated' ); } elseif ( 'instantsearch' === $value ) { add_settings_error( $this->option_group, 'native_search_enabled', - esc_html__( 'WordPress search is now based on Algolia instantsearch.js!', 'wp-search-with-algolia' ), + esc_html__( 'WordPress search is now based on Typesense instantsearch.js!', 'wp-search-with-typesense' ), 'updated' ); } else { @@ -166,7 +167,7 @@ public function sanitize_override_native_search( $value ) { add_settings_error( $this->option_group, 'native_search_disabled', - esc_html__( 'You chose to keep the WordPress native search instead of Algolia. If you are using the autocomplete feature of the plugin we highly recommend you turn Algolia search on instead of the WordPress native search.', 'wp-search-with-algolia' ), + esc_html__( 'You chose to keep the WordPress native search instead of Typesense. If you are using the autocomplete feature of the plugin we highly recommend you turn Typesense search on instead of the WordPress native search.', 'wp-search-with-typesense' ), 'updated' ); } @@ -195,7 +196,7 @@ public function display_page() { public function display_errors() { settings_errors( $this->option_group ); - if ( defined( 'ALGOLIA_HIDE_HELP_NOTICES' ) && ALGOLIA_HIDE_HELP_NOTICES ) { + if ( defined( 'TYPESENSE_HIDE_HELP_NOTICES' ) && TYPESENSE_HIDE_HELP_NOTICES ) { return; } @@ -210,7 +211,7 @@ public function display_errors() { $searchable_posts_index = $this->plugin->get_index( 'searchable_posts' ); if ( false === $searchable_posts_index->is_enabled() && ( ! empty( $maybe_get_page ) ) && $maybe_get_page === $this->slug ) { /* translators: placeholder contains the link to the indexing page. */ - $message = sprintf( __( 'Searchable posts index needs to be checked on the Algolia: Indexing page for the search results to be powered by Algolia.', 'wp-search-with-algolia' ), esc_url( admin_url( 'admin.php?page=algolia-indexing' ) ) ); + $message = sprintf( __( 'Searchable posts index needs to be checked on the Typesense: Indexing page for the search results to be powered by Typesense.', 'wp-search-with-typesense' ), esc_url( admin_url( 'admin.php?page=typesense-indexing' ) ) ); echo '

' . wp_kses_post( $message ) . '

'; @@ -224,7 +225,7 @@ public function display_errors() { * @since 1.0.0 */ public function print_section_settings() { - echo '

' . esc_html__( 'By enabling this plugin to override the native WordPress search, your search results will be powered by Algolia\'s typo-tolerant & relevant search algorithms.', 'wp-search-with-algolia' ) . '

'; + echo '

' . esc_html__( 'By enabling this plugin to override the native WordPress search, your search results will be powered by Typesense\'s typo-tolerant & relevant search algorithms.', 'wp-search-with-typesense' ) . '

'; // @Todo: replace this with a check on the searchable_posts_index. $indices = $this->plugin->get_indices( @@ -236,7 +237,7 @@ public function print_section_settings() { if ( empty( $indices ) ) { echo '
' . - esc_html( __( 'You have no index containing only posts yet. Please index some content on the `Indexing` page.', 'wp-search-with-algolia' ) ) . + esc_html( __( 'You have no index containing only posts yet. Please index some content on the `Indexing` page.', 'wp-search-with-typesense' ) ) . '
'; } } diff --git a/includes/admin/class-algolia-admin-page-settings.php b/includes/admin/class-algolia-admin-page-settings.php index 041e5c8..a16b4ba 100644 --- a/includes/admin/class-algolia-admin-page-settings.php +++ b/includes/admin/class-algolia-admin-page-settings.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -9,11 +9,11 @@ */ /** - * Class Algolia_Admin_Page_Settings + * Class Typesense_Admin_Page_Settings * * @since 1.0.0 */ -class Algolia_Admin_Page_Settings { +class Typesense_Admin_Page_Settings { /** * Admin page slug. @@ -23,7 +23,7 @@ class Algolia_Admin_Page_Settings { * * @var string */ - private $slug = 'algolia-account-settings'; + private $slug = 'typesense-account-settings'; /** * Admin page capabilities. @@ -43,7 +43,7 @@ class Algolia_Admin_Page_Settings { * * @var string */ - private $section = 'algolia_section_settings'; + private $section = 'typesense_section_settings'; /** * Admin page option group. @@ -53,27 +53,27 @@ class Algolia_Admin_Page_Settings { * * @var string */ - private $option_group = 'algolia_settings'; + private $option_group = 'typesense_settings'; /** - * The Algolia_Plugin instance. + * The Typesense_Plugin instance. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Plugin + * @var Typesense_Plugin */ private $plugin; /** - * Algolia_Admin_Page_Settings constructor. + * Typesense_Admin_Page_Settings constructor. * * @author WebDevStudios * @since 1.0.0 * - * @param Algolia_Plugin $plugin The Algolia_Plugin instance. + * @param Typesense_Plugin $plugin The Typesense_Plugin instance. */ - public function __construct( Algolia_Plugin $plugin ) { + public function __construct( Typesense_Plugin $plugin ) { $this->plugin = $plugin; add_action( 'admin_menu', array( $this, 'add_page' ) ); @@ -81,7 +81,7 @@ public function __construct( Algolia_Plugin $plugin ) { add_action( 'admin_notices', array( $this, 'display_errors' ) ); // Display a link to this page from the plugins page. - add_filter( 'plugin_action_links_' . ALGOLIA_PLUGIN_BASENAME, array( $this, 'add_action_links' ) ); + add_filter( 'plugin_action_links_' . TYPESENSE_PLUGIN_BASENAME, array( $this, 'add_action_links' ) ); } /** @@ -97,7 +97,7 @@ public function __construct( Algolia_Plugin $plugin ) { public function add_action_links( array $links ) { return array_merge( $links, array( - '' . esc_html__( 'Settings', 'wp-search-with-algolia' ) . '', + '' . esc_html__( 'Settings', 'wp-search-with-typesense' ) . '', ) ); } @@ -112,22 +112,10 @@ public function add_action_links( array $links ) { */ public function add_page() { $api = $this->plugin->get_api(); - if ( ! $api->is_reachable() ) { - // Means this is the only reachable admin page, so make it the default one! - return add_menu_page( - 'WP Search with Algolia', - esc_html__( 'Algolia Search', 'wp-search-with-algolia' ), - 'manage_options', - $this->slug, - array( $this, 'display_page' ), - '' - ); - } - add_submenu_page( - 'algolia', - esc_html__( 'Settings', 'wp-search-with-algolia' ), - esc_html__( 'Settings', 'wp-search-with-algolia' ), + 'typesense', + esc_html__( 'Settings', 'wp-search-with-typesense' ), + esc_html__( 'Settings', 'wp-search-with-typesense' ), $this->capability, $this->slug, array( $this, 'display_page' ) @@ -147,52 +135,49 @@ public function add_settings() { array( $this, 'print_section_settings' ), $this->slug ); - add_settings_field( - 'algolia_application_id', - esc_html__( 'Application ID', 'wp-search-with-algolia' ), - array( $this, 'application_id_callback' ), + 'typesense_api_key', + esc_html__( 'API key', 'wp-search-with-typesense' ), + array( $this, 'api_key_callback' ), $this->slug, $this->section ); add_settings_field( - 'algolia_search_api_key', - esc_html__( 'Search-only API key', 'wp-search-with-algolia' ), - array( $this, 'search_api_key_callback' ), + 'typesense_host', + esc_html__( 'Server Host', 'wp-search-with-typesense' ), + array( $this, 'host_callback' ), $this->slug, $this->section ); add_settings_field( - 'algolia_api_key', - esc_html__( 'Admin API key', 'wp-search-with-algolia' ), - array( $this, 'api_key_callback' ), + 'typesense_port', + esc_html__( 'Server Port', 'wp-search-with-typesense' ), + array( $this, 'port_callback' ), $this->slug, $this->section ); add_settings_field( - 'algolia_index_name_prefix', - esc_html__( 'Index name prefix', 'wp-search-with-algolia' ), + 'typesense_index_name_prefix', + esc_html__( 'Index name prefix', 'wp-search-with-typesense' ), array( $this, 'index_name_prefix_callback' ), $this->slug, $this->section ); add_settings_field( - 'algolia_powered_by_enabled', - esc_html__( 'Remove Algolia powered by logo', 'wp-search-with-algolia' ), + 'typesense_powered_by_enabled', + esc_html__( 'Remove Typesense powered by logo', 'wp-search-with-typesense' ), array( $this, 'powered_by_enabled_callback' ), $this->slug, $this->section ); - register_setting( $this->option_group, 'algolia_application_id', array( $this, 'sanitize_application_id' ) ); - register_setting( $this->option_group, 'algolia_search_api_key', array( $this, 'sanitize_search_api_key' ) ); - register_setting( $this->option_group, 'algolia_api_key', array( $this, 'sanitize_api_key' ) ); - register_setting( $this->option_group, 'algolia_index_name_prefix', array( $this, 'sanitize_index_name_prefix' ) ); - register_setting( $this->option_group, 'algolia_powered_by_enabled', array( $this, 'sanitize_powered_by_enabled' ) ); + register_setting( $this->option_group, 'typesense_port' ); + register_setting( $this->option_group, 'typesense_host'); + register_setting( $this->option_group, 'typesense_api_key' ); } /** @@ -207,8 +192,8 @@ public function application_id_callback() { $setting = $settings->get_application_id(); $disabled_html = $settings->is_application_id_in_config() ? ' disabled' : ''; ?> - /> -

+ /> +

is_search_api_key_in_config() ? ' disabled' : ''; ?> - /> -

+ /> +

plugin->get_settings(); + $setting = $settings->get_host(); + +?> + +

+plugin->get_settings(); + $setting = $settings->get_port(); +?> + +

+plugin->get_settings(); $setting = $settings->get_api_key(); - $disabled_html = $settings->is_api_key_in_config() ? ' disabled' : ''; ?> - /> -

+ +

get_index_name_prefix(); $disabled_html = $settings->is_index_name_prefix_in_config() ? ' disabled' : ''; ?> - /> -

+ /> +

' . - '

' . esc_html( __( 'This will remove the Algolia logo from the autocomplete and the search page. We require that you keep the Algolia logo if you are using a free plan.', 'wp-search-with-algolia' ) ) . '

'; + echo "' . + '

' . esc_html( __( 'This will remove the Typesense logo from the autocomplete and the search page. We require that you keep the Typesense logo if you are using a free plan.', 'wp-search-with-typesense' ) ) . '

'; } /** @@ -297,7 +299,7 @@ public function sanitize_application_id( $value ) { add_settings_error( $this->option_group, 'empty', - esc_html__( 'Application ID should not be empty.', 'wp-search-with-algolia' ) + esc_html__( 'Application ID should not be empty.', 'wp-search-with-typesense' ) ); } @@ -315,103 +317,43 @@ public function sanitize_application_id( $value ) { * * @return string */ - public function sanitize_search_api_key( $value ) { - if ( $this->plugin->get_settings()->is_search_api_key_in_config() ) { - $value = $this->plugin->get_settings()->get_search_api_key(); - } + public function sanitize_api_key( $value ) { + //if ( $this->plugin->get_settings()->is_search_api_key_in_config() ) { + $value = $this->plugin->get_settings()->get_api_key(); + //} $value = sanitize_text_field( $value ); if ( empty( $value ) ) { add_settings_error( $this->option_group, 'empty', - esc_html__( 'Search-only API key should not be empty.', 'wp-search-with-algolia' ) + esc_html__( 'API key should not be empty.', 'wp-search-with-typesense' ) ); } return $value; } - /** - * Sanitize Admin API key. - * - * @author Richard Aber - * @since 2020-07-24 - * - * @param string $value The value to sanitize. - * - * @return string - */ - public function sanitize_api_key( $value ) { - if ( $this->plugin->get_settings()->is_api_key_in_config() ) { - $value = $this->plugin->get_settings()->get_api_key(); - } + public function sanitize_host( $value ) { + $value = $this->plugin->get_settings()->get_host(); $value = sanitize_text_field( $value ); if ( empty( $value ) ) { add_settings_error( $this->option_group, 'empty', - esc_html__( 'API key should not be empty', 'wp-search-with-algolia' ) - ); - } - - $errors = get_settings_errors( $this->option_group ); - - // @todo Not 100% clear why this is returning here. - if ( ! empty( $errors ) ) { - return $value; - } - - $settings = $this->plugin->get_settings(); - - $valid_credentials = true; - try { - Algolia_API::assert_valid_credentials( $settings->get_application_id(), $value ); - } catch ( Exception $exception ) { - $valid_credentials = false; - add_settings_error( - $this->option_group, - 'login_exception', - $exception->getMessage() - ); - } - - if ( ! $valid_credentials ) { - add_settings_error( - $this->option_group, - 'no_connection', - esc_html__( - 'We were unable to authenticate you against the Algolia servers with the provided information. Please ensure that you used a valid Application ID and Admin API key.', - 'wp-search-with-algolia' - ) + esc_html__( 'Host should not be empty.', 'wp-search-with-typesense' ) ); - $settings->set_api_is_reachable( false ); - } else { - if ( ! Algolia_API::is_valid_search_api_key( $settings->get_application_id(), $settings->get_search_api_key() ) ) { - add_settings_error( - $this->option_group, - 'wrong_search_API_key', - esc_html__( - 'It looks like your search API key is wrong. Ensure that the key you entered has only the search capability and nothing else. Also ensure that the key has no limited time validity.', - 'wp-search-with-algolia' - ) - ); - $settings->set_api_is_reachable( false ); - } else { - add_settings_error( - $this->option_group, - 'connection_success', - esc_html__( 'We succesfully managed to connect to the Algolia servers with the provided information. Your search API key has also been checked and is OK.', 'wp-search-with-algolia' ), - 'updated' - ); - $settings->set_api_is_reachable( true ); - } } return $value; } + public function sanitize_port( $value ) { + $value = $this->plugin->get_settings()->get_port(); + $value = sanitize_text_field( $value ); + return $value; + } /** * Determine if the index name prefix is valid. * @@ -450,10 +392,10 @@ public function sanitize_index_name_prefix( $value ) { add_settings_error( $this->option_group, 'wrong_prefix', - esc_html__( 'Indices prefix can only contain alphanumeric characters and underscores.', 'wp-search-with-algolia' ) + esc_html__( 'Indices prefix can only contain alphanumeric characters and underscores.', 'wp-search-with-typesense' ) ); - $value = get_option( 'algolia_index_name_prefix' ); + $value = get_option( 'typesense_index_name_prefix' ); return $this->is_valid_index_name_prefix( $value ) ? $value : 'wp_'; } @@ -499,9 +441,9 @@ public function display_errors() { * @since 1.0.0 */ public function print_section_settings() { - echo '

' . esc_html__( 'Configure your Algolia account credentials. You can find them in the "API Keys" section of your Algolia dashboard.', 'wp-search-with-algolia' ) . '

'; - echo '

' . esc_html__( 'Once you provide your Algolia Application ID and API key, this plugin will be able to securely communicate with Algolia servers.', 'wp-search-with-algolia' ) . ' ' . esc_html__( 'We ensure your information is correct by testing them against the Algolia servers upon save.', 'wp-search-with-algolia' ) . '

'; - /* translators: the placeholder contains the URL to Algolia's website. */ - echo '

' . wp_kses_post( sprintf( __( 'No Algolia account yet? Follow this link to create one for free in a couple of minutes!', 'wp-search-with-algolia' ), 'https://www.algolia.com/users/sign_up' ) ) . '

'; + echo '

' . esc_html__( 'Configure your Typesense account credentials. You can find them in the "API Keys" section of your Typesense dashboard.', 'wp-search-with-typesense' ) . '

'; + echo '

' . esc_html__( 'Once you provide your Typesense Application ID and API key, this plugin will be able to securely communicate with Typesense servers.', 'wp-search-with-typesense' ) . ' ' . esc_html__( 'We ensure your information is correct by testing them against the Typesense servers upon save.', 'wp-search-with-typesense' ) . '

'; + /* translators: the placeholder contains the URL to Typesense's website. */ + echo '

' . wp_kses_post( sprintf( __( 'No Typesense account yet? Follow this link to create one for free in a couple of minutes!', 'wp-search-with-typesense' ), 'https://www.typesense.com/users/sign_up' ) ) . '

'; } } diff --git a/includes/admin/class-algolia-admin.php b/includes/admin/class-algolia-admin.php index c5b498c..c9e9414 100644 --- a/includes/admin/class-algolia-admin.php +++ b/includes/admin/class-algolia-admin.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -9,50 +9,44 @@ */ /** - * Class Algolia_Admin + * Class Typesense_Admin * * @since 1.0.0 */ -class Algolia_Admin { + +use Typesense\Client; +class Typesense_Admin { /** - * The Algolia Plugin. + * The Typesense Plugin. * * @since 1.0.0 * - * @var Algolia_Plugin + * @var Typesense_Plugin */ private $plugin; /** - * Algolia_Admin constructor. + * Typesense_Admin constructor. * * @author WebDevStudios * @since 1.0.0 * - * @param Algolia_Plugin $plugin The Algolia Plugin. + * @param Typesense_Plugin $plugin The Typesense Plugin. */ - public function __construct( Algolia_Plugin $plugin ) { + public function __construct( Typesense_Plugin $plugin ) { $this->plugin = $plugin; add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); $api = $plugin->get_api(); - if ( $api->is_reachable() ) { - new Algolia_Admin_Page_Autocomplete( $plugin->get_settings(), $this->plugin->get_autocomplete_config() ); - new Algolia_Admin_Page_Native_Search( $plugin ); + new Typesense_Admin_Page_Autocomplete( $plugin->get_settings(), $plugin->get_autocomplete_config()); + new Typesense_Admin_Page_Native_Search( $plugin ); - add_action( 'wp_ajax_algolia_re_index', array( $this, 're_index' ) ); - add_action( 'wp_ajax_algolia_push_settings', array( $this, 'push_settings' ) ); + add_action( 'wp_ajax_typesense_re_index', array( $this, 're_index' ) ); - $maybe_get_page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING ); - if ( ! empty( $maybe_get_page ) && 'algolia' === substr( $maybe_get_page, 0, 7 ) ) { - add_action( 'admin_notices', array( $this, 'display_reindexing_notices' ) ); - } - } - - new Algolia_Admin_Page_Settings( $plugin ); + new Typesense_Admin_Page_Settings( $plugin ); add_action( 'admin_notices', array( $this, 'display_unmet_requirements_notices' ) ); } @@ -64,7 +58,7 @@ public function __construct( Algolia_Plugin $plugin ) { * @since 1.0.0 */ public function enqueue_styles() { - wp_enqueue_style( 'algolia-admin', plugin_dir_url( __FILE__ ) . 'css/algolia-admin.css', array(), ALGOLIA_VERSION ); + wp_enqueue_style( 'typesense-admin', plugin_dir_url( __FILE__ ) . 'css/typesense-admin.css', array(), TYPESENSE_VERSION ); } /** @@ -75,26 +69,14 @@ public function enqueue_styles() { */ public function enqueue_scripts() { wp_enqueue_script( - 'algolia-admin', - plugin_dir_url( __FILE__ ) . 'js/algolia-admin.js', - array( 'jquery', 'jquery-ui-sortable' ), - ALGOLIA_VERSION, - false - ); - wp_enqueue_script( - 'algolia-admin-reindex-button', + 'typesense-admin-reindex-button', plugin_dir_url( __FILE__ ) . 'js/reindex-button.js', array( 'jquery' ), - ALGOLIA_VERSION, - false - ); - wp_enqueue_script( - 'algolia-admin-push-settings-button', - plugin_dir_url( __FILE__ ) . 'js/push-settings-button.js', - array( 'jquery' ), - ALGOLIA_VERSION, + TYPESENSE_VERSION, false ); + wp_localize_script( 'ajax-script', 'ajax_object', + array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) ); } /** @@ -108,17 +90,17 @@ public function enqueue_scripts() { public function display_unmet_requirements_notices() { if ( ! extension_loaded( 'mbstring' ) ) { echo '
-

' . esc_html__( 'Algolia Search requires the "mbstring" PHP extension to be enabled. Please contact your hosting provider.', 'wp-search-with-algolia' ) . '

+

' . esc_html__( 'Typesense Search requires the "mbstring" PHP extension to be enabled. Please contact your hosting provider.', 'wp-search-with-typesense' ) . '

'; } elseif ( ! function_exists( 'mb_ereg_replace' ) ) { echo '
-

' . esc_html__( 'Algolia needs "mbregex" NOT to be disabled. Please contact your hosting provider.', 'wp-search-with-algolia' ) . '

+

' . esc_html__( 'Typesense needs "mbregex" NOT to be disabled. Please contact your hosting provider.', 'wp-search-with-typesense' ) . '

'; } if ( ! extension_loaded( 'curl' ) ) { echo '
-

' . esc_html__( 'Algolia Search requires the "cURL" PHP extension to be enabled. Please contact your hosting provider.', 'wp-search-with-algolia' ) . '

+

' . esc_html__( 'Typesense Search requires the "cURL" PHP extension to be enabled. Please contact your hosting provider.', 'wp-search-with-typesense' ) . '

'; return; @@ -128,7 +110,7 @@ public function display_unmet_requirements_notices() { } /** - * Display notice to help users adding 'algolia_' as an ignored query string to the db caching configuration. + * Display notice to help users adding 'typesense_' as an ignored query string to the db caching configuration. * * @author WebDevStudios * @since 1.0.0 @@ -144,9 +126,9 @@ public function w3tc_notice() { $enabled = $config->get_integer( 'dbcache.enabled' ); $settings = array_map( 'trim', $config->get_array( 'dbcache.reject.sql' ) ); - if ( $enabled && ! in_array( 'algolia_', $settings, true ) ) { + if ( $enabled && ! in_array( 'typesense_', $settings, true ) ) { /* translators: placeholder contains the URL to the caching plugin's config page. */ - $message = sprintf( __( 'In order for database caching to work with Algolia you must add algolia_ to the "Ignored Query Stems" option in W3 Total Cache settings here.', 'wp-search-with-algolia' ), esc_url( admin_url( 'admin.php?page=w3tc_dbcache' ) ) ); + $message = sprintf( __( 'In order for database caching to work with Typesense you must add typesense_ to the "Ignored Query Stems" option in W3 Total Cache settings here.', 'wp-search-with-typesense' ), esc_url( admin_url( 'admin.php?page=w3tc_dbcache' ) ) ); ?>

@@ -182,8 +164,8 @@ public function display_reindexing_notices() { %1$s', 'wp-search-with-algolia' ), + /* Translators: placeholder is an Typesense index name. */ + __( 'For Typesense search to work properly, you need to index: %1$s', 'wp-search-with-typesense' ), esc_html( $index->get_admin_name() ) ), $allowed_html @@ -191,8 +173,8 @@ public function display_reindexing_notices() { ?>

-

@@ -210,77 +192,39 @@ public function display_reindexing_notices() { * @throws Exception If index ID or page are not provided, or index name dies not exist. */ public function re_index() { - - $index_id = filter_input( INPUT_POST, 'index_id', FILTER_SANITIZE_STRING ); - $page = filter_input( INPUT_POST, 'p', FILTER_SANITIZE_STRING ); - - try { - if ( empty( $index_id ) ) { - throw new RuntimeException( 'Index ID should be provided.' ); - } - - if ( ! ctype_digit( $page ) ) { - throw new RuntimeException( 'Page should be provided.' ); + + $index_id = $_GET['index']; + $document = [ + 'post_id' => '1', + 'id' => '500', + 'post_content' => 'New world', + 'post_title' => 'Dummy text 2', + 'post_excerpt' => 'dcd', + 'is_sticky' => 1, + + 'post_modified' => 'fwecfwe', + 'post_date' => 'cwe', + + 'comment_count' => 2, + ]; + $indices = $this->plugin->get_indices(); + try{ + $terms = get_terms(array( + 'taxonomy' => 'category', + 'hide_empty' => false + )); + foreach($terms as $term){ + try{ + $indices[1]->sync($term); + } + catch(Exception $e){ + continue; + } } - $page = (int) $page; - - $index = $this->plugin->get_index( $index_id ); - if ( null === $index ) { - throw new RuntimeException( sprintf( 'Index named %s does not exist.', $index_id ) ); - } - - $total_pages = $index->get_re_index_max_num_pages(); - - ob_start(); - if ( $page <= $total_pages || 0 === $total_pages ) { - $index->re_index( $page ); - } - ob_end_clean(); - - $response = array( - 'totalPagesCount' => $total_pages, - 'finished' => $page >= $total_pages, - ); - - wp_send_json( $response ); - } catch ( Exception $exception ) { - echo esc_html( $exception->getMessage() ); - throw $exception; + throw new RuntimeException('All records indexed'); } - } - - /** - * Push settings. - * - * @author WebDevStudios - * @since 1.0.0 - * - * @throws RuntimeException If index_id is not provided or if the corresponding index is null. - * @throws Exception If index_id is not provided or if the corresponding index is null. - */ - public function push_settings() { - - $index_id = filter_input( INPUT_POST, 'index_id', FILTER_SANITIZE_STRING ); - - try { - if ( empty( $index_id ) ) { - throw new RuntimeException( 'index_id should be provided.' ); - } - - $index = $this->plugin->get_index( $index_id ); - if ( null === $index ) { - throw new RuntimeException( sprintf( 'Index named %s does not exist.', $index_id ) ); - } - - $index->push_settings(); - - $response = array( - 'success' => true, - ); - wp_send_json( $response ); - } catch ( Exception $exception ) { - echo esc_html( $exception->getMessage() ); - throw $exception; + catch(Exception $e){ + echo $e->getMessage(); } } } diff --git a/includes/admin/css/typesense-admin.css b/includes/admin/css/typesense-admin.css new file mode 100644 index 0000000..5974914 --- /dev/null +++ b/includes/admin/css/typesense-admin.css @@ -0,0 +1,61 @@ +/** + * All of the CSS for your admin-specific functionality should be + * included in this file. + */ +.form-table .table-autocomplete th { + padding: 8px 10px !important; + +} + +.form-table .table-autocomplete { + width: auto; +} + +.table-autocomplete .dashicons-move { + cursor: pointer; +} + +/* Override admin menu styles for the algolia icon */ +@font-face { + font-family: 'algolia'; + src: url('../fonts/algolia.eot?nqrd9q'); + src: url('../fonts/algolia.eot?nqrd9q#iefix') format('embedded-opentype'), + url('../fonts/algolia.ttf?nqrd9q') format('truetype'), + url('../fonts/algolia.woff?nqrd9q') format('woff'), + url('../fonts/algolia.svg?nqrd9q#algolia') format('svg'); + font-weight: normal; + font-style: normal; +} + +#adminmenu #toplevel_page_algolia .menu-icon-generic div.wp-menu-image:before, +#adminmenu #toplevel_page_algolia-account-settings .menu-icon-generic div.wp-menu-image:before { + font-family: algolia !important; + content: "\e900"; +} + +/* Logs page */ +.log-details { + background-color: #32373c; + color: #FFF; + padding: 30px; + border-radius: 3px; + display: none; +} + +/* Native search page */ +form .input-radio label { + font-weight: bold; +} +form .radio-info { + margin-bottom: 15px; + padding-left: 25px; +} + +/* Indexing page */ +.failed-task, .status-running, .status-idle, #delete-pending-tasks, .current-task, .run-queue-link, .stop-queue-link { + display: none; +} + +#delete-pending-tasks { + display: none; +} diff --git a/includes/admin/fonts/algolia.eot b/includes/admin/fonts/algolia.eot old mode 100755 new mode 100644 diff --git a/includes/admin/fonts/algolia.svg b/includes/admin/fonts/algolia.svg old mode 100755 new mode 100644 diff --git a/includes/admin/fonts/algolia.ttf b/includes/admin/fonts/algolia.ttf old mode 100755 new mode 100644 diff --git a/includes/admin/fonts/algolia.woff b/includes/admin/fonts/algolia.woff old mode 100755 new mode 100644 diff --git a/includes/admin/js/push-settings-button.js b/includes/admin/js/push-settings-button.js index bf9ac50..8d080ea 100644 --- a/includes/admin/js/push-settings-button.js +++ b/includes/admin/js/push-settings-button.js @@ -36,12 +36,6 @@ $.post( ajaxurl, data, function(response) { - if (typeof response.success === 'undefined') { - alert( 'An error occurred' ); - enableButton( $clickedButton ); - return; - } - alert( 'Settings correctly pushed for index: ' + index ); enableButton( $clickedButton ); } diff --git a/includes/admin/js/reindex-button.js b/includes/admin/js/reindex-button.js index b5c47c4..a93ac1e 100644 --- a/includes/admin/js/reindex-button.js +++ b/includes/admin/js/reindex-button.js @@ -2,89 +2,46 @@ $( function() { - var $reindexButtons = $( '.algolia-reindex-button' ); - $reindexButtons.on( 'click', handleReindexButtonClick ); + var $buttons = $( '.typesense-reindex-button' ); + $buttons.on( 'click', handleButtonClick ); } ); - var ongoing = 0; + function handleButtonClick(e) { + $clickedButton = $( e.currentTarget ); + var index = $clickedButton.data( 'index_id' ); + disableButton( $clickedButton ); - $( window ).on( - 'beforeunload', function() { - if (ongoing > 0) { - return 'If you leave now, re-indexing tasks in progress will be aborted'; - } - } - ); - - function handleReindexButtonClick(e) { - - $clickedButton = $( e.currentTarget ); - var index = $clickedButton.data( 'index' ); - if ( ! index) { - throw new Error( 'Clicked button has no "data-index" set.' ); - } - - ongoing++; - - $clickedButton.attr( 'disabled', 'disabled' ); - $clickedButton.data( 'originalText', $clickedButton.text() ); - updateIndexingPourcentage( $clickedButton, 0 ); + pushSettings( $clickedButton,index); + //alert('wefwerfwfer'); + } - reIndex( $clickedButton, index ); + function disableButton($button) { + $button.prop( 'disabled', true ); } - function updateIndexingPourcentage($clickedButton, amount) { - $clickedButton.text( 'Processing, please be patient ... ' + amount + '%' ); + function enableButton($button) { + $button.prop( 'disabled', false ); } - function reIndex($clickedButton, index, currentPage) { - if ( ! currentPage) { - currentPage = 1; - } + function pushSettings($clickedButton,index) { var data = { - 'action': 'algolia_re_index', - 'index_id': index, - 'p': currentPage + 'action': 'typesense_re_index', + index: 'qwe' }; $.post( ajaxurl, data, function(response) { - if (typeof response.totalPagesCount === 'undefined') { - alert( 'An error occurred' ); - resetButton( $clickedButton ); - return; - } - - if (response.totalPagesCount === 0) { - $clickedButton.parents( '.error' ).fadeOut(); - resetButton( $clickedButton ); - return; - } - progress = Math.round( (currentPage / response.totalPagesCount) * 100 ); - updateIndexingPourcentage( $clickedButton, progress ); - - if (response.finished !== true) { - reIndex( $clickedButton, index, ++currentPage ); - } else { - $clickedButton.parents( '.error' ).fadeOut(); - resetButton( $clickedButton ); - } + alert(response); + enableButton( $clickedButton ); } ).fail( function(response) { alert( 'An error occurred: ' + response.responseText ); - resetButton( $clickedButton ); + enableButton( $clickedButton ); } ); } - function resetButton($clickedButton) { - ongoing--; - $clickedButton.text( $clickedButton.data( 'originalText' ) ); - $clickedButton.removeAttr( 'disabled' ); - $clickedButton.data( 'currentPage', 1 ); - } - })( jQuery ); diff --git a/includes/admin/partials/form-override-search-option.php b/includes/admin/partials/form-override-search-option.php index 29d83cf..70c6517 100644 --- a/includes/admin/partials/form-override-search-option.php +++ b/includes/admin/partials/form-override-search-option.php @@ -13,15 +13,15 @@
This is only a valid option if you wish to search on your content from another website.', - 'wp-search-with-algolia' + 'Do not use Typesense for searching at all.
This is only a valid option if you wish to search on your content from another website.', + 'wp-search-with-typesense' ), [ 'br' => [], @@ -32,15 +32,15 @@
This will allow your search results to be typo tolerant.
This option does not support filtering and displaying instant search results but has the advantage to play nicely with any theme.', - 'wp-search-with-algolia' + 'With this option WordPress search will be powered by Typesense behind the scenes.
This will allow your search results to be typo tolerant.
This option does not support filtering and displaying instant search results but has the advantage to play nicely with any theme.', + 'wp-search-with-typesense' ), [ 'br' => [], @@ -52,15 +52,15 @@
By default you will be able to filter by post type, categories, tags and authors.
Please note that the plugin is shipped with some sensible default styling rules
but it could require some CSS adjustments to provide an optimal search experience.', - 'wp-search-with-algolia' + 'This will replace the search page with an instant search experience powered by Typesense.
By default you will be able to filter by post type, categories, tags and authors.
Please note that the plugin is shipped with some sensible default styling rules
but it could require some CSS adjustments to provide an optimal search experience.', + 'wp-search-with-typesense' ), [ 'br' => [], diff --git a/includes/admin/partials/index-records.php b/includes/admin/partials/index-records.php new file mode 100644 index 0000000..7221501 --- /dev/null +++ b/includes/admin/partials/index-records.php @@ -0,0 +1,22 @@ + + + + + + + + + + + + +
+ +
+

+ +
+ +
+ +

diff --git a/includes/admin/partials/page-autocomplete-config.php b/includes/admin/partials/page-autocomplete-config.php index 05d6f7d..e968c58 100644 --- a/includes/admin/partials/page-autocomplete-config.php +++ b/includes/admin/partials/page-autocomplete-config.php @@ -14,11 +14,11 @@ - - - - - + + + + + @@ -26,41 +26,41 @@ - + - /> + />
- + - + - - + +

- +
- +
- +

diff --git a/includes/admin/partials/page-search.php b/includes/admin/partials/page-search.php index 8186544..1a5f2f1 100644 --- a/includes/admin/partials/page-search.php +++ b/includes/admin/partials/page-search.php @@ -13,11 +13,11 @@

- -

diff --git a/includes/class-algolia-api.php b/includes/class-algolia-api.php index 7fd9b88..0e9a17d 100644 --- a/includes/class-algolia-api.php +++ b/includes/class-algolia-api.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -8,45 +8,44 @@ * @package WebDevStudios\WPSWA */ -use Algolia\AlgoliaSearch\Exceptions\AlgoliaException; -use Algolia\AlgoliaSearch\SearchClient; +use Typesense\Client; /** - * Class Algolia_API + * Class Typesense_API * * @since 1.0.0 */ -class Algolia_API { +class Typesense_API { /** - * The SearchClient instance. + * The Client instance. * * @author WebDevStudios * @since 1.0.0 * - * @var SearchClient + * @var Client */ private $client; /** - * The Algolia_Settings instance. + * The Typesense_Settings instance. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Settings + * @var Typesense_Settings */ private $settings; - + public $dummy; /** - * Algolia_API constructor. + * Typesense_API constructor. * * @author WebDevStudios * @since 1.0.0 * - * @param Algolia_Settings $settings The Algolia_Settings instance. + * @param Typesense_Settings $settings The Typesense_Settings instance. */ - public function __construct( Algolia_Settings $settings ) { + public function __construct( Typesense_Settings $settings ) { $this->settings = $settings; } @@ -64,8 +63,6 @@ public function is_reachable() { } try { - // Here we check that all requirements for the PHP API SearchClient are met. - // If they are not, instantiating the client will throw exceptions. $client = $this->get_client(); } catch ( Exception $e ) { return false; @@ -75,167 +72,40 @@ public function is_reachable() { } /** - * Get the SearchClient. + * Get the Client. * * @author WebDevStudios * @since 1.0.0 * - * @return SearchClient|null + * @return Client|null */ - public function get_client(): ?SearchClient { - - $application_id = $this->settings->get_application_id(); - $api_key = $this->settings->get_api_key(); - - if ( - empty( $application_id ) || - empty( $api_key ) - ) { - return null; - } - - if ( null === $this->client ) { - $this->client = Algolia_Search_Client_Factory::create( - (string) $this->settings->get_application_id(), - (string) $this->settings->get_api_key() - ); - } + public function get_client(){ + $api_key = (string)$this->settings->get_api_key(); + $host = (string)$this->settings->get_host(); + $port = (string)$this->settings->get_port(); + + if ( + empty( $api_key ) || + empty( $host ) + ) { + return null; + } + + + $this->client = new Client( + [ + 'api_key' => $api_key, + 'nodes' => [ + [ + 'host' => $host, + 'port' => $port, + 'protocol' => 'http', + ], + ], + 'connection_timeout_seconds' => 2, + ] + ); return $this->client; } - - /** - * Assert that the credentials are valid. - * - * @author WebDevStudios - * @since 1.0.0 - * - * @param string $application_id The Algolia Application ID. - * @param string $api_key The Algolia Admin API Key. - * - * @return void - * - * @throws Exception If the Algolia Admin API Key does not have correct ACLs. - */ - public static function assert_valid_credentials( $application_id, $api_key ) { - - $client = Algolia_Search_Client_Factory::create( - (string) $application_id, - (string) $api_key - ); - - // This checks if the API Key is an Admin API key. - // Admin API keys have no scopes so we need a separate check here. - try { - $client->listApiKeys(); - - return; - } catch ( Exception $exception ) { // phpcs:ignore --- intentionally empty catch. - } - - // If this call does not succeed, then the application_ID or API_key is/are wrong. - // This will raise an exception. - $key = $client->getApiKey( (string) $api_key ); - - $required_acls = array( - 'addObject', - 'deleteObject', - 'listIndexes', - 'deleteIndex', - 'settings', - 'editSettings', - ); - - $missing_acls = array(); - foreach ( $required_acls as $required_acl ) { - if ( ! in_array( $required_acl, $key['acl'], true ) ) { - $missing_acls[] = $required_acl; - } - } - - if ( ! empty( $missing_acls ) ) { - throw new Exception( - 'Your admin API key is missing the following ACLs: ' . implode( ', ', $missing_acls ) - ); - } - } - - /** - * Check if the credentials are valid. - * - * @author WebDevStudios - * @since 1.0.0 - * - * @param string $application_id The Algolia Application ID. - * @param string $api_key The Algolia Admin API Key. - * - * @return bool - */ - public static function is_valid_credentials( $application_id, $api_key ) { - try { - self::assert_valid_credentials( $application_id, $api_key ); - } catch ( Exception $e ) { - return false; - } - - return true; - } - - /** - * Check if the Search API Key is valid. - * - * @author WebDevStudios - * @since 1.0.0 - * - * @param string $application_id The Algolia Application ID. - * @param string $search_api_key The Algolia Search API Key. - * - * @return bool - */ - public static function is_valid_search_api_key( $application_id, $search_api_key ) { - - $client = Algolia_Search_Client_Factory::create( - (string) $application_id, - (string) $search_api_key - ); - - // If this call does not succeed, the application_ID and/or API_key are wrong. - try { - $acl = $client->getApiKey( $search_api_key ); - } catch ( AlgoliaException $e ) { - return false; - } - - // We expect a search only key for security reasons. Will be used in front. - $scopes = array_flip( $acl['acl'] ); - if ( ! isset( $scopes['search'] ) ) { - return false; - } - unset( $scopes['search'] ); - - if ( isset( $scopes['settings'] ) ) { - unset( $scopes['settings'] ); - } - - if ( isset( $scopes['listIndexes'] ) ) { - unset( $scopes['listIndexes'] ); - } - - // Short circuit ACL checks for local development. - if ( defined( 'WP_LOCAL_DEV' ) && WP_LOCAL_DEV ) { - return true; - } - - if ( ! empty( $scopes ) ) { - // The API key has more permissions than allowed. - return false; - } - - // We do expect a search key without unlimited TTL. - if ( 0 !== $acl['validity'] ) { - return false; - } - - return true; - } -} +} \ No newline at end of file diff --git a/includes/class-algolia-autocomplete-config.php b/includes/class-algolia-autocomplete-config.php index 637e249..9856f87 100644 --- a/includes/class-algolia-autocomplete-config.php +++ b/includes/class-algolia-autocomplete-config.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -9,31 +9,31 @@ */ /** - * Class Algolia_Autocomplete_Config + * Class Typesense_Autocomplete_Config * * @since 1.0.0 */ -class Algolia_Autocomplete_Config { +class Typesense_Autocomplete_Config { /** - * The Algolia_Plugin instance. + * The Typesense_Plugin instance. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Plugin + * @var Typesense_Plugin */ private $plugin; /** - * Algolia_Autocomplete_Config constructor. + * Typesense_Autocomplete_Config constructor. * * @author WebDevStudios * @since 1.0.0 * - * @param Algolia_Plugin $plugin The Algolia_Plugin instance. + * @param Typesense_Plugin $plugin The Typesense_Plugin instance. */ - public function __construct( Algolia_Plugin $plugin ) { + public function __construct( Typesense_Plugin $plugin ) { $this->plugin = $plugin; } @@ -57,7 +57,7 @@ public function get_form_data() { * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Index $index + * @var Typesense_Index $index */ foreach ( $indices as $index ) { $index_config = $this->extract_index_config( $existing_config, $index->get_id() ); @@ -74,8 +74,8 @@ public function get_form_data() { } usort( - $config, function( $a, $b ) { - return $a['position'] > $b['position']; + $config, function( $a, $b ):int { + return $a['position'] <=> $b['position']; } ); @@ -156,22 +156,23 @@ private function extract_index_config( array $config, $index_id ) { public function get_config() { $settings = $this->plugin->get_settings(); $config = $settings->get_autocomplete_config(); - foreach ( $config as $key => &$entry ) { - if ( ! isset( $entry['index_id'] ) ) { - unset( $config[ $key ] ); - continue; - } - - $index = $this->plugin->get_index( $entry['index_id'] ); + //foreach ( $config as $key => &$entry ) { + // if ( ! isset( $entry['index_id'] ) ) { + // unset( $config[ $key ] ); + // continue; + // } +////////////////////////////////////////////changes here +/* $index = $this->plugin->get_index( $entry['index_id'] ); if ( null === $index ) { unset( $config[ $key ] ); continue; - } - $entry['index_name'] = $index->get_name(); - $entry['enabled'] = true; - } + }*/ +////////////////////////////////////////////changes here + //$entry['index_name'] = $index->get_name(); + //$entry['enabled'] = true; + //} - $config = (array) apply_filters( 'algolia_autocomplete_config', $config ); + $config = (array) apply_filters( '_autocomplete_config', $config ); // Remove manually disabled indices. $config = array_filter( @@ -182,8 +183,8 @@ public function get_config() { // Sort the indices. usort( - $config, function( $a, $b ) { - return $a['position'] > $b['position']; + $config, function( $a, $b ):int { + return $a['position'] <=> $b['position']; } ); diff --git a/includes/class-algolia-cli.php b/includes/class-algolia-cli.php index b0c835a..ec8694f 100644 --- a/includes/class-algolia-cli.php +++ b/includes/class-algolia-cli.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -9,36 +9,36 @@ */ /** - * Class Algolia_CLI + * Class Typesense_CLI * - * Push and re-index records into Algolia indices. + * Push and re-index records into Typesense indices. * * @since 1.0.0 */ -class Algolia_CLI extends \WP_CLI_Command { +class Typesense_CLI extends \WP_CLI_Command { /** - * The Algolia_Plugin instance. + * The Typesense_Plugin instance. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Plugin + * @var Typesense_Plugin */ private $plugin; /** - * Algolia_CLI constructor. + * Typesense_CLI constructor. * * @author WebDevStudios * @since 1.0.0 */ public function __construct() { - $this->plugin = Algolia_Plugin_Factory::create(); + $this->plugin = Typesense_Plugin_Factory::create(); } /** - * Push all records to Algolia for a given index. + * Push all records to Typesense for a given index. * * ## OPTIONS * @@ -53,7 +53,7 @@ public function __construct() { * * ## EXAMPLES * - * wp algolia re-index + * wp Typesense re-index * * @alias re-index * @@ -65,7 +65,7 @@ public function __construct() { */ public function reindex( $args, $assoc_args ) { if ( ! $this->plugin->get_api()->is_reachable() ) { - WP_CLI::error( 'The configuration for this website does not allow to contact the Algolia API.' ); + WP_CLI::error( 'The configuration for this website does not allow to contact the Typesense API.' ); } $index_id = isset( $args[0] ) ? $args[0] : null; @@ -105,19 +105,19 @@ public function reindex( $args, $assoc_args ) { * @author WebDevStudios * @since 1.0.0 * - * @param Algolia_Index $index Algolia_Index instance. + * @param Typesense_Index $index Typesense_Index instance. * @param bool $clear Clear all existing records prior to pushing the records. * * @return void */ - private function do_reindex( Algolia_Index $index, $clear ) { + private function do_reindex( Typesense_Index $index, $clear ) { if ( $clear ) { /* translators: the placeholder will contain the name of the index. */ - WP_CLI::log( sprintf( __( 'About to clear index %s...', 'wp-search-with-algolia' ), $index->get_name() ) ); + WP_CLI::log( sprintf( __( 'About to clear index %s...', 'wp-search-with-Typesense' ), $index->get_name() ) ); $index->clear(); /* translators: the placeholder will contain the name of the index. */ - WP_CLI::success( sprintf( __( 'Correctly cleared index "%s".', 'wp-search-with-algolia' ), $index->get_name() ) ); + WP_CLI::success( sprintf( __( 'Correctly cleared index "%s".', 'wp-search-with-Typesense' ), $index->get_name() ) ); } $total_pages = $index->get_re_index_max_num_pages(); diff --git a/includes/class-algolia-compatibility.php b/includes/class-algolia-compatibility.php index 46ddb25..5e7c427 100644 --- a/includes/class-algolia-compatibility.php +++ b/includes/class-algolia-compatibility.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -9,11 +9,11 @@ */ /** - * Class Algolia_Compatibility + * Class Typesense_Compatibility * * @since 1.0.0 */ -class Algolia_Compatibility { +class Typesense_Compatibility { /** * The "current language" from WPML, if available, else null. @@ -26,16 +26,16 @@ class Algolia_Compatibility { private $current_language; /** - * Algolia_Compatibility constructor. + * Typesense_Compatibility constructor. * * @author WebDevStudios * @since 1.0.0 */ public function __construct() { - add_action( 'algolia_before_get_records', array( $this, 'register_vc_shortcodes' ) ); - add_action( 'algolia_before_get_records', array( $this, 'enable_yoast_frontend' ) ); - add_action( 'algolia_before_get_records', array( $this, 'wpml_switch_language' ) ); - add_action( 'algolia_after_get_records', array( $this, 'wpml_switch_back_language' ) ); + add_action( 'Typesense_before_get_records', array( $this, 'register_vc_shortcodes' ) ); + add_action( 'Typesense_before_get_records', array( $this, 'enable_yoast_frontend' ) ); + add_action( 'Typesense_before_get_records', array( $this, 'wpml_switch_language' ) ); + add_action( 'Typesense_after_get_records', array( $this, 'wpml_switch_back_language' ) ); } /** @@ -110,7 +110,7 @@ public function wpml_switch_back_language( $post ) { /** * Check if WPML is enabled. * - * @link https://github.com/algolia/algoliasearch-wordpress/issues/567 + * @link https://github.com/Typesense/Typesensesearch-wordpress/issues/567 * * @author WebDevStudios * @since 1.0.0 diff --git a/includes/class-algolia-plugin.php b/includes/class-algolia-plugin.php index 9799c93..9925089 100644 --- a/includes/class-algolia-plugin.php +++ b/includes/class-algolia-plugin.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -9,41 +9,41 @@ */ /** - * Class Algolia_Plugin + * Class Typesense_Plugin * * @since 1.0.0 */ -class Algolia_Plugin { +class Typesense_Plugin { - const NAME = 'algolia'; + const NAME = 'typesense'; /** - * Instance of Algolia_API. + * Instance of Typesense_API. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_API + * @var Typesense_API */ protected $api; /** - * Instance of Algolia_Settings. + * Instance of Typesense_Settings. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Settings + * @var Typesense_Settings */ private $settings; /** - * Instance of Algolia_Autocomplete_Config. + * Instance of Typesense_Autocomplete_Config. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Autocomplete_Config + * @var Typesense_Autocomplete_Config */ private $autocomplete_config; @@ -68,72 +68,71 @@ class Algolia_Plugin { private $changes_watchers; /** - * Instance of Algolia_Styles. + * Instance of Typesense_Styles. * * @author WebDevStudios * @since 1.5.0 * - * @var Algolia_Styles + * @var Typesense_Styles */ private $styles; /** - * Instance of Algolia_Scripts. + * Instance of Typesense_Scripts. * * @author WebDevStudios * @since 1.5.0 * - * @var Algolia_Scripts + * @var Typesense_Scripts */ private $scripts; /** - * Instance of Algolia_Template_Loader. + * Instance of Typesense_Template_Loader. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Template_Loader + * @var Typesense_Template_Loader */ private $template_loader; /** - * Instance of Algolia_Compatibility. + * Instance of Typesense_Compatibility. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Compatibility + * @var Typesense_Compatibility */ private $compatibility; /** - * Get the singleton instance of Algolia_Plugin. + * Get the singleton instance of Typesense_Plugin. * * @author WebDevStudios * @since 1.0.0 - * @deprecated 1.6.0 Use Algolia_Plugin_Factory::create() - * @see Algolia_Plugin_Factory::create() + * @deprecated 1.6.0 Use Typesense_Plugin_Factory::create() + * @see Typesense_Plugin_Factory::create() * - * @return Algolia_Plugin + * @return Typesense_Plugin */ public static function get_instance() { - _deprecated_function( __METHOD__, '1.6.0', 'Algolia_Plugin_Factory::create();' ); - return Algolia_Plugin_Factory::create(); + //_deprecated_function( __METHOD__, '1.6.0', 'Typesense_Plugin_Factory::create();' ); + return Typesense_Plugin_Factory::create(); } /** - * Algolia_Plugin constructor. + * Typesense_Plugin constructor. * * @author WebDevStudios * @since 1.0.0 */ public function __construct() { - $this->settings = new Algolia_Settings(); - $this->api = new Algolia_API( $this->settings ); - $this->compatibility = new Algolia_Compatibility(); - $this->styles = new Algolia_Styles(); - $this->scripts = new Algolia_Scripts(); + $this->settings = new Typesense_Settings(); + $this->api = new Typesense_API( $this->settings ); + $this->scripts = new Typesense_Scripts(); + $this->styles = new Typesense_Styles(); add_action( 'init', array( $this, 'load' ), 20 ); } @@ -144,16 +143,12 @@ public function __construct() { * @since 1.0.0 */ public function load() { - if ( $this->api->is_reachable() ) { - $this->load_indices(); - $this->override_wordpress_search(); - $this->autocomplete_config = new Algolia_Autocomplete_Config( $this ); - $this->template_loader = new Algolia_Template_Loader( $this ); - } - + $this->template_loader = new Typesense_Template_Loader( $this ); + $this->autocomplete_config = new Typesense_Autocomplete_Config( $this ); + $this->load_indices(); // Load admin or public part of the plugin. if ( is_admin() ) { - new Algolia_Admin( $this ); + new Typesense_Admin( $this ); } } @@ -181,7 +176,7 @@ public function get_name() { * @return string The version number of the plugin. */ public function get_version() { - return ALGOLIA_VERSION; + return TYPESENSE_VERSION; } /** @@ -190,19 +185,19 @@ public function get_version() { * @author WebDevStudios * @since 1.0.0 * - * @return Algolia_API + * @return Typesense_API */ public function get_api() { return $this->api; } /** - * Get the Algolia_Settings. + * Get the Typesense_Settings. * * @author WebDevStudios * @since 1.0.0 * - * @return Algolia_Settings + * @return Typesense_Settings */ public function get_settings() { return $this->settings; @@ -211,7 +206,7 @@ public function get_settings() { /** * Override WordPress native search. * - * Replaces native WordPress search results by Algolia ranked results. + * Replaces native WordPress search results by Typesense ranked results. * * @author WebDevStudios * @since 1.0.0 @@ -231,16 +226,16 @@ private function override_wordpress_search() { return; } - new Algolia_Search( $index ); + new Typesense_Search( $index ); } /** - * Get the Algolia_Autocomplete_Config. + * Get the Typesense_Autocomplete_Config. * * @author WebDevStudios * @since 1.0.0 * - * @return Algolia_Autocomplete_Config + * @return Typesense_Autocomplete_Config */ public function get_autocomplete_config() { return $this->autocomplete_config; @@ -253,75 +248,25 @@ public function get_autocomplete_config() { * @since 1.0.0 */ public function load_indices() { - $synced_indices_ids = $this->settings->get_synced_indices_ids(); + //$synced_indices_ids = $this->settings->get_synced_indices_ids(); $client = $this->get_api()->get_client(); $index_name_prefix = $this->settings->get_index_name_prefix(); + $this->indices=array(); + $this->indices[] = new Typesense_Posts_Index('post'); - // Add a searchable posts index. - $searchable_post_types = get_post_types( - array( - 'exclude_from_search' => false, - ), 'names' - ); - $searchable_post_types = (array) apply_filters( 'algolia_searchable_post_types', $searchable_post_types ); - $this->indices[] = new Algolia_Searchable_Posts_Index( $searchable_post_types ); - - // Add one posts index per post type. - $post_types = get_post_types(); - - $post_types_blacklist = $this->settings->get_post_types_blacklist(); - foreach ( $post_types as $post_type ) { - // Skip blacklisted post types. - if ( in_array( $post_type, $post_types_blacklist, true ) ) { - continue; - } - - $this->indices[] = new Algolia_Posts_Index( $post_type ); - } - - // Add one terms index per taxonomy. - $taxonomies = get_taxonomies(); - $taxonomies_blacklist = $this->settings->get_taxonomies_blacklist(); - foreach ( $taxonomies as $taxonomy ) { - // Skip blacklisted post types. - if ( in_array( $taxonomy, $taxonomies_blacklist, true ) ) { - continue; - } - - $this->indices[] = new Algolia_Terms_Index( $taxonomy ); - } + $this->indices[1] = new Typesense_Terms_Index( 'category' ); - // Add the users index. - $this->indices[] = new Algolia_Users_Index(); + $this->indices[0]->set_client( $client); + $this->indices[1]->set_client( $client); - // Allow developers to filter the indices. - $this->indices = (array) apply_filters( 'algolia_indices', $this->indices ); + $this->changes_watchers=array(); + $this->changes_watchers[] = new Typesense_Post_Changes_Watcher( $this->indices[0] ); - foreach ( $this->indices as $index ) { - $index->set_name_prefix( $index_name_prefix ); - $index->set_client( $client ); - - if ( in_array( $index->get_id(), $synced_indices_ids, true ) ) { - $index->set_enabled( true ); - - if ( $index->contains_only( 'posts' ) ) { - $this->changes_watchers[] = new Algolia_Post_Changes_Watcher( $index ); - } elseif ( $index->contains_only( 'terms' ) ) { - $this->changes_watchers[] = new Algolia_Term_Changes_Watcher( $index ); - } elseif ( $index->contains_only( 'users' ) ) { - $this->changes_watchers[] = new Algolia_User_Changes_Watcher( $index ); - } - } - } - - $this->changes_watchers = (array) apply_filters( 'algolia_changes_watchers', $this->changes_watchers ); - - foreach ( $this->changes_watchers as $watcher ) { - $watcher->watch(); - } + $this->changes_watchers[0]->watch(); } + /** * Get indices. * @@ -332,31 +277,8 @@ public function load_indices() { * * @return array */ - public function get_indices( array $args = array() ) { - if ( empty( $args ) ) { - return $this->indices; - } - - $indices = $this->indices; - - if ( isset( $args['enabled'] ) && true === $args['enabled'] ) { - $indices = array_filter( - $indices, function( $index ) { - return $index->is_enabled(); - } - ); - } - - if ( isset( $args['contains'] ) ) { - $contains = (string) $args['contains']; - $indices = array_filter( - $indices, function( $index ) use ( $contains ) { - return $index->contains_only( $contains ); - } - ); - } - - return $indices; + public function get_indices() { + return $this->indices; } /** @@ -367,7 +289,7 @@ public function get_indices( array $args = array() ) { * * @param string $index_id The ID of the index to get. * - * @return Algolia_Index|null + * @return Typesense_Index|null */ public function get_index( $index_id ) { foreach ( $this->indices as $index ) { @@ -388,7 +310,7 @@ public function get_index( $index_id ) { * @return string */ public function get_path() { - return untrailingslashit( ALGOLIA_PATH ); + return untrailingslashit( TYPESENSE_PATH ); } /** @@ -400,40 +322,40 @@ public function get_path() { * @return string */ public function get_templates_path() { - return (string) apply_filters( 'algolia_templates_path', 'algolia/' ); + return (string) apply_filters( 'typesense_templates_path', 'typesense/' ); } /** - * Get the Algolia_Template_Loader. + * Get the Typesense_Template_Loader. * * @author WebDevStudios * @since 1.0.0 * - * @return Algolia_Template_Loader + * @return Typesense_Template_Loader */ public function get_template_loader() { return $this->template_loader; } /** - * Get the Algolia_Styles. + * Get the Typesense_Styles. * * @author WebDevStudios * @since 1.5.0 * - * @return Algolia_Styles + * @return Typesense_Styles */ public function get_styles() { return $this->styles; } /** - * Get the Algolia_Scripts. + * Get the Typesense_Scripts. * * @author WebDevStudios * @since 1.5.0 * - * @return Algolia_Scripts + * @return Typesense_Scripts */ public function get_scripts() { return $this->scripts; diff --git a/includes/class-algolia-scripts.php b/includes/class-algolia-scripts.php index 32d5f92..b25d749 100644 --- a/includes/class-algolia-scripts.php +++ b/includes/class-algolia-scripts.php @@ -13,7 +13,7 @@ * * @since 1.5.0 */ -class Algolia_Scripts { +class Typesense_Scripts { /** * Algolia_Scripts constructor. @@ -33,53 +33,112 @@ public function __construct() { */ public function register_scripts() { - $in_footer = Algolia_Utils::get_scripts_in_footer_argument(); + $in_footer = Typesense_Utils::get_scripts_in_footer_argument(); $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_register_script( 'algolia-search', - ALGOLIA_PLUGIN_URL . 'js/algoliasearch/dist/algoliasearch.jquery' . $suffix . '.js', + TYPESENSE_PLUGIN_URL . 'js/algoliasearch/dist/algoliasearch.jquery' . $suffix . '.js', [ 'jquery', 'underscore', 'wp-util', ], - ALGOLIA_VERSION, + TYPESENSE_VERSION, $in_footer ); +//Typesense scripts + wp_register_script( + 'typesense-js', + TYPESENSE_PLUGIN_URL . 'js/typesense-js/dist/typesense.js', + [ + 'jquery', + 'underscore', + 'wp-util', + ], + TYPESENSE_VERSION, + $in_footer + ); + wp_register_script( + 'typesense-min-js', + TYPESENSE_PLUGIN_URL . 'js/typesense-js/dist/typesense.min.js', + [ + 'jquery', + 'underscore', + 'wp-util', + ], + TYPESENSE_VERSION, + $in_footer + ); + + wp_register_script( + 'typesense-min-js-map', + TYPESENSE_PLUGIN_URL . 'js/typesense-js/dist/typesense.min.js.map', + [ + 'jquery', + 'underscore', + 'wp-util', + ], + TYPESENSE_VERSION, + $in_footer + ); + wp_register_script( + 'typesense-adapter', + TYPESENSE_PLUGIN_URL . 'js/typesense-instantsearch-adapter/dist/typesense-instantsearch-adapter.min.js', + [ + 'jquery', + 'underscore', + 'wp-util', + ], + TYPESENSE_VERSION, + $in_footer + ); + + wp_register_script( + 'typesense-adapter-map', + TYPESENSE_PLUGIN_URL . 'js/typesense-instantsearch-adapter/dist/typesense-instantsearch-adapter.min.js.map', + [ + 'jquery', + 'underscore', + 'wp-util', + ], + TYPESENSE_VERSION, + $in_footer + ); +//Typesense scripts wp_register_script( 'algolia-autocomplete', - ALGOLIA_PLUGIN_URL . 'js/autocomplete.js/dist/autocomplete' . $suffix . '.js', + TYPESENSE_PLUGIN_URL . 'js/autocomplete.js/dist/autocomplete' . $suffix . '.js', [ 'jquery', 'underscore', 'wp-util', ], - ALGOLIA_VERSION, + TYPESENSE_VERSION, $in_footer ); wp_register_script( 'algolia-autocomplete-noconflict', - ALGOLIA_PLUGIN_URL . 'js/autocomplete-noconflict.js', + TYPESENSE_PLUGIN_URL . 'js/autocomplete-noconflict.js', [ 'algolia-autocomplete', ], - ALGOLIA_VERSION, + TYPESENSE_VERSION, $in_footer ); wp_register_script( 'algolia-instantsearch', - ALGOLIA_PLUGIN_URL . 'js/instantsearch.js/dist/instantsearch-preact' . $suffix . '.js', + 'https://cdn.jsdelivr.net/npm/instantsearch.js@4.5.0', [ 'jquery', 'underscore', 'wp-util', ], - ALGOLIA_VERSION, + TYPESENSE_VERSION, $in_footer ); } diff --git a/includes/class-algolia-search.php b/includes/class-algolia-search.php index eca3229..039056e 100644 --- a/includes/class-algolia-search.php +++ b/includes/class-algolia-search.php @@ -1,6 +1,6 @@ * @since 1.0.0 @@ -8,14 +8,14 @@ * @package WebDevStudios\WPSWA */ -use Algolia\AlgoliaSearch\Exceptions\AlgoliaException; +use Typesense\TypesenseSearch\Exceptions\TypesenseException; /** - * Class Algolia_Search + * Class Typesense_Search * * @since 1.0.0 */ -class Algolia_Search { +class Typesense_Search { /** * Current page hits. @@ -38,24 +38,24 @@ class Algolia_Search { private $total_hits; /** - * Instance of Algolia_Index. + * Instance of Typesense_Index. * * @author WebDevStudios * @since 1.0.0 * - * @var Algolia_Index + * @var Typesense_Index */ private $index; /** - * Algolia_Search constructor. + * Typesense_Search constructor. * * @author WebDevStudios * @since 1.0.0 * - * @param Algolia_Index $index Instance of Algolia_Index. + * @param Typesense_Index $index Instance of Typesense_Index. */ - public function __construct( Algolia_Index $index ) { + public function __construct( Typesense_Index $index ) { $this->index = $index; add_action( 'loop_start', [ $this, 'begin_highlighting' ] ); @@ -81,18 +81,18 @@ private function should_filter_query( WP_Query $query ) { * * @since 1.3.0 * - * @param bool $should_filter Whether Algolia should filter the search query. - * @param WP_Query $query The WP_Query that was tested for Algolia Search filtering. + * @param bool $should_filter Whether Typesense should filter the search query. + * @param WP_Query $query The WP_Query that was tested for Typesense Search filtering. */ return (bool) apply_filters( - 'algolia_should_filter_query', + 'Typesense_should_filter_query', $should_filter, $query ); } /** - * We force the WP_Query to only return records according to Algolia's ranking. + * We force the WP_Query to only return records according to Typesense's ranking. * * @author WebDevStudios * @since 1.0.0 @@ -114,14 +114,14 @@ public function pre_get_posts( WP_Query $query ) { } /** - * Filters the array of parameters used in the Algolia Index search. + * Filters the array of parameters used in the Typesense Index search. * * @author WebDevStudios * @since 1.0.0 * @since 1.2.0 Introduced 'highlightPreTag' and 'highlightPostTag` parameters. * * @param array $params { - * Search parameters for the Algolia Index search. + * Search parameters for the Typesense Index search. * * @type string $attributesToRetrieve Which attributes to retrieve. * @type int $hitsPerPage Pagination parameter. The number of hits per page to retrieve. @@ -131,22 +131,22 @@ public function pre_get_posts( WP_Query $query ) { * } */ $params = apply_filters( - 'algolia_search_params', + 'Typesense_search_params', array( 'attributesToRetrieve' => 'post_id', 'hitsPerPage' => (int) get_option( 'posts_per_page' ), - 'page' => $current_page - 1, // Algolia pages are zero indexed. - 'highlightPreTag' => '', + 'page' => $current_page - 1, // Typesense pages are zero indexed. + 'highlightPreTag' => '', 'highlightPostTag' => '', ) ); - $order_by = apply_filters( 'algolia_search_order_by', null ); - $order = apply_filters( 'algolia_search_order', 'desc' ); + $order_by = apply_filters( 'Typesense_search_order_by', null ); + $order = apply_filters( 'Typesense_search_order', 'desc' ); try { $results = $this->index->search( $query->query['s'], $params, $order_by, $order ); - } catch ( AlgoliaException $exception ) { + } catch ( TypesenseException $exception ) { error_log( $exception->getMessage() ); // phpcs:ignore -- Legacy. return; @@ -199,7 +199,7 @@ public function pre_get_posts( WP_Query $query ) { } /** - * This hook returns the actual real number of results available in Algolia. + * This hook returns the actual real number of results available in Typesense. * * @author WebDevStudios * @since 1.0.0 @@ -215,9 +215,9 @@ public function found_posts( $found_posts, WP_Query $query ) { /** * Filter the search SQL that is used in the WHERE clause of WP_Query. - * Removes the where Like part of the queries as we consider Algolia as being the source of truth. + * Removes the where Like part of the queries as we consider Typesense as being the source of truth. * We don't want to filter by anything but the actual list of post_ids resulting - * from the Algolia search. + * from the Typesense search. * * @author WebDevStudios * @since 1.0.0 @@ -244,13 +244,13 @@ public function output_highlighting_bundled_styles() { return; } - if ( ! apply_filters( 'algolia_search_highlighting_enable_bundled_styles', true ) ) { + if ( ! apply_filters( 'Typesense_search_highlighting_enable_bundled_styles', true ) ) { return; } ?>