[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] com =?UTF-8?Q?pecl/search=5Fengine/solr=3A=20Fix=20SolrInputDocument=3A?= =?UTF-8?Q?=3Aad
From:       Omar Shaban <omars () php ! net>
Date:       2015-11-30 13:12:48
Message-ID: php-mail-43ae7d0e08afcd4d24dd6d3dfc3e18a61103047949 () git ! php ! net
[Download RAW message or body]

Commit:    0d703a59efd809f9c2192aa75777f796f876737d
Author:    Omar Shaban <omars@php.net>         Mon, 30 Nov 2015 15:12:48 +0200
Parents:   ed5012e07f5a88493d4d567da673a4e72eb34c0b
Branches:  master

Link:       http://git.php.net/?p=pecl/search_engine/solr.git;a=commitdiff;h=0d703a59efd809f9c2192aa75777f796f876737d


Log:
Fix SolrInputDocument::addChildDocument

Changed paths:
  M  php_solr_input_document.c
  A  tests/050.solrinputdocument_addchilddocument_02_error.phpt
  A  tests/054.solrinputdocument_addchilddocuments.phpt


Diff:
diff --git a/php_solr_input_document.c b/php_solr_input_document.c
index ce76003..88f7d14 100644
--- a/php_solr_input_document.c
+++ b/php_solr_input_document.c
@@ -746,24 +746,27 @@ PHP_METHOD(SolrInputDocument, merge)
 PHP_METHOD(SolrInputDocument, addChildDocument)
 {
     zval *child_obj = NULL;
-    solr_document_t *solr_doc = NULL;
-    HashTable * document_fields = NULL;
+    solr_document_t *solr_doc = NULL, *child_doc_entry = NULL;
 
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &child_obj, \
solr_ce_SolrInputDocument) == FAILURE)  {
         RETURN_FALSE;
     }
 
-    if (solr_fetch_document_entry(child_obj, &solr_doc TSRMLS_CC) == FAILURE)
+    if (solr_fetch_document_entry(getThis(), &solr_doc TSRMLS_CC) == FAILURE)
     {
-        solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_4000 TSRMLS_CC, \
SOLR_FILE_LINE_FUNC, "Internal Error: Unable to fetch document_entry."); +        \
solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_1008 TSRMLS_CC, \
SOLR_FILE_LINE_FUNC, "Internal Error: Unable to fetch document_entry.");  return;
     }
 
-    document_fields = solr_doc->fields;
+    if (solr_fetch_document_entry(child_obj, &child_doc_entry TSRMLS_CC) == FAILURE)
+    {
+        solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_1008 TSRMLS_CC, \
SOLR_FILE_LINE_FUNC, "Internal Error: Unable to fetch document_entry for child \
document."); +        return;
+    }
 
     /* SolrInputDocument must contain at least one field */
-    if (0 == zend_hash_num_elements(document_fields)) {
+    if (0 == zend_hash_num_elements(child_doc_entry->fields)) {
         solr_throw_exception_ex(solr_ce_SolrIllegalArgumentException, \
SOLR_ERROR_4000 TSRMLS_CC, SOLR_FILE_LINE_FUNC, "Child document has no fields");  \
return;  }
@@ -794,7 +797,7 @@ PHP_METHOD(SolrInputDocument, addChildDocuments)
 
     if (solr_fetch_document_entry(getThis(), &solr_doc TSRMLS_CC) == FAILURE)
     {
-        solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_4000 TSRMLS_CC, \
SOLR_FILE_LINE_FUNC, "Internal Error: Unable to fetch document_entry."); +        \
solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_1008 TSRMLS_CC, \
SOLR_FILE_LINE_FUNC, "Internal Error: Unable to fetch document_entry.");  }
 
     solr_input_docs = Z_ARRVAL_P(docs_array);
diff --git a/tests/050.solrinputdocument_addchilddocument_02_error.phpt \
b/tests/050.solrinputdocument_addchilddocument_02_error.phpt new file mode 100644
index 0000000..762e5a0
--- /dev/null
+++ b/tests/050.solrinputdocument_addchilddocument_02_error.phpt
@@ -0,0 +1,32 @@
+--TEST--
+SolrInputDocument::addChildDocument()/SolrInputDocument::addChildDocuments() - \
Expected SolrIllegalArgumentException +--FILE--
+<?php
+
+require_once "bootstrap.inc";
+
+$doc = new SolrInputDocument();
+
+$child1 = new SolrInputDocument();
+$child2 = new SolrInputDocument();
+
+$doc->addField('id', 1123);
+$doc->addField('features', "PHP Client Side");
+$doc->addField('features', "Fast development cycles");
+$doc->cat   = 'Information Technology';
+try {
+	$doc->addChildDocument($child1);
+} catch (SolrIllegalArgumentException $e) {
+	echo $e->getMessage(). PHP_EOL;
+}
+
+$children = [$child1, $child2];
+try {
+	$doc->addChildDocuments($children);
+} catch (SolrIllegalArgumentException $e) {
+	echo $e->getMessage(). PHP_EOL;
+}
+?>
+--EXPECT--
+Child document has no fields
+SolrInputDocument number 1 has no fields
\ No newline at end of file
diff --git a/tests/054.solrinputdocument_addchilddocuments.phpt \
b/tests/054.solrinputdocument_addchilddocuments.phpt new file mode 100644
index 0000000..ba795b4
--- /dev/null
+++ b/tests/054.solrinputdocument_addchilddocuments.phpt
@@ -0,0 +1,32 @@
+--TEST--
+SolrInputDocument::addChildDocuments() - add child documents
+--FILE--
+<?php
+
+require_once "bootstrap.inc";
+
+$doc = new SolrInputDocument();
+
+$doc2 = new SolrInputDocument();
+$doc3 = new SolrInputDocument();
+
+$doc->addField('id', 1123);
+$doc->addField('features', "PHP Client Side");
+$doc->addField('features', "Fast development cycles");
+$doc->cat   = 'Information Technology';
+
+$doc2->addField('cat', 'Lucene Search');
+$doc2->cat = 'Custom Search';
+
+$doc2->addField('cat', 'Lucene Search');
+$doc2->cat = 'Custom Search';
+
+$doc3->addField('cat', 'Lucene Search');
+$doc3->cat = 'Custom Search';
+$docs = [$doc2, $doc3];
+$doc->addChildDocuments($docs);
+
+var_dump($doc->getChildDocumentsCount());
+?>
+--EXPECT--
+int(2)
\ No newline at end of file


--
PECL CVS Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic