Skip to content

Commit

Permalink
refactor: property, method renamings and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mustafa Şükrü Kapusuz committed May 19, 2023
1 parent 1be9677 commit 24f6bdf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
11 changes: 8 additions & 3 deletions includes/indices/class-algolia-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
* @since 1.0.0
*/
abstract class Algolia_Index {
protected $settings = [];
/**
* Default index settings
*
* @var array
*/
protected array $default_settings = [];

/**
* The SearchClient instance.
Expand Down Expand Up @@ -686,8 +691,8 @@ protected function get_re_index_batch_size() {
*
* @return array
*/
public function get_settings() {
$settings = (array) apply_filters( 'algolia_' . $this->get_id() . '_index_settings', $this->settings );
public function get_default_settings() {
$settings = (array) apply_filters( 'algolia_' . $this->get_id() . '_index_settings', $this->default_settings );

/**
* Replacing `attributesToIndex` with `searchableAttributes` as
Expand Down
9 changes: 5 additions & 4 deletions includes/indices/class-algolia-posts-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @since 1.0.0
*/
final class Algolia_Posts_Index extends Algolia_Index {
protected $settings = [
protected array $default_settings = [
'searchableAttributes' => array(
'unordered(post_title)',
'unordered(taxonomies)',
Expand Down Expand Up @@ -288,15 +288,16 @@ private function get_post_shared_attributes( WP_Post $post ) {

/**
* Get settings.
* Overridden to able to have "algolia_posts_index_settings" filter.
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.0.0
*
* @return array
*/
public function get_settings() {
$this->settings = (array) apply_filters( 'algolia_posts_index_settings', $this->settings, $this->post_type );
return parent::get_settings();
public function get_default_settings() {
$this->default_settings = (array) apply_filters( 'algolia_posts_index_settings', $this->default_settings, $this->post_type );
return parent::get_default_settings();
}

/**
Expand Down
9 changes: 5 additions & 4 deletions includes/indices/class-algolia-searchable-posts-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,15 @@ private function get_post_shared_attributes( WP_Post $post ) {
/**
* Get settings.
*
* Overridden to able to have "excerpt_length" WP filter hook for the attributesToSnippet.content
*
* @author WebDevStudios <contact@webdevstudios.com>
* @since 1.0.0
*
* @return array
*/
public function get_settings() {
// override settings prop to inject the WP Filter Hook.
$this->settings = [
public function get_default_settings() {
$this->default_settings = [
'searchableAttributes' => array(
'unordered(post_title)',
'unordered(taxonomies)',
Expand All @@ -282,7 +283,7 @@ public function get_settings() {
'snippetEllipsisText' => '…',
];

return parent::get_settings();
return parent::get_default_settings();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions includes/indices/class-algolia-terms-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @since 1.0.0
*/
final class Algolia_Terms_Index extends Algolia_Index {
protected $settings = [
protected array $default_settings = [
'searchableAttributes' => array(
'unordered(name)',
'unordered(description)',
Expand Down Expand Up @@ -138,10 +138,10 @@ protected function get_re_index_items_count() {
*
* @return array
*/
public function get_settings() {
public function get_default_settings() {
// override settings prop to have a custom WP filter hook for terms only
$this->settings = apply_filters( 'algolia_terms_index_settings', $this->settings, $this->taxonomy );
return parent::get_settings();
$this->default_settings = apply_filters( 'algolia_terms_index_settings', $this->default_settings, $this->taxonomy );
return parent::get_default_settings();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/indices/class-algolia-users-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @since 1.0.0
*/
final class Algolia_Users_Index extends Algolia_Index {
protected $settings = [
protected array $default_settings = [
'searchableAttributes' => array(
'unordered(display_name)',
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function set_algolia_index(): void {
}

public function get_local_settings(): array {
return $this->get_index()->get_settings();
return $this->get_index()->get_default_settings();
}

public function get_remote_settings(): array {
Expand Down

0 comments on commit 24f6bdf

Please sign in to comment.