Customization to index files from wp downloads manager to Elasticsearch

  • support
    Participant
    3 years, 8 months ago #21376

    Dear WPSolr team,

    I would like to make use of your plugin in order to index documents and pdf files to Elasticsearch and enable a full text search feature on my website.

    Actually, the website uses WP Download Manager (https://www.wpdownloadmanager.com/) in order to organise their files. So those are custom post types that save the file

    May you send a quotation for this kind of customization?

    Thank you.

    Best regards,

    Hendrik

    wpsolr
    Keymaster
    3 years, 8 months ago #21378

    WPSOLR already indexes custom post types and attachment files.

    support
    Participant
    3 years, 8 months ago #21379

    Hi there,

    I gave it a try because the “Download” post type is recognized.
    If I search for a word that is included in the “Download” post name, WPSolr find it, unfortunately I can’t search text inside any pdf file linked to this post type.

    Even by checking all fields and taxonomies, when I export my data to Elasticsearch, I don’t see a big difference in index size compared to the difference when I ingest other media files.
    There should be 140 pdf files ingested into the index.

    For information, those files aren’t inside the post description, but uploaded in a dedicated WP download manager field on the post itself. Those files also aren’t displayed through the WordPress media file system.

    If you have any knowledge with this kind of behavior, do you have any hypothesis to resolve this?

    Thank you.

    Best regards,

    Hendrik

    wpsolr
    Keymaster
    3 years, 8 months ago #21380

    Does the custom field on your post type contain the PDF content, or a link to the PDF content?

    support
    Participant
    3 years, 7 months ago #22083

    Hi there,

    Apparently my answer didn’t go through.
    I’ve tried to manually and a direct link to the pdf in the post meta fields, but those files aren’t taken into Elasticsearch.
    The wpdownloads attachement field isn’t a standard file type as the files aren’t managed through the WordPress medias.

    How may I achieve this then ?

    Thank you.

    Best regards,

    Hendrik

    wpsolr
    Keymaster
    3 years, 7 months ago #22086

    WPSOLR does extract file content from custom fields, but only for ACF, in a dedicated extension.

    support
    Participant
    3 years, 7 months ago #22087

    Hi there,

    Does it extract file content if I add the URL to the file in a URL field?
    How may I achieve this by having the URL to the file?

    Thank you.

    Bets regards,

    Hendrik

    wpsolr
    Keymaster
    3 years, 7 months ago #22088

    Add a new ACF file field to your products, and activate the WPSOLR ACF extension.

    support
    Participant
    3 years, 7 months ago #22091

    Hi there,
    As explained WP download manager has no relation to ACF file field.

    Best File / Document Management & Digital eCommerce Plugin for WordPress


    The plugin has a file field like here:
    __wpdm_files : a:1:{i:0;s:46:”5e312bd311838c_filename.pdf”;}
    I can programmatically add a URL to the pdf file, but not a File type field as ACF makes use of.
    Please, may it be possible to estimate how WPSOLR might include WP download manager files?

    Thank you.

    Best regards,

    Hendrik

    wpsolr
    Keymaster
    3 years, 7 months ago #22092

    With ACF, you can add custom fields to any post type.
    If you think you need a custom development, please contact us with the “Pricing” button in the header.

    support
    Participant
    3 years, 6 months ago #22175

    Hi there,

    I found my way by adding a filter in the functions.php file of my theme.
    If anyone is looking to index WP Download Manager Pro downloads with WPSolr, here you go

    
    /*
    * Add WP download manager attachements in WPSolr indexer
    */
    use wpsolr\core\classes\WPSOLR_Events;
    add_filter( WPSOLR_Events::WPSOLR_FILTER_GET_POST_ATTACHMENTS, 'filter_get_wpdm_post_attachments', 10, 2 );
    function filter_get_wpdm_post_attachments( $attachments, $post_id ) {
    
        if ( get_post_type( $post_id ) != 'wpdmpro' ) {
            return $attachments;
        }
    
        $wpdm_files = get_post_meta( $post_id, '__wpdm_files', true );
    
        if ( ! empty( $wpdm_files ) ) {
    
            foreach ( $wpdm_files as $key => $file_name ) {
    
                $download_link = get_permalink( $post_id ).'?wpdmdl='.$post_id."&ind=".$key."&filename=".$file_name;
                array_push( $attachments, [ 'url' => $download_link ] );
    
            }
    
        }
    
        return $attachments;
    }
    
    support
    Participant
    3 years, 6 months ago #22177

    I’ve enhanced the function a little bit by disabling locked downloads indexing

    
    /*
    * Add WP download manager attachements in WPSOLR indexer
    */
    add_filter( WPSOLR_Events::WPSOLR_FILTER_GET_POST_ATTACHMENTS, 'filter_get_wpdm_post_attachments', 10, 2 );
    function filter_get_wpdm_post_attachments( $attachments, $post_id ) {
    
        if ( 'wpdmpro' != get_post_type( $post_id ) ) {
    
    		return $attachments;
    		
        }
    
    	$wpdm_files = get_post_meta( $post_id, '__wpdm_files', true );
    	$wpdm_locked = wpdm_is_locked( $post_id );
    
        if ( ! empty( $wpdm_files ) && !$wpdm_locked ) {
    
            foreach ( $wpdm_files as $key => $file_name ) {
    
                $download_link = get_permalink( $post_id ).'?wpdmdl='.$post_id."&ind=".$key."&filename=".$file_name;
                array_push( $attachments, [ 'url' => $download_link ] );
    
            }
    
        }
    
        return $attachments;
    }
    
Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.