Skip to content

Automatic reindexing

iverberk edited this page Dec 28, 2014 · 1 revision

Basic usage

By including the CallableTrait on your models you make them observable for Larasearch. Any changes to the model will be automatically propagated to the related searchable models. The searchable model and it relations (thus including the changed model) are automatically reindexed to Elasticsearch. This way you never have to worry about your Elasticsearch documents being out of sync. The functionality is actually implemented as a queue so you can (and probably should) process the change asynchronously.

Preventing a (re)index

Sometimes you want extra control over the automatic reindexing. Larasearch provides this in the form of a shouldIndex method which you can define on your model. Within this function you can define additional to logic to decide whether or not you want the reindex to proceed.

class Husband extends Eloquent {

    ...

    /**
     * @return bool
     */
    public function shouldIndex()
    {
        // Your custom logic to determine if a (re)index should be performed
    }

}