Skip to content

Commit

Permalink
Merge branch 'master' of git.php.net:/pecl/search_engine/solr
Browse files Browse the repository at this point in the history
* 'master' of git.php.net:/pecl/search_engine/solr:
  Bug #73671 Zend assertion error in `make test when php 7.1
  Bug #72740: test case
  Fixes Bug #72740: addQueryField return wrong query
  Update news entry
  Implement Request #73031: Enable gzip encoding if server supports it
  refactoring params_t to string
  update NEWS
  Request #72145 	Simple Optimistic Concurrency Support [php5compat]
  Refactoring setVersion + properly destroy doc field
  SolrInputDocument::setVersion test compat
  pecl compat base64, zend_hash_str_del, unserialize
  Fix document version names
  Request #72145 	Simple Optimistic Concurrency Support
  field_copy_constructor fix boost data type
  Fix incorrect boost after document merge
  Fix undefined constant in updateField arg
  Request #71360: Atomic Updates [php5 compat]
  Request #71360: Atomic Updates
  Bug 72033 testcase
  Fix Bug #72033 Real Time Get requests failure
  • Loading branch information
remicollet committed Jun 23, 2017
2 parents 6e9e097 + e1cd59a commit 2ee19ba
Show file tree
Hide file tree
Showing 34 changed files with 1,028 additions and 191 deletions.
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bug #73671: Zend assertion error in `make test` when php 7.1 is built with --enable-debug
Bug #72033: Real Time Get requests fails if it wasn't the first request
Bug #72740: addQueryField return wrong query
Feature #71360: Atomic Update
Feature #72145: Simple Optimistic Concurrency Support
Request #73031: Enable gzip encoding if server supports it

74 changes: 67 additions & 7 deletions docs/documentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
/* $Id$ */

define('SOLR_MAJOR_VERSION', 2);
define('SOLR_MINOR_VERSION', 3);
define('SOLR_MINOR_VERSION', 4);
define('SOLR_PATCH_VERSION', 0);

define('SOLR_EXTENSION_VERSION', '2.3.0');
define('SOLR_EXTENSION_VERSION', '2.4.0');

