Ignore page elements

I’ve got “Next” and “Previous” links at the top of pages. Is there a way for Algolia to not display these words in search results?

That’s definitely possible, but depends how you’re indexing. Are you using a plugin or crawling?

Thanks. I’m using the WordPress plugin

Hey @ben3 thanks for reaching out,

I think that in your use case, the best would be to use a regex to remove the part you are interested in removing.

You can use a filter declared here: https://github.com/algolia/algoliasearch-wordpress/blob/master/includes/class-algolia-utils.php#L199

Then it’s up to you to adjust the regex according to what the “previous next” buttons look like in the content.

If they are a shortcode like “[prevnext][/prevnext]”, then you could do:

<?php
add_filter( 'algolia_strip_patterns', function( $patterns ) {
    $patterns[] = '/\[\/?prevnext.*?\]/';

    return $patterns;
} );

Let me know if that doesn’t help!

1 Like

Thanks. I actually use a bullet point with a css class <div class="previousarrow">

Would that still work?

You’d have to adapt the regex pattern to match your use case.

You can try out the pattern on https://regexr.com/.

Let us know if you manage to make it work!

I’m sorry, I’ve no idea what I’m doing here.
I’m not an expert in PHP and haven’t used Regex before. Could you give me some more help please.

@ben3 with the current information I have, I’m unfortunately not able to make sure the code I’ll share will work in your use case. I don’t know what injects the prev next links. I don’t know if there are spaces, attributes or other things that could impact the regex.

Could you send a quick message to support@algolia.com with the details of your account so that we can find a solution to help you more in depth?

I’d love to know a bit more about the project and the challenges you face to see how we could help you ship your search experience.

Speak soon,