views:

170

answers:

1

I will be uploading my website to a VPS soon. It is a classifieds website which uses Solr integrated with MySql.

Solr is updated whenever a new classified is put or deleted.

I need a way to make the commit() and optimize() be automated, for example once every 3 hours or so.

How can I do this? (Details Please) When is it ideal to optimize?

Thanks

+1  A: 

You could set up a cron task that periodically executes a remote call to the Solr REST interface, e.g:

curl 'http://<SOLR_INSTANCE_URL>/update?optimize=true'

Find further info on updating the Solr index here.

Quoting the Solr tutorial:

Commit can be an expensive operation so it's best to make many changes to an index in a batch and then send the commit command at the end. There is also an optimize command that does the same thing as commit, in addition to merging all index segments into a single segment, making it faster to search and causing any deleted documents to be removed.

UPDATE: Besides, the auto-commit feature can be enabled in solrconfig.xml (within the UpdateHandler section):

<autoCommit>
      <maxDocs>10000</maxDocs> <!-- maximum uncommited docs before autocommit triggered -->
      <maxTime>86000</maxTime> <!-- maximum time (in MS) after adding a doc before an autocommit is triggered -->
</autoCommit>
nuqqsa
Thanks for the answer. Here is a follow-up Q, does optimize also perform commit? So when doing only optimize it also commits? Thanks
Camran
Yes, optimize performs commit plus merging all index segments into a single segment (a new segment is created when a new writer is opened and when a writer commits or is closed).
nuqqsa