• Resolved synthesiamaniac

    (@synthesiamaniac)


    I recently noticed that when I updated Relevanssi, the search results excepts were missing data. I have numerous download pages on my site which use a shortcode to pull the filenames from a folder and build hyperlinks on the page. In previous versions, using the expand shortcode option indexed all of these filenames and displayed the relevant ones in the search excerpt. However, in the newer version, the excerpt only displays the headers that are on the page but none of the shortcode information.

    I have two filters for the plugin which are used to format the except to make it look like a list and have allowed <br> tags in the except. These are the filters:

    
    add_filter( 'relevanssi_post_content', 'rlv_filesize' );
    function rlv_filesize( $content ) {
    	$content = preg_replace( '#<td class="filesize".*?</td>#', '', $content );
    	return $content;
    }
    
    add_filter( 'relevanssi_excerpt_content', 'rlv_excerpt', 10, 2 );
    function rlv_excerpt( $content, $post ) {
    	$content = preg_replace( '#<td class="filesize".*?</td>#', '<br />', $content );
    	return $content;
    }
    

    I am not sure why it is not working and would appreciate your feedback. It may have to do with the new Gutenberg system.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Is the “Use custom field content for building excerpts” option checked in the Relevanssi Excerpts and highlights tab, and is it listing the correct shortcodes?

    Gutenberg should not affect the excerpts. Also, it looks like indexing works and the problem is only in the excerpts. Has anything changed in how your theme displays the excerpts?

    Thread Starter synthesiamaniac

    (@synthesiamaniac)

    The “Use custom field content for building excerpts” option is checked and in the indexing tab, the option “Custom Fields” is set to all.

    Nothing has changed in the theme. The only updates are new versions of WordPress.

    Thread Starter synthesiamaniac

    (@synthesiamaniac)

    Furthermore, I noticed that the “Breakdown of search results” feature is not working either.
    The box “Show the breakdown of search hits in the excerpts” is checked and the breakdown format is defined as:

    (Search hits: %body% on page)
    
    Plugin Author Mikko Saari

    (@msaari)

    If the breakdown is not showing up, then there’s a good reason to assume the excerpts are not generated by Relevanssi at all.

    Is your theme using the_excerpt() to print out the excerpts, or perhaps something else?

    Thread Starter synthesiamaniac

    (@synthesiamaniac)

    I am using the Customizr theme and it should be using the_excerpt() to print out the page excerpts. The theme has not been modified so that functionality should not have changed, unless updates to WordPress changed the way the excerpt function works. It was orginally working back when the plugin was first installed.

    Is there a way to test if the_excerpt() is being used?

    Plugin Author Mikko Saari

    (@msaari)

    The best way to test is to make changes to Relevanssi excerpt settings (or disable the excerpts completely) and see if that changes the excerpts.

    You can also debug your excerpt function, because that’s likely the part that’s not working:

    add_filter( 'relevanssi_excerpt_content', 'rlv_excerpt', 10, 2 );
    function rlv_excerpt( $content, $post ) {
    	var_dump( $content );
    	$content = preg_replace( '#<td class="filesize".*?</td>#', '<br />', $content );
    	var_dump( $content );
    	return $content;
    }

    If you change the function to that, then search for “linkin park”, what does it print out?

    Thread Starter synthesiamaniac

    (@synthesiamaniac)

    So after adding in various filters to test the functionality of Relevanssi, it seemed like everything was configured correct. After some additional debugging, I found that the plugin “Give”, after the latest update, is blocking or breaking the excerpt functionality of the plugin. Disabling that fixed the problem.

    Now, for one final question….
    I added two filters, as previously mentioned, to organize the excerpt in a list fashion and remove the file size label. However, occasionally I get a <\> or \> symbol in the excerpt and sometimes the text “file size”.

    How can I remove that code that is being inserted into the excerpt and remove the table headers from the excerpt? The “name” and “file size” text comes from the headers on the tables where the download links are organized.

    For example, if the term “link” is searched for, the results page generates this:

    The Legend of Zelda: A Link to the Past File Size The Legend of Zelda A Link to the Past – Credits 
    The Legend of Zelda: Four Swords Adventures File Size The Legend of Zelda Four Swords Adventures… (Search hits: 3 on page)

    The results are not in the list format and the text “File Size” is visible.

    Plugin Author Mikko Saari

    (@msaari)

    You can modify the filter so that it will also remove the table headers, like this:

    add_filter( 'relevanssi_excerpt_content', 'rlv_excerpt', 10, 2 );
    function rlv_excerpt( $content, $post ) {
    	$content = preg_replace( '#<th.*?</th>#', '<br/>', $content );
    	$content = preg_replace( '#<td class="filesize".*?</td>#', '<br/>', $content );
    	return $content;
    }

    As for the extra symbols, not sure about that –?Relevanssi shouldn’t split HTML tags in excerpts. I made a small change in the function above which may help.

    Thread Starter synthesiamaniac

    (@synthesiamaniac)

    Thank you very much!!
    Everything is working as it should now.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Search Excerpt does not include Shortcode Results’ is closed to new replies.