Get WPFTS Pro today with 25% discount!

Able to delete from index


  • Do you guys have a filter/hook available to remove items from the index?
    We have events that are part of the index but want them removed once they expire. We do this using a custom logic.

    Thanks


  • Hi @alihs

    Sure, you can do that using the wpfts_index_post hook.

    You can implement custom logic inside the hook code and then return normal $chunks value in case you want the Event post to be in the index or return $chunks = array(); (empty array) in case you want to remove the post from the index.

    There is no way (by plugin logic) to remove a post from the index completely, but the method above will store an empty record for your expired event, so it will be 100% not searchable and will not take DB space.

    Note, another (and more convenient) way to remove posts from the search index is to change their post_status to "draft", for example, and be sure the "draft" status is listed in the excluded list.
    It says WPFTS to save only ID information about the post. But without hooks or complex logic.

    alt text

    Let me know if this helps.
    Thank you.


  • @EpsilonAdmin Thanks for the very prompt reply.

    I have the following

    add_filter( 'wpfts_index_post', function( $chunks, $post, $is_refresh_raw_cache ) {
        if ( $post->post_type == 'events' ) {
    	$date_listing = get_post_meta( $post->ID, 'date_listing', true );
    
    	if ( $date_listing <= $date_now ) {
                // i was returning false here, which i now realize was wrong.
    	    return array();
    	}
        }
    
        return $chunks
    }
    

    On another note
    I do get this message but it keeps on repeating itself even when i upgrade the index multiple times.

    Screenshot 2025-02-25 at 8.47.58 AM.png

    Upon trying to investigate

    Screenshot 2025-02-25 at 8.51.45 AM.png

    I found the action but see the value on z missing, which i think doesn't then pass on properly down the chain and update the index.

    I might be completely wrong here. Trying to analyze and help out.


  • Hi @alihs

    I hope the code you showed is an excerpt and you still have

    $date_now = current_time('timestamp');
    

    somewhere and also your $date_listing value is a Unix timestamp (integer).

    For the second case: this AJAX action is used by the WP admin to refresh some index statistics, it does not have any parameters (that's why "z" is empty here).

    The message you see means that 257 posts were processed by an outdated version of one or more indexing rules and WPFTS wants to reindex them to bring everything into compliance.
    You can open the page with the list of rules and see which indexing rules are not compliant.
    You can also send me a screenshot so I can help you figure this out.

    By the way, this may be due to the fact that you somehow change some posts from the code, but do not call the "save_post" hook, which triggers reindexing under the hood. Because of this WPFTS considers these posts outdated. If the number of posts controlled by the rule is not 257, then this is exactly the case.

    Let me know if you have more information.
    Thanks!


  • Hi @EpsilonAdmin
    Yes, i do have $date_now and yes its part of an excerpt. I had it fixed by passing empty array instead of returning false.

    The index refresh keeps on displaying, initially its 257 and then get to 90ish and then again 257. Seems to be an infinite loop

    https://streamable.com/etht3a

    Thanks


  • Hi @alihs

    Thank you for your reply!
    According to the video you sent it looks like you have around 257 that is constantly refreshing. Those posts are simple and short, and reindeer can refresh them in one internal "tick", but it looks like they are changed very often.

    Strange thing, actually!

    Could you check the Indexing Rules page where it may show which rule has those 257 unsynced posts?

    Also, could you say which 257 posts you have? May be specific post type has exactly 257 records or something.

    Thank you!


  • @EpsilonAdmin

    We have over 600+ posts. Other CPT amounts to ~500 spread across around 7-8 different CPTs.
    I keep getting the indexing message.
    Memcache/Redis is turned off as well as DB cache, still get the same thing.
    Re-indexing does sort it out.


  • While here, would like to suggest to add filters for enqueue of js and css files so we could disable them if needed or overwrite them.

    Much appreciated


  • Hi @alihs

    I think I know what happens.

    There is a "hidden" property of $chunks that we remove when returning array().

    This property contains the list of rules applied to the post, and this fact actually forces WPFTS indexer to mark posts as "non-correct" indexed.

    This is what I say about:
    alt text

    We have "__used_rules" property in $chunks which we have to store.

    Please change your hook code like this

    	if ( $date_listing <= $date_now ) {
                // i was returning false here, which i now realize was wrong.
    	    return array(
                     '__used_rules' => $chunks['__used_rules'],
                );
    	}
    

    I think that should help.

    Please try and let me know what happens.

    Thank you!


  • @EpsilonAdmin I don't see the error anymore. Give me a day to troubleshoot further

Suggested Topics

Be the first to read the news!

We are always improving our products, adding new functions and fixes. Subscribe now to be the first to get the updates and stay informed about our sales! We are not spammy. Seriously.

Join Us Now!

We are a professional IT-team. Many of us have been working in a Web IT field for more than 10 years. Our advanced experience of software development has been employed in the creation of the WordPress FullText Search plugin. All solutions implemented into the plugin have been used for 5 or more years in over 60 different web-projects.

We are looking forward to your comments, requests and suggestions in relation to the current plugin and future updates.

ewm-logo-450

The forum powered by NodeBB | Contributors