larasearch icon indicating copy to clipboard operation
larasearch copied to clipboard

Automatic reindexing not working ?

Open prigal opened this issue 9 years ago • 1 comments

I add the

use \Iverberk\Larasearch\Traits\SearchableTrait;

on my Product model.

Then I do a

$product= new Product(['title'=>'Amazing']);
$product->save();

Then I try to search via :

curl -XGET 'http://127.0.0.1:9200/products_20150722092624/_search?pretty=1&q=Amazing'
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

Why the index wasn't updated after save() to make 'Amazing' searchable ? Do I forgot to do something ?

Thank you.

prigal avatar Jul 23 '15 15:07 prigal

i has same problem. this is what i did.

To fix auto index for larasearch find around line 25 in: /vendor/larasearch/src/Iverberk/Larasearch/Observer.php

         /**
     * Model save event handler
     *
     * @param Model $model
     */
    public function saved(Model $model)
    {
        if ($model::$__es_enable && $model->shouldIndex())
        {
            Queue::push('Iverberk\Larasearch\Jobs\ReindexJob', $this->findAffectedModels($model));
        }
    }

Change to:

         /**
     * Model save event handler
     *
     * @param Model $model
     */
    public function saved(Model $model)
    {

            Queue::push('Iverberk\Larasearch\Jobs\ReindexJob', $this->findAffectedModels($model));

    }

smithdp1 avatar Aug 12 '15 19:08 smithdp1