-
-
Save jchristopher/501c08394e005179edfbfb9bd4e041fd to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* NOTE: THIS IS FOR SEARCHWP VERSION 3 | |
*/ | |
/** | |
* WP All Import SearchWP PRE-import routine | |
* | |
* @link https://searchwp.com/docs/kb/best-work-content-imports/ | |
*/ | |
function myswp_before_xml_import( $import_id ) { | |
// Pause the SearchWP indexer during import | |
SWP()->indexer_pause(); | |
// Tell SearchWP to ignore edit events | |
searchwp_update_option( 'prevent_delta_triggers', true ); | |
// Purge SearchWP index | |
// This is optional, but beneificial if your import process | |
// overwrites ALL content indexed by SearchWP. | |
// NOTE: if this is uncommented, the pmxi_saved_post action | |
// below should be commented out as it is not necessary. | |
// SWP()->purge_index(); | |
} | |
add_action( 'pmxi_before_xml_import', 'myswp_before_xml_import', 10, 1 ); | |
/** | |
* WP All Import callback that runs for each imported entry. | |
* Purge that post from the SearchWP index. | |
* | |
* NOTE: If you are purging the index in pmxi_before_xml_import above | |
* this hook should be disabled as it is not necssary. | |
* | |
* @link https://searchwp.com/docs/kb/best-work-content-imports/ | |
*/ | |
function myswp_post_updated( $post_id ){ | |
SWP()->purge_post( $post_id ); | |
} | |
add_action('pmxi_saved_post', 'myswp_post_updated', 10, 1 ); | |
/** | |
* WP All Import SearchWP POST-import routine | |
* | |
* @link https://searchwp.com/docs/kb/best-work-content-imports/ | |
*/ | |
function myswp_after_xml_import( $import_id ) { | |
// Tell SearchWP to resume listening to edit triggers | |
searchwp_update_option( 'prevent_delta_triggers', false ); | |
// Re-enable the SearchWP indexer | |
SWP()->indexer_unpause(); | |
// Trigger the indexer to rebuild the index | |
SWP()->trigger_index(); | |
} | |
add_action( 'pmxi_after_xml_import', 'myswp_after_xml_import', 10, 1 ); |
- Does the
SWP()->trigger_index()
function immediately deletes the current existing index and starts from scratch to generate a brand new one?- If ^ true, does this means that while the index rebuild happens, the site search page might not return results accurately until the index rebuild finishes?
Anyone has an answer? I'm eager to know the answers to this questions to.
Sorry, GitHub didn't start notifying about comments on gists until somewhat recently so I did not see these questions.
Does the SWP()->trigger_index() function immediately deletes the current existing index and starts from scratch to generate a brand new one?
It does not delete the index, it only tells the indexer to check for unindexed content.
If ^ true, does this means that while the index rebuild happens, the site search page might not return results accurately until the index rebuild finishes?
Until the index has completed building, search results can be missing as the content is not indexed, that is correct. Unless you are working with a very large amount of content this "downtime" is minimal.
Thank you for your reply. Do you know how to create a new start index via code? I've tried several methods already:
SWP()->process_updates();
SWP()->update_index();
SWP()->trigger_index()
But still there are posts that cannot be found by searchWP.
To receive support please open a support ticket using the Support tab of the SearchWP settings screen, thank you!
@jchristopher
SWP()->trigger_index()
function immediately deletes the current existing index and starts from scratch to generate a brand new one?