Drupal coder

Performance tip : disable Drupal's core search indexer when using Apache Solr

Here's a quick tip for people using the (simply awesome) Apache Solr Search Integration module.

The Apache Solr module depends on Drupal's core Search module. This means the Search module will be enabled too when the Solr module is installed. As soon as the core Search module is enabled it starts to index all your nodes and stuff too. This not only takes time to run, but also fills up your database (search_dataset, search_index, ... tables).

Most of the time when you are installing the Apache Solr Search module, you don't need Drupal's core search form and replace the search form with the Apache Solr one using the Apache Solr module setting "Make Apache Solr Search the default:". You have now disabled the core Search module's form, but you have not disabled the indexing. To disable the indexing and save some CPU cycles and database space, just go to your site's search settings page (admin/settings/search) and set the "Number of items to index per cron run" to 0.

search-index-limit.png

May 13, 2010Apache Solr, Drupal, performance, search

Comments

After doing this, is it safe to truncate the search_* tables? Because we're still getting 20 seconds queries from the search_update_totals() function. Even after clicking re-index in core search.

search_index has ~5.500.000 rows and search_index has ~375.000 rows.

Odd - I don't have a "0" option in that dropdown. The lowest is "10". Drupal 6.19.

Thanks.
In many cases you can also consider using google site search API to get rid of complex indexing processes at all: http://code.google.com/apis/ajaxsearch/

A trusted source warned me that this wasn't necessarily a great idea, in that Views searches use drupal's core search index, not solrs. If you not using views to provide a special search, then I guess you're good to go.

Thanks for his advice :)
And after setting the "Number of items to index per cron run" to 0 I clicked on "Re-index site", and that should have flushed the db tables. Great!

Good advice. Damien, adding this flag in settings is a good suggestion.

Great stuff, I'll try the module for my site. Thanks for sharing.

This could also be added to a settings.php file as follows:

$conf['search_cron_limit'] = 0;

This was an "ah haa" realization for me too. I'm sorry to say I had to go digging into the search module to turn it off. Now I know how to do it properly (and easily). Definitely something for the Solr doc I reckon. Thanks for the heads up.

Ahhhhh.

I always wondered about that and assumed that Solr must somehow hook into that.

I guess not.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options