If an item is deleted from system, search api doesn't delete this item in the server because it's getting the wrong id; this causes an error when the search returns an item that is in the index but not in the Drupal.

I'll submit a patch.

Comments

kporras07 created an issue. See original summary.

kporras07’s picture

This patch fixes my issue by passing full item id to search_api_track_item_delete so that it can now how to delete it from server.

(It previously deleted the item from the tracking table because it was using the right Datasource Controller but the item wasn't deleted form server)

kporras07’s picture

Status: Active » Needs review

I forgot to update status :(

Status: Needs review » Needs work

The last submitted patch, 2: search_api_et-search_api_delete_items-2811811-2.patch, failed testing.

jseffel’s picture

Seems to work.

The last submitted patch, 2: search_api_et-search_api_delete_items-2811811-2.patch, failed testing.

fmfpereira’s picture

Do not work for me, at least using commerce_product entity.

The main problem is that search_api_et_entity_delete (hook implementation) runs after the entity has been deleted from database.

search_api_track_item_delete calls search_api_get_datasource_controller($type)->trackItemDelete and at one point method getTrackableEntityIds() is called.

getTrackableEntityIds() checks database to see if entity exists on the base table, but since the entity has been deleted from database, the index is nor returned and the entity is not deleted.

search_api_track_item_delete should be executed before entity being removed from database, or at least for all the indexes the uses that entity type.

joel_osc’s picture

From the node.module code it appears that the delete hooks are called prior to the node being deleted. The most recent dev version of this module addresses building the proper IDs, however, I am still having a problem with nodes still stuck in the index. Here is a patch that worked for me, but I am no expert with SearchApi so I would appreciate any feedback from the maintainers and the community. Cheers.

joel_osc’s picture

Status: Needs work » Needs review
thomas.claes’s picture

Like fmfpereira already said

Do not work for me, at least using commerce_product entity.

The main problem is that search_api_et_entity_delete (hook implementation) runs after the entity has been deleted from database.

search_api_track_item_delete calls search_api_get_datasource_controller($type)->trackItemDelete and at one point method getTrackableEntityIds() is called.

getTrackableEntityIds() checks database to see if entity exists on the base table, but since the entity has been deleted from database, the index is nor returned and the entity is not deleted.

search_api_track_item_delete should be executed before entity being removed from database, or at least for all the indexes the uses that entity type.

In DrupalCommerceEntityController->delete(), the commerce_product is first deleted and afterwards, the hook_entity_delete() is fired.
So we don't have a way to do 'predeletion'-operations on the commerce_product.

david.lopez’s picture

My suggestion is just to send all the possible translations to the search_api and this will take care of it.

czigor’s picture

Status: Needs review » Reviewed & tested by the community

Tested #11 and it works. It also makes sense to go through all enabled languages.

On our site we still have disabled language items in the index, although #2777767: Items are indexed also for Disabled languaegs should have fixed that. Therefore we still have items of disabled languages in the index after deleting the entity, but I think that's a different issue.

As per the question of running hook_entity_delete() before or after the db is updated I don't think we can do much. Even search_api removes items in search_api_entity_delete().

joel_osc’s picture

Agree to the approach, patch works for me as well.

ciss’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/search_api_et.module
@@ -310,9 +310,21 @@ function search_api_et_entity_delete($entity, $entity_type) {
+  if (isset($entity->translations)) {

This feels unsafe. Shouldn't we fetch the translations via the ET translation handler?

lendude’s picture

StatusFileSize
new1.09 KB
new1.07 KB

#14 makes sense, with the fix in #11 any entity with no translations (only 'und') would still not be deleted since that is not an active language.

This implements #14.

idebr’s picture

Status: Needs review » Reviewed & tested by the community

Patch works as expected for content entered as LANGUAGE_NONE as well as content that is assigned to a language and their entity translations.

idebr’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.51 KB
new3 KB
new4.52 KB

The last submitted patch, 17: 2811811-17-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • idebr authored b5970e7 on 7.x-2.x
    Issue #2811811 by idebr, Lendude, kporras07, joel_osc, david.lopez:...
idebr’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.