Skip to content

Commit

Permalink
Do not index attachment by default anymore. (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret authored Sep 14, 2021
1 parent 4c41e78 commit 4696426
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ public function allowedPostTypes()
);
}

return $allowedPostTypes;
return \apply_filters('swiftype_allowed_post_types', $allowedPostTypes);
}
}
22 changes: 20 additions & 2 deletions Document/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,34 @@ class Indexer extends AbstractSwiftypeComponent
*/
private $documentMapper;

/**
* @var string[]
*/
private static $FORBIDDEN_POST_TYPES = ['attachment'];

/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->documentMapper = new Mapper();
\add_filter('swiftype_allowed_post_types', [$this, 'filterAllowedPostType']);
\add_action('swiftype_engine_loaded', [$this, 'installHooks']);
}

/**
* Filter out forbiden post types fron indexing.
*
* @param string[] $allowedPostTypes
*
* @return string[]
*/
public function filterAllowedPostType($allowedPostTypes)
{
return \array_diff($allowedPostTypes, self::$FORBIDDEN_POST_TYPES);
}

/**
* Install hooks only when the engine is created (swiftype_engine_loaded).
*/
Expand All @@ -44,8 +62,8 @@ public function installHooks()
\add_action('trashed_post', [$this, 'handleTrashedPost']);


add_action('swiftype_batch_post_index', [$this, 'handlePostBatchIndex']);
add_action('swiftype_batch_post_delete', [$this, 'handlePostBatchDelete']);
\add_action('swiftype_batch_post_index', [$this, 'handlePostBatchIndex']);
\add_action('swiftype_batch_post_delete', [$this, 'handlePostBatchDelete']);
}
}

Expand Down

0 comments on commit 4696426

Please sign in to comment.