fix: sync posts to Elasticsearch when Post Search is disabled#4325
fix: sync posts to Elasticsearch when Post Search is disabled#4325faisalahammad wants to merge 3 commits into
Conversation
Move the post indexable activation out of the Post Search feature setup so posts continue to sync even when that feature is disabled. Previously, disabling Post Search prevented the Post indexable's SyncManager from being instantiated, so wp_insert_post / delete_post / meta / term hooks were never attached. Fixes 10up#4158
|
Hi @faisalahammad, Thank you for taking the time to open this pull request. However, this issue is a bit more complex than it appears. If we simply make the post indexable, ElasticPress will start using Elasticsearch for post queries even when the Post Search feature is disabled. This requires some discussion and a decision. For example, should posts still be indexed during sync when the Post Search feature is disabled, or should they be excluded from indexing altogether? I would love to hear your thoughts on this before we move forward. Regards, |
|
Hi @burhandodhy, good question. Checked this in the code. Activating the post indexable only wires up So with this change:
Added a second test, To answer your question directly: posts should keep syncing during indexing even when Post Search is disabled. Other features (WooCommerce, Autosuggest, RelatedPosts, Facets, SearchOrdering, Documents) all depend on the post indexable being populated, and none of them currently activate it themselves. If we exclude posts from sync when Search is off, those features silently break for any site that has Search disabled but still uses them. |
Add testPostQueryNotIntegratedWithSearchDisabled to confirm activating the post indexable does not enable ES query integration when Post Search feature is disabled. Refs 10up#4325
|
@burhandodhy pushed the added test and updated branch against develop. Ready for another look when you have time. |
Summary
Move the Post indexable activation out of the Post Search feature
setup()so posts continue to sync to Elasticsearch even when the Post Search feature is disabled.Previously, disabling Post Search prevented
Post::setup()from being called, which meant theSyncManagerwas never instantiated andwp_insert_post/delete_post/ meta / term hooks were never attached.Fixes #4158
Changes
includes/classes/Features.php
Before:
After:
Why:
setup_features()runs oninitpriority 0 for every request. Activating the post indexable here ensures it is always set up, independent of whether the Search feature is active.includes/classes/Feature/Search/Search.php
Before:
After:
Why: The Search feature no longer needs to activate the post indexable. Its
setup()still loads weighting, synonyms, and registerssearch_setupfor query integration.Testing
Test 1: Post sync with Post Search disabled
Result: works as expected.
Test 2: Post sync with Post Search enabled (regression)
Result: works as expected.
Test 3: Automated regression test
Added
tests/php/indexables/TestPostSyncWithoutSearch.phpwithtestPostSyncWithSearchDisabled()— disables the Search feature, creates a post, and asserts the sync hook fires and the document exists in Elasticsearch. Passes on single-site and multisite test suites.