/**
* Returns the current version of the Apache Solr extension
Expand Down Expand Up @@ -133,6 +133,7 @@ class SolrMissingMandatoryParameterException extends SolrException
/**
*
* @author Israel Ekpo <iekpo@php.net>
* @author Omar Shaban <omars@php.net>
*/
abstract class SolrUtils
{
Expand Down Expand Up @@ -216,6 +217,7 @@ public function __destruct() {}
*
* @link http://docs.php.net/manual/en/class.solrinputdocument.php
* @author Israel Ekpo <iekpo@php.net>
* @author Omar Shaban <omars@php.net>
*/
final class SolrInputDocument
{
Expand Down Expand Up @@ -248,7 +250,52 @@ final class SolrInputDocument
* Sorts the fields by boost value
*/
const SORT_FIELD_BOOST_VALUE = 4 ;


/**
* Adds a new value to a multivalued field
*/
const UPDATE_MODIFIER_ADD = 1;

/**
* Sets a field value
*/
const UPDATE_MODIFIER_SET = 2;

/**
* Increments a field value
*/
const UPDATE_MODIFIER_INC = 3;

/**
* Removes a value from a multivalued field
*/
const UPDATE_MODIFIER_REMOVE = 4;

/**
* Removes values matching a java regular expression
*/
const UPDATE_MODIFIER_REMOVEREGEX = 5;

/**
* Concurrency default
* @var int
*/
const VERSION_ASSERT_NONE = 0;

/**
* Assert that a document does not exist, will fail if the document exists
* @var int
*/
const VERSION_ASSERT_NOT_EXISTS = -1;

/**
* Assert that the document already exists
* if the document does not exist, the updates will be rejected.
*
* @var int
*/
const VERSION_ASSERT_EXISTS = 1;

/**
* Adds a field to the document
*
Expand All @@ -267,10 +314,6 @@ public function addField($fieldName, $fieldValue, $fieldBoostValue = 0.0) {}
*/
public function clear() {}

public function __clone() {}
public function __construct() {}
public function __destruct() {}

/**
* Removes a field from the document
* @param string $fieldName
Expand Down Expand Up @@ -419,6 +462,23 @@ public function getChildDocuments() {}
* @return int
*/
public function getChildDocumentsCount() {}

/**
* Set document version to enable optimistic concurrency mode using self::VERSION_* constants
* or asserting version match
*
* @param int $version
*/
public function setVersion($version) {}

/**
* @return int
*/
public function getVersion() {}

public function __clone() {}
public function __construct() {}
public function __destruct() {}
}

/**
Expand Down
19 changes: 19 additions & 0 deletions pecl-compat/src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef PHP_7

PHPAPI extern zend_string *compat_php_base64_decode(const unsigned char * str, int length)
{
int ret_length = 0L;
unsigned char * return_str = php_base64_decode(str, length, &ret_length);
return zend_string_init(return_str, ret_length, 1);
}

PHPAPI extern int compat_php_var_unserialize(zval *rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC)
{
return php_var_unserialize(&rval, p, max, var_hash TSRMLS_CC);
}

#else
#define compat_php_base64_decode php_base64_decode
#define compat_php_var_unserialize php_var_unserialize
#endif

5 changes: 5 additions & 0 deletions pecl-compat/src/zend_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ static zend_always_inline void *zend_hash_index_find_ptr(const HashTable *ht

/*---------*/

#define zend_hash_str_del(ht, arKey, nKeyLength) zend_hash_del(ht, arKey, nKeyLength)

/*---------*/


static zend_always_inline zend_bool compat_zend_hash_exists(const HashTable *ht
, zend_string *key)
{
Expand Down
14 changes: 13 additions & 1 deletion src/php5/php_solr.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ ZEND_BEGIN_ARG_INFO_EX(SolrInputDocument_addChildDocuments_args, SOLR_ARG_PASS_R
ZEND_ARG_ARRAY_INFO(SOLR_ARG_PASS_BY_REF_TRUE, docs, SOLR_ARG_ALLOW_NULL_FALSE)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(SolrInputDocument_updateField_args, SOLR_ARG_PASS_REMAINING_BY_REF_FALSE, SOLR_METHOD_RETURN_REFERENCE_TRUE, 3)
ZEND_ARG_INFO(SOLR_ARG_PASS_BY_REF_FALSE, fieldName)
ZEND_ARG_INFO(SOLR_ARG_PASS_BY_REF_FALSE, modifier)
ZEND_ARG_INFO(SOLR_ARG_PASS_BY_REF_FALSE, value)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(SolrInputDocument_setVersion_args, SOLR_ARG_PASS_REMAINING_BY_REF_FALSE, SOLR_METHOD_RETURN_REFERENCE_TRUE, 1)
ZEND_ARG_INFO(SOLR_ARG_PASS_BY_REF_FALSE, version)
ZEND_END_ARG_INFO()
/* }}} */

/* {{{ SolrClient arguments */
Expand Down Expand Up @@ -609,6 +618,7 @@ static zend_function_entry solr_input_document_methods[] = {
PHP_ME(SolrInputDocument, clear, Solr_no_args, ZEND_ACC_PUBLIC)
PHP_MALIAS(SolrInputDocument, reset, clear, Solr_no_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, addField, SolrInputDocument_addField_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, updateField, SolrInputDocument_updateField_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, getFieldBoost, SolrInputDocument_getFieldBoost_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, setFieldBoost, SolrInputDocument_setFieldBoost_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, getFieldNames, Solr_no_args, ZEND_ACC_PUBLIC)
Expand All @@ -624,6 +634,8 @@ static zend_function_entry solr_input_document_methods[] = {
PHP_ME(SolrInputDocument, hasChildDocuments, Solr_no_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, getChildDocumentsCount, Solr_no_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, addChildDocuments, SolrInputDocument_addChildDocuments_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, setVersion, SolrInputDocument_setVersion_args, ZEND_ACC_PUBLIC)
PHP_ME(SolrInputDocument, getVersion, Solr_no_args, ZEND_ACC_PUBLIC)
PHP_FE_END
};
/* }}} */
Expand Down Expand Up @@ -1136,7 +1148,7 @@ PHP_MINIT_FUNCTION(solr)
zend_declare_property_long(solr_ce_SolrInputDocument, SOLR_INDEX_PROPERTY_NAME, sizeof(SOLR_INDEX_PROPERTY_NAME) -1, 0L, ZEND_ACC_PRIVATE TSRMLS_CC);

/* Register SolrInputDocument class constants */
solr_document_register_class_constants(solr_ce_SolrInputDocument TSRMLS_CC);
solr_input_document_register_class_constants(solr_ce_SolrInputDocument TSRMLS_CC);

/* Register SolrClient Class */
INIT_CLASS_ENTRY(ce, PHP_SOLR_CLIENT_CLASSNAME, solr_client_methods);
Expand Down
5 changes: 5 additions & 0 deletions src/php5/php_solr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
#include <libxml/xpathInternals.h>
#include <libxml/xmlstring.h>

#include <pecl-compat/compat.h>

extern zend_module_entry solr_module_entry;

#define phpext_solr_ptr &solr_module_entry
Expand Down Expand Up @@ -231,6 +233,7 @@ PHP_METHOD(SolrInputDocument, setBoost);
PHP_METHOD(SolrInputDocument, getBoost);
PHP_METHOD(SolrInputDocument, clear);
PHP_METHOD(SolrInputDocument, addField);
PHP_METHOD(SolrInputDocument, updateField);
PHP_METHOD(SolrInputDocument, setFieldBoost);
PHP_METHOD(SolrInputDocument, getFieldBoost);
PHP_METHOD(SolrInputDocument, getFieldNames);
Expand All @@ -246,6 +249,8 @@ PHP_METHOD(SolrInputDocument, getChildDocuments);
PHP_METHOD(SolrInputDocument, hasChildDocuments);
PHP_METHOD(SolrInputDocument, getChildDocumentsCount);
PHP_METHOD(SolrInputDocument, addChildDocuments);
PHP_METHOD(SolrInputDocument, setVersion);
PHP_METHOD(SolrInputDocument, getVersion);
/* }}} */

/* {{{ SolrClient methods declarations */
Expand Down
4 changes: 2 additions & 2 deletions src/php5/php_solr_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ PHP_METHOD(SolrClient, getById)
solr_string_appends(&query_string, "id=", sizeof("id=")-1);
solr_string_appends(&query_string, id, id_len);

solr_string_append_solr_string(&(client->handle.request_body.buffer), &query_string);
solr_string_set_ex(&(client->handle.request_body.buffer), query_string.str, query_string.len);
if (solr_make_request(client, SOLR_REQUEST_GET TSRMLS_CC) == FAILURE)
{
/* if there was an error with the http request solr_make_request throws an exception by itself
Expand Down Expand Up @@ -1374,7 +1374,7 @@ PHP_METHOD(SolrClient, getByIds)
}
solr_string_remove_last_char(&query_string);

solr_string_append_solr_string(&(client->handle.request_body.buffer), &query_string);
solr_string_set_ex(&(client->handle.request_body.buffer), query_string.str, query_string.len);
if (solr_make_request(client, SOLR_REQUEST_GET TSRMLS_CC) == FAILURE)
{
/* if there was an error with the http request solr_make_request throws an exception by itself
Expand Down
123 changes: 123 additions & 0 deletions src/php5/php_solr_input_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,66 @@ PHP_METHOD(SolrInputDocument, addField)
}
/* }}} */

/* {{{ proto bool SolrInputDocument::updateField(string fieldName, int modifier, string value) */
PHP_METHOD(SolrInputDocument, updateField)
{
solr_char_t *field_name = NULL, *field_value = NULL;
COMPAT_ARG_SIZE_T field_name_length = 0, field_value_len = 0;
solr_document_t *doc_entry;
solr_field_list_t *field;
uint field_exists = 0;

long modifier = 0L;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &field_name, &field_name_length, &modifier, &field_value, &field_value_len) == FAILURE) {
return;
}

if (!field_name_length || !field_value_len) {
RETURN_FALSE;
}

if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == FAILURE) {
return;
}

switch (modifier) {
case SOLR_FIELD_VALUE_MOD_ADD:
case SOLR_FIELD_VALUE_MOD_REMOVE:
case SOLR_FIELD_VALUE_MOD_REMOVEREGEX:
case SOLR_FIELD_VALUE_MOD_SET:
case SOLR_FIELD_VALUE_MOD_INC:
break;

default:
solr_throw_exception_ex(solr_ce_SolrIllegalArgumentException, SOLR_ERROR_4003 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_4003_MSG);
return;
}

if ((field = zend_hash_str_find_ptr(doc_entry->fields, field_name, field_name_length)) == NULL){
field = (solr_field_list_t *)pemalloc(sizeof(solr_field_list_t), SOLR_DOCUMENT_FIELD_PERSISTENT);
memset(field, 0, sizeof(solr_field_list_t));
field->field_name = pestrdup(field_name, SOLR_DOCUMENT_FIELD_PERSISTENT);
field->count = 1;
field->head = NULL;
field->last = NULL;
if (modifier > 0) {
field->modified = 1;
}
doc_entry->field_count++;
if (zend_hash_str_add_ptr(doc_entry->fields, field_name, field_name_length, field) == NULL) {
RETURN_FALSE;
}
} else if (field->modified == 0) {
solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_4004 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_4004_MSG);
RETURN_FALSE;
}


solr_document_insert_field_value(field, field_value, 0.0, modifier);
}

/* }}} */
/* {{{ proto bool SolrInputDocument::setFieldBoost(string fieldname, float boost_value)
Sets the boost for the specified field. */
PHP_METHOD(SolrInputDocument, setFieldBoost)
Expand Down Expand Up @@ -348,6 +408,69 @@ PHP_METHOD(SolrInputDocument, setFieldBoost)
}
/* }}} */

