/* {{{ proto array SolrUtils::getSolrStats(void) Returns the number of active documents, clients and SolrParam objects in the current thread. */ PHP_METHOD(SolrUtils, getSolrStats) { int document_count = zend_hash_num_elements(SOLR_GLOBAL(documents)); int client_count = zend_hash_num_elements(SOLR_GLOBAL(clients)); int params_count = zend_hash_num_elements(SOLR_GLOBAL(params)); array_init(return_value); add_assoc_long(return_value, "document_count", document_count); add_assoc_long(return_value, "client_count", client_count); add_assoc_long(return_value, "params_count", params_count); }
/* {{{ proto void SolrInputDocument::__destruct(void) Destructor for SolrInputDocument */ PHP_METHOD(SolrInputDocument, __destruct) { solr_document_t *doc_entry = NULL; /* Retrieve the document entry for this SolrDocument */ if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS) { zend_hash_index_del(SOLR_GLOBAL(documents), doc_entry->document_index); /* Keep track of how many SolrDocument instances we currently have */ SOLR_GLOBAL(document_count)--; return ; } }
/* {{{ 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)++; }
/* {{{ proto void SolrFunction::__destruct(void) Destructor. */ PHP_METHOD(SolrCollapseFunction, __destruct) { solr_function_t *function = NULL; /* Retrieve the document entry for this SolrDocument */ if (solr_fetch_function_entry(getThis(), &function TSRMLS_CC) == SUCCESS ) { zend_hash_index_del(SOLR_GLOBAL(functions), function->function_index); } return; }
PHP_METHOD(SolrCollapseFunction, __construct) { long int index = SOLR_UNIQUE_FUNCTION_INDEX(); uint nSize = SOLR_INITIAL_HASH_TABLE_SIZE; solr_function_t *solr_function_dest = NULL; solr_function_t solr_function; zval *index_prop, *zvfield = NULL; solr_char_t *param_name = (solr_char_t *)"field"; int param_name_len = sizeof("field"); solr_string_t field_str; solr_char_t *field_name = NULL; int field_name_len = 0; memset(&solr_function, 0, sizeof(solr_function_t)); if (zend_hash_index_update(SOLR_GLOBAL(functions),index,(void *) &solr_function, sizeof(solr_function_t), (void **) &solr_function_dest) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error while registering query parameters in HashTable"); return ; } index_prop = zend_read_property(Z_OBJCE_P(getThis()), getThis(), SOLR_INDEX_PROPERTY_NAME, sizeof(SOLR_INDEX_PROPERTY_NAME) - 1, 1 TSRMLS_CC); Z_LVAL_P(index_prop) = index; solr_function_dest->function_index = index; solr_function_dest->name = (solr_char_t *)"collapse"; solr_function_dest->name_length = sizeof(solr_function_dest->name); /* Allocated memory for the params HashTable using fast cache for HashTables */ ALLOC_HASHTABLE(solr_function_dest->params); zend_hash_init(solr_function_dest->params, nSize, NULL, (dtor_func_t) solr_string_free_ex, SOLR_FUNCTIONS_PERSISTENT); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &field_name, &field_name_len) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error Parsing Parameters"); return; } if (field_name_len > 0 ) { memset(&field_str, 0, sizeof(solr_string_t)); solr_string_set(&field_str, (solr_char_t *)field_name, field_name_len); if(zend_hash_update(solr_function_dest->params, param_name, param_name_len, (void **)&field_str, sizeof(solr_string_t), NULL) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error assigning field"); } } }