Solr autocommit and autooptimize?

2019-03-31 20:09发布

问题:

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:

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>