/**
* {{{ proto bool SolrInputDocument::setVersion(int version)
* Enable optimistic concurrency using assertions */
PHP_METHOD(SolrInputDocument, setVersion)
{
long version = 0;
solr_document_t *doc_entry = NULL;
solr_field_list_t *field = NULL;
solr_char_t *field_name = "_version_";
COMPAT_ARG_SIZE_T field_name_length = sizeof("_version_");
char version_str[80];
zend_error_handling error_handling;

zend_replace_error_handling(EH_THROW, solr_ce_SolrIllegalArgumentException, &error_handling TSRMLS_CC);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &version) == FAILURE) {
zend_restore_error_handling(&error_handling TSRMLS_CC);
return;
}
zend_restore_error_handling(&error_handling TSRMLS_CC);

if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == FAILURE) {
return;
}

field = pemalloc(sizeof(solr_field_list_t), SOLR_DOCUMENT_FIELD_PERSISTENT);

field->count = 0L;
field->field_boost = 0.0f;
field->field_name = pestrdup(field_name, SOLR_DOCUMENT_FIELD_PERSISTENT);
field->head = field->last = NULL;

snprintf(version_str, 80, "%ld", version);

solr_document_insert_field_value(field, version_str, 0.0);

if ((zend_hash_str_update_ptr(doc_entry->fields, field_name, field_name_length, field) == NULL )) {
solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_1008 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_1008_MSG);
solr_destroy_field_list(&field);
return;
}

