Hello.
I have an entity type with around 315000 items in it, which i need to index with ApacheSolr. But when i try to create an search_api index for it i get the WSOD. After page refresh the index is exist but i have 0 items to index.
I found out that the SearchApiAbstractDataSourceController->trackItemInsert() method can't hadle all 315000 items in one array. So, i suggest it should be chunked into smaller pieces.
diff --git a/sites/all/modules/search_api/includes/datasource.inc b/sites/all/modules/search_api/includes/datasource.inc
old mode 100644
new mode 100755
index 684a694..9b8166a
--- a/sites/all/modules/search_api/includes/datasource.inc
+++ b/sites/all/modules/search_api/includes/datasource.inc
@@ -475,19 +475,22 @@ abstract class SearchApiAbstractDataSourceController implements SearchApiDataSou
if (!$this->table) {
return;
}
- $insert = db_insert($this->table)
- ->fields(array($this->itemIdColumn, $this->indexIdColumn, $this->changedColumn));
- foreach ($item_ids as $item_id) {
- foreach ($indexes as $index) {
- $this->checkIndex($index);
- $insert->values(array(
- $this->itemIdColumn => $item_id,
- $this->indexIdColumn => $index->id,
- $this->changedColumn => 1,
- ));
+
+ foreach (array_chunk($item_ids, 1000) as $chunk) {
+ $insert = db_insert($this->table)
+ ->fields(array($this->itemIdColumn, $this->indexIdColumn, $this->changedColumn));
+ foreach ($chunk as $item_id) {
+ foreach ($indexes as $index) {
+ $this->checkIndex($index);
+ $insert->values(array(
+ $this->itemIdColumn => $item_id,
+ $this->indexIdColumn => $index->id,
+ $this->changedColumn => 1,
+ ));
+ }
}
+ $insert->execute();
}
- $insert->execute();
}
/**
Comments
Comment #1
drunken monkeyGood catch, thanks!
Also works for me and seems innocent enough. Let's just wait a few days whether someone objects, and then I'll happily commit this.
Comment #2
drunken monkeyCommitted, thanks again!
Comment #3
Oleksandr.Masovets commentedNP. Glad to help :)