Continue reading Indexing attachments from File blocks

Indexing attachments from File blocks

…this function to your site to index the contents of files added with the File block: add_filter( ‘relevanssi_block_to_render’, function( $block ) { if ( ‘core/file‘ === $block[‘blockName’] ) { $file_id = $block[‘attrs’][‘id’]; $file_content = get_post_meta( $file_id, ‘_relevanssi_pdf_content’, true ); if ( $file_content ) { $block[‘innerContent’][0] = $file_content; } } return…The Relevanssi attachment indexing assumes the files are connected to the posts using the WordPress attachment mechanism. What if you don’t use that but instead add the files to the pages using the File block in the block editor? That’s not a problem, but it requires some extra code. Add……); if ( $file_content ) { $content = preg_replace( ‘#’ . preg_quote( $matches[0], ‘#’ ) . ‘#’, $file_content, $content ); } } return $content; }, 10, 2 ); This filter uses relevanssi_pre_excerpt_content and replaces the file block comment in the post content with the file contents from the custom field….

Read more Indexing attachments from File blocks 0 Comment on Indexing attachments from File blocks
Continue reading Attachment file content cannot be saved

Attachment file content cannot be saved

The Relevanssi error “Could not save the file content to the custom field” means that Relevanssi has managed to read the attachment contents but cannot save them to the _relevanssi_pdf_content custom field Relevanssi uses to store the attachment contents. Relevanssi uses the update_post_meta() function to save the content, and for…

Read more Attachment file content cannot be saved 0 Comment on Attachment file content cannot be saved
Continue reading Indexing and searching PDFs in WordPress

Indexing and searching PDFs in WordPress

…service on a separate server. Which PDF files can you index? Since Relevanssi is a WordPress search, Relevanssi operates on WordPress posts (including all the different post types). So, to have Relevanssi index your PDFs, they need to be WordPress posts. That’s fortunately really simple: upload your PDF files to……the Media library, and they become posts with the post type of attachment. Relevanssi can only parse and read PDF files that contain text. If the PDF file is all images, Relevanssi cannot read it. An easy way to check is to try to select the text in a PDFRelevanssi Premium users have asked for PDF indexing since day one, and version 2.0 finally introduced this feature. Coming up with a fast and reliable method hasn’t been easy, but we’re pretty proud of what we have now. Our PDF indexer doesn’t tax your server as it runs as a…

Read more Indexing and searching PDFs in WordPress 78 Comments on Indexing and searching PDFs in WordPress
Continue reading Controlling attachment types in index

Controlling attachment types in index

….= ‘ No images’; return $restriction; } Only PDFs This function will only index PDF attachments, and nothing else. add_filter( ‘relevanssi_indexing_restriction’, ‘rlv_only_pdfs’ ); function rlv_only_pdfs( $restriction ) { global $wpdb; $restriction[‘mysql’] .= ” AND post.ID NOT IN (SELECT ID FROM $wpdb->posts WHERE post_type = ‘attachment’ AND post_mime_type != ‘application/pdf‘ )…

Read more Controlling attachment types in index 16 Comments on Controlling attachment types in index
Continue reading Indexing attachment file names

Indexing attachment file names

…( ‘attachment’ === $post->post_type ) { $content .= ‘ ‘ . basename( $post->guid ); } return $content; } Notice that by default Relevanssi replaces periods with spaces, so “sample.pdf” is indexed as “sample pdf”. That should not be a problem, as also in searching “sample.pdf” becomes “sample pdf”. However, if…Relevanssi has been working nicely for the normal usecase. But how does one setup indexing of attachment files. When someone searches by a file name or an extension like pdf, there are no results. I have enabled ‘attachment’ at Relevanssi ‘Indexing options’ and still there are no results. Relevanssi doesn’t…

Read more Indexing attachment file names 7 Comments on Indexing attachment file names