algolia / scout-extended

Scout Extended: The Full Power of Algolia in Laravel
https://www.algolia.com/doc/framework-integration/laravel/getting-started/introduction-to-scout-extended/
MIT License
400 stars 87 forks source link

Why is the Record deleted before updating? #202

Open finalgamer opened 5 years ago

finalgamer commented 5 years ago

In https://github.com/algolia/scout-extended/blob/db5bd4135c66738b79450d20fc6368a97fc8175e/src/Jobs/UpdateJob.php#L137 a request to delete the object from the search index is sent. One line below is the actual updateObject action, which is sent to Algolia.

Why is the object deleted before the update?

Due to this every update does also trigger a delete query doubling the amount of operations made on the index and basically doubling the cost of the Algolia subscription.

nunomaduro commented 5 years ago

Normally, we just send a delete if there is something that needs to be deleted: https://github.com/algolia/scout-extended/blob/db5bd4135c66738b79450d20fc6368a97fc8175e/src/Jobs/DeleteJob.php#L49.

Do you have a use case where you are being impacted by this? If yes, can you detail it?

finalgamer commented 5 years ago

I have done some more digging and found that this is caused by my Eloquent Model having a splitter for a property.

For a more concrete example. We are storing news articles which may have a body property larger than the Algolia index size. Because of that we do split the body just before the limit is reached. Which most of our bodies do not reach, which means they are not split in multiple records.

I assume your intention with deleting the records is to ensure all split records are up to date. If this is the case is there a way to reduce this to one operation?

nunomaduro commented 5 years ago

@finalgamer You described perfectly the implementation. Is exactly that.

We don't have nothing in place to reduce this to one operation. Any ideas?

finalgamer commented 5 years ago

My workaround would be to store the amount of records it generates in the database with the model and when updating the record the new count and last count are compared.

My other workaround, which might work in my case, is to remove the splitting again and deal with incomplete search data on large articles.

nunomaduro commented 5 years ago

My workaround would be to store the amount of records it generates in the database with the model and when updating the record the new count and last count are compared.

Would be willing to code and add this feature?