Skip to main contentSkip to footer

I have some trouble with reindexing of new posts. The reason is simple – I sync data into the database automatically.

So what I need is a cronjob to reindex the site once a day. How do I do a cronjob?

The easiest way would be to get Relevanssi Premium and use WP CLI, so you can just say wp relevanssi index to get the job done.

If that’s not possible, you need to use the function relevanssi_build_index() to build the index. It’ll work fine if your database is small enough so that you can index it in one go; if not, you need to run it several times, first with

relevanssi_build_index(false, false, X);

then

relevanssi_build_index(true, false, X);

as many times as is necessary, where X is the number of posts you are guaranteed to be able to index at one go.

Creating URLs for the cron job

To make this happen in practice, you need two files. First, create a file relevanssi-start-indexing.php with this content:

<?php
require 'wp-blog-header.php';
relevanssi_build_index( false, false, 100 );

and then a file relevanssi-continue-indexing.php with this content:

<?php
require 'wp-blog-header.php';
relevanssi_build_index( true, false, 100 );

This assumes the files are in your WP installation root directory. If they’re not, adjust the path to wp-blog-header.php so that it points to the right place.

Now to start indexing, have the cron job visit the relevanssi-start-indexing.php – this will start the indexing and will index 100 posts. Then have the cron job visit relevanssi-continue-indexing.php as many times as is necessary to have everything indexed.

You don’t have to do this 100 posts at a time, but you need to adjust the number based on your site: how many posts can be indexed before PHP execution times out? It’s likely something like 500, but the exact number depends on your posts and server.

Removing automatic indexing

If you index with a cron job, you may want to disable automatic indexing. You can do it by adding this to your site:

remove_action( 'wp_insert_post', 'relevanssi_insert_edit', 99 );
remove_action( 'wp_after_insert_post', 'relevanssi_insert_edit', 99 ); // Relevanssi 4.17 / Premium 2.19 onwards.

This was asked at the WordPress.org support forums.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Restricting Did you mean suggestions to one post type

Sometimes it may be necessary to restrict the Did you mean suggestions Relevanssi serves to just one post type. There’s no option for that, as by default the Relevanssi database the Did you mean suggestions use as a source (this only applies to Premium, that is) doesn’t have any information……about the post types the words are related to. However, it does have the post ID, which can be linked to a post type, and there’s a filter hook that lets us modify the query that fetches the words from the database. Then it’s just a question of formulating some…

Relevanssi and languages

Relevanssi is language-agnostic in itself. It does not know any language and doesn’t care about which language the site uses. However, there are a few things that you need to consider when using Relevanssi in languages other than English. Characters: use UTF8 As long as your site uses UTF8 characters,……mean” suggestions in Relevanssi Premium only support Latin characters. The way these suggestions work is that when Relevanssi searches, Relevanssi then modifies the search term in different ways by adding or removing letters in it. Relevanssi does these modifications with the Latin alphabet (mainly the English alphabet, with a few…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed