/* {{{ proto array SolrInputDocument::toArray(void)
   Returns an array representation of the object. */
PHP_METHOD(SolrInputDocument, toArray)
{
	solr_document_t *doc_entry = NULL;
	zval fields_array;

	/* Retrieve the document entry for the SolrDocument instance */
	if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
	{
		HashTable *fields_ht;
		array_init(return_value);
		array_init(&fields_array);
		zend_hash_init(Z_ARRVAL(fields_array), zend_hash_num_elements(doc_entry->fields), NULL, ZVAL_PTR_DTOR, 0);

		add_assoc_double(return_value, "document_boost", doc_entry->document_boost);
		add_assoc_long(return_value,   "field_count", doc_entry->field_count);
		add_assoc_zval(return_value,   "fields", &fields_array);

		fields_ht = doc_entry->fields;

		SOLR_HASHTABLE_FOR_LOOP(fields_ht)
		{
			solr_field_list_t *field = NULL;
			zval current_field;
			zval *current_field_ptr = &current_field;

			field = zend_hash_get_current_data_ptr(fields_ht);
			/* create SolrDocumentField */
			solr_create_document_field_object(field, &current_field_ptr TSRMLS_CC);
			/* create SolrDocumentField to the fields HT */
			add_next_index_zval(&fields_array, current_field_ptr);
		}
		/* We are done */
		return;
	}
Exemple #2
0
/* {{{ static int solr_document_get_field(zval *objptr, zval *return_value, solr_char_t *field_name, int field_name_length TSRMLS_DC) */
static int solr_document_get_field(zval *objptr, zval *return_value, solr_char_t *field_name, int field_name_length TSRMLS_DC)
{
	solr_document_t *doc_entry = NULL;

	if (!field_name_length) {

		return FAILURE;
	}

	/* Retrieve the document entry for the SolrDocument instance */
	if (solr_fetch_document_entry(objptr, &doc_entry TSRMLS_CC) == SUCCESS)
	{
		solr_field_list_t **field_values = NULL;

		if (zend_hash_find(doc_entry->fields, (char *)field_name, field_name_length, (void **) &field_values) == SUCCESS)
		{
			solr_create_document_field_object(*field_values, &return_value TSRMLS_CC);

			/* The field was retrieved, so we're done here */
			return SUCCESS;
		}

		return FAILURE;
	}

	return FAILURE;
}
/* {{{ proto SolrDocumentField SolrInputDocument::getField(string fieldname)
   Returns the requested field. */
PHP_METHOD(SolrInputDocument, getField)
{
	solr_char_t *field_name = NULL;
	COMPAT_ARG_SIZE_T  field_name_length = 0;
	solr_document_t *doc_entry = NULL;
	zend_string *field_str = NULL;

	/* Process the parameters passed to the default constructor */
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &field_name, &field_name_length) == FAILURE) {

		RETURN_FALSE;
	}

	if (!field_name_length) {
		RETURN_FALSE;
	}

	field_str = zend_string_init(field_name, field_name_length, SOLR_DOCUMENT_FIELD_PERSISTENT);

	/* Retrieve the document entry for the SolrDocument instance */
	if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == SUCCESS)
	{
		solr_field_list_t *field_values = NULL;

		if ((field_values = zend_hash_find_ptr(doc_entry->fields, field_str)) != NULL)
		{
			solr_create_document_field_object(field_values, &return_value TSRMLS_CC);
			/* The field was retrieved, so we're done here */
			zend_string_release(field_str);
			return ;
		}
		goto return_false;
	}
return_false:
	zend_string_release(field_str);
	RETURN_FALSE;
}