Skip to content

Running WP_CLI command wp algolia reindex --all would clear index even if --clear flag is not specified #442

@menno-ll

Description

@menno-ll

Describe the bug
When you run the wp-cli command wp algolia reindex --all the index would still be cleared.
This happens because when it re-indexes the first batch, it checks if the index exists.
And inside that functionality, it also empties the index if the index already existed.

To Reproduce
Steps to reproduce the behavior:

  1. In your terminal, run wp algolia reindex --all
  2. Visit algolia backend interface, see you have indexed items.
  3. Run wp algolia reindex --all
  4. While the command is running, refresh the algolia backend interface
  5. You will see the index has been cleared, and less items are in the index (and going up in amount as more content is being indexed)

Expected behavior
Index should not be cleared when the --clear flag has not been specified.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser chrome
  • Version 131.0.6778.109 (Official Build) (arm64)

Smartphone (please complete the following information):
Cannot run wp-cli on smartphone

Additional context
Add any other context about the problem here.

Fix would be to add add_filter( 'algolia_clear_index_if_existing', '__return_false' ); to class-algolia-cli.php in an else statement, somewhere around line 126 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    indexingIssues around the indexing process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions