[ https://issues.apache.org/jira/browse/SOLR-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12647555#action_12647555 ]
richr edited comment on SOLR-341 at 11/14/08 1:45 AM: ------------------------------------------------------- Hi I've encountered an issue in the _documentToXmlFragment() method of the Apache_Solr_Service class. To cut a long story short, I'm building up documents from database rows, some of which contain NULL values. I've noticed that NULL values interfere with the following (Iterator-based) code in the above method: foreach ($document as $key => $value) { ... - what basically happens is that a NULL $value seems to cause the foreach loop to terminate prematurely. Any fields 'beyond' that with the NULL value do not get added to the index. The very simple workaround for this was to replace the above code fragment with the following: $keys = $document->getFieldNames(); foreach ($keys as $key) { $value = $document->$key; ... As you can see, it's essentially the same, and fully backwards-compatible. It just avoids the issue I've been experiencing with the iterator. I'd really like to see this change make it to the code if possible (I can submit a patch if necessary). For reference, I'm using PHP 5.3 on OSX. Best regards Rich was (Author: richr): Hi I've encountered an issue in the _documentToXmlFragment() method of the Apache_Solr_Service class. To cut a long story short, I'm building up documents from database rows, some of which contain NULL values. I've noticed that NULL values interfere with the following (Iterator-based) code: foreach ($document as $key => $value) { ... - what basically happens is that a NULL $value seems to cause the foreach loop to terminate prematurely. Any fields 'beyond' that with the NULL value do not get added to the index. The very simple workaround for this was to replace the above code fragment with the following: $keys = $document->getFieldNames(); foreach ($keys as $key) { $value = $document->$key; ... As you can see, it's essentially the same, and fully backwards-compatible. It just avoids the issue I've been experiencing with the iterator. I'd really like to see this change make it to the code if possible (I can submit a patch if necessary). For reference, I'm using PHP 5.3 on OSX. Best regards Rich > PHP Solr Client > --------------- > > Key: SOLR-341 > URL: https://issues.apache.org/jira/browse/SOLR-341 > Project: Solr > Issue Type: New Feature > Components: clients - php > Affects Versions: 1.2 > Environment: PHP >= 5.2.0 (or older with JSON PECL extension or other > json_decode function implementation). Solr >= 1.2 > Reporter: Donovan Jimenez > Priority: Trivial > Fix For: 1.4 > > Attachments: SolrPhpClient.2008-09-02.zip, SolrPhpClient.zip > > > Developed this client when the example PHP source didn't meet our needs. The > company I work for agreed to release it under the terms of the Apache License. > This version is slightly different from what I originally linked to on the > dev mailing list. I've incorporated feedback from Yonik and "hossman" to > simplify the client and only accept one response format (JSON currently). > When Solr 1.3 is released the client can be updated to use the PHP or > Serialized PHP response writer. > example usage from my original mailing list post: > <?php > require_once('Solr/Service.php'); > $start = microtime(true); > $solr = new Solr_Service(); //Or explicitly new Solr_Service('localhost', > 8180, '/solr'); > try > { > $response = $solr->search('solr', 0, 10, > array(/* you can include other parameters here */)); > echo 'search returned with status = ', > $response->responseHeader->status, > ' and took ', microtime(true) - $start, ' seconds', "\n"; > //here's how you would access results > //Notice that I've mapped the values by name into a tree of stdClass > objects > //and arrays (actually, most of this is done by json_decode ) > if ($response->response->numFound > 0) > { > $doc_number = $response->response->start; > foreach ($response->response->docs as $doc) > { > $doc_number++; > echo $doc_number, ': ', $doc->text, "\n"; > } > } > //for the purposes of seeing the available structure of the response > //NOTE: Solr_Response::_parsedData is lazy loaded, so a print_r on > the response before > //any values are accessed may result in different behavior (in case > //anyone has some troubles debugging) > //print_r($response); > } > catch (Exception $e) > { > echo $e->getMessage(), "\n"; > } > ?> -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.