/* {{{ proto void SolrInputDocument::__construct() SolrInputDocument constructor */ PHP_METHOD(SolrInputDocument, __construct) { zval *objptr = getThis(); uint nSize = SOLR_INITIAL_HASH_TABLE_SIZE; ulong document_index = SOLR_UNIQUE_DOCUMENT_INDEX(); auto solr_document_t solr_doc; solr_document_t *doc_entry = NULL, *doc_ptr = NULL; memset(&solr_doc, 0, sizeof(solr_document_t)); doc_entry = &solr_doc; doc_entry->document_index = document_index; doc_entry->field_count = 0L; doc_entry->document_boost = 0.0f; /* Allocated memory for the fields HashTable using fast cache for HashTables */ ALLOC_HASHTABLE(doc_entry->fields); ALLOC_HASHTABLE(doc_entry->children); /* Initializing the hash table used for storing fields in this SolrDocument */ zend_hash_init(doc_entry->fields, nSize, NULL, (dtor_func_t) solr_destroy_field_list, SOLR_DOCUMENT_FIELD_PERSISTENT); zend_hash_init(doc_entry->children, nSize, NULL, ZVAL_PTR_DTOR, SOLR_DOCUMENT_FIELD_PERSISTENT); /* Let's check one more time before insert into the HashTable */ if (zend_hash_index_exists(SOLR_GLOBAL(documents), document_index)) { pefree(doc_entry->fields, SOLR_DOCUMENT_FIELD_PERSISTENT); pefree(doc_entry->children, SOLR_DOCUMENT_FIELD_PERSISTENT); return; } /* Add the document entry to the directory of documents */ zend_hash_index_update(SOLR_GLOBAL(documents), document_index, (void *) doc_entry, sizeof(solr_document_t), (void **) &doc_ptr); /* Set the value of the internal id property */ zend_update_property_long(solr_ce_SolrInputDocument, objptr, SOLR_INDEX_PROPERTY_NAME, sizeof(SOLR_INDEX_PROPERTY_NAME) - 1, document_index TSRMLS_CC); /* Keep track of how many SolrDocument instances we currently have */ SOLR_GLOBAL(document_count)++; /* Overriding the default object handlers */ Z_OBJ_HT_P(objptr) = &solr_input_document_object_handlers; }
/* {{{ proto void SolrInputDocument::__clone(void) Clones the current object. Not to be called directly. */ PHP_METHOD(SolrInputDocument, __clone) { zval *objptr = getThis(); solr_document_t new_solr_doc; solr_document_t *new_doc_entry = NULL, *old_doc_entry = NULL; ulong document_index = SOLR_UNIQUE_DOCUMENT_INDEX(); new_doc_entry = &new_solr_doc; new_doc_entry = (solr_document_t *) pemalloc(sizeof(solr_document_t), SOLR_DOCUMENT_PERSISTENT); memset(&new_solr_doc, 0, sizeof(solr_document_t)); /* Retrieve the document entry for the original SolrDocument */ if (solr_fetch_document_entry(objptr, &old_doc_entry TSRMLS_CC) == FAILURE) { return ; } /* Duplicate the doc_entry contents */ memcpy(new_doc_entry, old_doc_entry, sizeof(solr_document_t)); /* Override the document index with a new one and create a new HashTable */ new_doc_entry->document_index = document_index; /* Allocate new memory for the fields HashTable, using fast cache for HashTables */ ALLOC_HASHTABLE(new_doc_entry->fields); ALLOC_HASHTABLE(new_doc_entry->children); /* Initializing the hash table used for storing fields in this SolrDocument */ zend_hash_init(new_doc_entry->fields, old_doc_entry->fields->nTableSize, NULL, (dtor_func_t) solr_destroy_field_list_ht_dtor, SOLR_DOCUMENT_FIELD_PERSISTENT); zend_hash_init(new_doc_entry->children, old_doc_entry->children->nTableSize, NULL, ZVAL_PTR_DTOR, SOLR_DOCUMENT_FIELD_PERSISTENT); /* Copy the contents of the old fields HashTable to the new SolrDocument */ zend_hash_copy(new_doc_entry->fields, old_doc_entry->fields, (copy_ctor_func_t) field_copy_constructor); zend_hash_copy(new_doc_entry->children, old_doc_entry->children, (copy_ctor_func_t) zval_add_ref); /* Add the document entry to the directory of documents */ zend_hash_index_update_ptr(SOLR_GLOBAL(documents), document_index, (void *) new_doc_entry); /* Set the value of the internal id property */ zend_update_property_long(solr_ce_SolrInputDocument, objptr, SOLR_INDEX_PROPERTY_NAME, sizeof(SOLR_INDEX_PROPERTY_NAME) - 1, document_index TSRMLS_CC); /* Keep track of how many SolrDocument instances we currently have */ SOLR_GLOBAL(document_count)++; }