RETURN_TRUE;
}
/* }}} */

/* {{{ proto int SolrInputDocument::getVersion( void ) */
PHP_METHOD(SolrInputDocument, getVersion)
{
solr_document_t *doc_entry = NULL;
solr_char_t *field_name = "_version_";
COMPAT_ARG_SIZE_T field_name_length = sizeof("_version_");
solr_field_list_t *field = NULL;

if (solr_fetch_document_entry(getThis(), &doc_entry TSRMLS_CC) == FAILURE) {
RETURN_NULL();
}
if ((field = zend_hash_str_find_ptr(doc_entry->fields, field_name, field_name_length)) != NULL) {
RETURN_LONG(atol(field->head->field_value));
}
RETURN_NULL();
}
/* }}} */

/* {{{ proto float SolrInputDocument::getFieldBoost(string fieldname)
Returns the boost value for the specified field. */
PHP_METHOD(SolrInputDocument, getFieldBoost)
Expand Down
7 changes: 7 additions & 0 deletions src/php5/solr_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@
#define SOLR_ERROR_4002 4002L
#define SOLR_ERROR_4002_MSG "Return value requested without processing output"

#define SOLR_ERROR_4003 4003L
#define SOLR_ERROR_4003_MSG "Invalid field value modifier."


#define SOLR_ERROR_4004 4004L
#define SOLR_ERROR_4004_MSG "Cannot add and modify the same field."

/* }}} */

/* {{{ UserSpace Errors */
Expand Down

0 comments on commit 2ee19ba

Please sign in to comment.