/** * add a document to the list. To index all the list execute flushDocuments * * @param \Elastica\Document $document * */ protected function pushDocument($document) { // Get language if exists $lang = $document->__isset('language') ? $document->language : '*'; //Add boost field if does not exist if (!$document->__isset('boost') && $this->boost) { $document->set('boost', $this->boost); } // Extract the first letter of the langue (en for en-GB) $explode = explode('-', $lang); $lang = $explode[0]; // If it is the first of this language if (!array_key_exists($lang, $this->documents)) { $this->documents[$lang] = array(); // Init array } // add document to the list $this->documents[$lang][] = $document; $mem_limit_bytes = trim(ini_get('memory_limit')) * 1024 * 1024; if (memory_get_usage() > $mem_limit_bytes * 0.2) { // Check memory use //if documents array is too big we flush it $this->flushDocuments(); } }