Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to configure/restrict indexing by post status #59

Merged
merged 2 commits into from
Nov 13, 2023

Conversation

renatonascalves
Copy link
Contributor

@renatonascalves renatonascalves commented Nov 10, 2023

I opted to use the grammatically correct plural version: statuses. Even though ElasticPress uses the singular version.

The Wiki must be updated after this is merged.

fixes #58

Summary by CodeRabbit

  • New Features
    • Introduced the ability to restrict indexable post statuses for search operations.
    • Added a new filter hook for handling post statuses during indexing.
  • Refactor
    • Updated methods to include and remove the new filter hook.
  • Documentation
    • Minor updates to formatting and documentation.

@renatonascalves renatonascalves self-assigned this Nov 10, 2023
Copy link

coderabbitai bot commented Nov 10, 2023

Walkthrough

The changes introduced in this diff primarily focus on enhancing the functionality of the plugin to restrict indexable post statuses for search operations. This is achieved by adding new properties, methods, and hooks in the Adapter and SearchPress classes. The changes also include the addition of a method to filter post statuses in the VipEnterpriseSearch class.

Changes

File Change Summary
lib/adapters/class-adapter.php Introduced a new property restricted_post_statuses with corresponding getter and setter methods. Added a new method restrict_post_statuses to set the restricted post statuses.
lib/adapters/class-searchpress.php Added a new method apply_sync_post_statuses for handling post statuses for indexing. Modified the hook and unhook methods to include and remove a new filter hook sp_config_sync_statuses.
lib/adapters/class-vip-enterprise-search.php Added a new method filter__ep_indexable_post_statuses to filter the list of post statuses to be indexed. Included corresponding hooks to register and unregister the filter.

Assessment against linked issues (Beta)

Objective Addressed Explanation
Add ability to restrict by post status (58) The changes introduce the ability to restrict post statuses for indexing, which directly addresses this objective.
Utilize VIP Search hook to confirm if a post should be indexed or not (58) The changes include the addition of hooks in the SearchPress and VipEnterpriseSearch classes, which can be used to confirm if a post should be indexed.
Enable taxonomy aggregation for 'category' and 'post_tag' (58) The changes do not appear to address this objective as there is no mention of taxonomy aggregation for 'category' and 'post_tag'.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5085e09 and 0fe5055.
Files selected for processing (3)
  • lib/adapters/class-adapter.php (3 hunks)
  • lib/adapters/class-searchpress.php (3 hunks)
  • lib/adapters/class-vip-enterprise-search.php (4 hunks)
Additional comments: 8
lib/adapters/class-searchpress.php (2)
  • 52-70: The new method apply_sync_post_statuses is added to handle post statuses for indexing. It merges the restricted post statuses with the existing ones. Ensure that the restricted post statuses are correctly set before this method is called.

  • 481-493: The hook method is updated to include a new filter hook sp_config_sync_statuses. Ensure that the filter is correctly applied in the context where it is used.

lib/adapters/class-adapter.php (3)
  • 77-85: The new property restricted_post_statuses is added to the Adapter class. This property will hold an array of post statuses that are allowed to be indexed. This is a good addition for controlling which post statuses should be indexed.

  • 393-403: The getter method get_restricted_post_statuses is added for the new property restricted_post_statuses. This method will return the array of restricted post statuses. This is a good practice as it encapsulates the property and provides controlled access to it.

  • 504-514: The setter method restrict_post_statuses is added for the new property restricted_post_statuses. This method will set the array of restricted post statuses. This is a good practice as it encapsulates the property and provides controlled access to it.

lib/adapters/class-vip-enterprise-search.php (3)
  • 80-101: The new method filter__ep_indexable_post_statuses is introduced to filter the list of post statuses to be indexed in ElasticPress. It checks if there are any restricted post statuses and if there are, it merges them with the existing post statuses. The use of array_unique ensures there are no duplicate statuses. The logic seems correct.

  • 567-573: The new method filter__ep_indexable_post_statuses is registered as a filter for ep_indexable_post_status. This ensures that the method is called whenever the ep_indexable_post_status filter is applied.

  • 589-595: The new method filter__ep_indexable_post_statuses is unregistered from the ep_indexable_post_status filter. This ensures that the method is no longer called when the ep_indexable_post_status filter is applied.

lib/adapters/class-searchpress.php Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0fe5055 and 83d83e0.
Files selected for processing (1)
  • lib/adapters/class-searchpress.php (3 hunks)
Additional comments: 3
lib/adapters/class-searchpress.php (3)
  • 53-70: The new method apply_sync_post_statuses is added to handle post statuses for indexing. It merges the restricted post statuses with the existing ones. Ensure that the restricted post statuses are correctly set before this method is called.

  • 482-493: The hook method is updated to include a new filter hook sp_config_sync_statuses and its corresponding callback apply_sync_post_statuses. Ensure that this hook is correctly triggered in the expected scenarios.

  • 499-511: The unhook method is updated to remove the new filter hook sp_config_sync_statuses and its corresponding callback apply_sync_post_statuses. Ensure that this unhook operation is correctly triggered when needed.

Copy link
Member

@attackant attackant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐙

@renatonascalves renatonascalves merged commit 76ec651 into main Nov 13, 2023
6 checks passed
@renatonascalves renatonascalves deleted the feature/restrict-by-post-status branch November 13, 2023 13:27
@renatonascalves
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to restrict by post status
2 participants