php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59376 SolrResponse unable to parse empty values
Submitted: 2010-08-20 05:14 UTC Modified: 2014-02-16 18:53 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: boyd at textinfo dot nl Assigned: omars (profile)
Status: Closed Package: solr (PECL)
PHP Version: 5.3.2 OS: Win
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: boyd at textinfo dot nl
New email:
PHP Version: OS:

 

 [2010-08-20 05:14 UTC] boyd at textinfo dot nl
Description:
------------
SolrResponse::getReponse() and SolrUtils::digestXmlResponse() are unable to parse a valid Solr xml reponse with an empty (array) value.

<str/> is not accepted
<str></str> is not accepted
<str> </str> is accepted

@see example

Reproduce code:
---------------
<?php
$s = '<?xml version="1.0" encoding="UTF-8"?>
<response>

<lst name="responseHeader">
 <int name="status">0</int>
 <int name="QTime">0</int>

 <lst name="params">
  <str name="fl">author, value</str>
  <str name="indent">on</str>
  <str name="start">0</str>
  <str name="q">myQuery</str>
  <str name="wt">xml</str>
  <str name="rows">10</str>
  <str name="version">2.2</str>
 </lst>
</lst>
<result name="response" numFound="1" start="0">
 <doc>
  <str name="author">Me</str>
  <arr name="value">
  	<str>Some text</str>
	<str/>
  </arr>
 </doc>
</result>
</response>';
$o = \SolrUtils::digestXmlResponse( $s, \SolrResponse::PARSE_SOLR_OBJ );

print_r( $o ); die;
?>

Expected result:
----------------
SolrObject Object
(
    [responseHeader] => SolrObject Object
        (
            [status] => 0
            [QTime] => 0
            [params] => SolrObject Object
                (
                    [fl] => author, value
                    [indent] => on
                    [start] => 0
                    [q] => myQuery
                    [wt] => xml
                    [rows] => 10
                    [version] => 2.2
                )

        )

    [response] => SolrObject Object
        (
            [numFound] => 1
            [start] => 0
            [docs] => Array
                (
                    [0] => SolrObject Object
                        (
                            [author] => Me
                            [value] => Array
                                (
                                    [0] => Some text
                                    [1] =>  
                                )

                        )

                )

        )

)


Actual result:
--------------
500 internal server error

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-14 14:34 UTC] vlad1k at ya dot ru
Looks like it doesn't work with any multiValued fields
 [2012-05-15 11:46 UTC] raphael dot droz+floss at gmail dot com
It happens with empty <doc></doc> too.
 [2012-05-15 12:13 UTC] raphael dot droz+floss at gmail dot com
Q&D workaround :
try {
 $response_array = $response->getResponse();
} catch(SolrException $e) {
 $raw_response = $response->getRawResponse();
 $raw_response = str_replace('<doc></doc>', '', $raw_response);
 $response_array = SolrUtils::digestXmlResponse($raw_response, SolrResponse::PARSE_SOLR_DOC);
}

also note that this bug isn't windows specific
 [2012-05-15 12:23 UTC] boyd at textinfo dot nl
My current workaround:

$empty = ' '; // or use default text
$output = preg_replace(
	'~<str (\w+)="(\w+)"/>~',
	'<str \1="\2">' . $empty . '</str>',
	$response->getRawResponse()
);

This works for any multivalued field and keeps attributes.
You can modify this easily to include empty doc tags
 [2014-02-16 18:53 UTC] omars@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: omars
 [2014-02-16 18:53 UTC] omars@php.net
Seems fixed, tested and produced the actual result
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC