You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-dev@lucene.apache.org by "Donovan Jimenez (JIRA)" <ji...@apache.org> on 2007/10/02 19:13:50 UTC

[jira] Updated: (SOLR-341) PHP Solr Client

     [ https://issues.apache.org/jira/browse/SOLR-341?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Donovan Jimenez updated SOLR-341:
---------------------------------

    Attachment: SolrPhpClient.zip

Updates to the Solr Client:
 - search can now take muliple parameters of the same name, such as when using facets
 - ping now can take a timeout value which acts as a maximum time allowed to wait for a response
 - namespace change to Apache_Solr to avoid confusion with php Solar (unrelated) project
 - Apache_Solr_Document now implements iterator interface, so its fields can be foreach'd
 - Reference implementation of a read from slave / write to master balancer has be added 

> 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
>         Attachments: SolrPhpClient.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.


Re: [jira] Updated: (SOLR-341) PHP Solr Client

Posted by Donovan Jimenez <dj...@conduit-it.com>.
As noted in the comments, you need one of the following:

  - PHP version >= 5.2 (includes the json_decode function by default)
- The JSON module installed through PECL (still requires PHP 5 but  
can work with lesser versions)
- a defined json_decode function alternative, for example, the Zend  
framework has a Zend_Json class with a decode function. You could  
replace the json_decode call with a call to this class, or you could  
take it as an example for defining your own.  I'm sure PEAR has some  
JSON decoding libraries as well.

the client will probably not work without PHP 5 and definitely will  
not work with the json_decode function as you've found out

- Donovan Jimenez

On Oct 4, 2007, at 12:35 AM, Yosvanys Aponte Báez wrote:

> I have this error with your example
> search returned with status =
> Fatal error: Call to undefined function json_decode() in C:\AppServ 
> \www\SolrPhpClient1\Apache\Solr\Response.php on line 195
>
> Can you help me
> -----Mensaje original-----
> De: Donovan Jimenez (JIRA) [mailto:jira@apache.org]
> Enviado el: martes, 02 de octubre de 2007 19:14
> Para: solr-dev@lucene.apache.org
> Asunto: [jira] Updated: (SOLR-341) PHP Solr Client
>
>
>      [ https://issues.apache.org/jira/browse/SOLR-341? 
> page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
>
> Donovan Jimenez updated SOLR-341:
> ---------------------------------
>
>     Attachment: SolrPhpClient.zip
>
> Updates to the Solr Client:
>  - search can now take muliple parameters of the same name, such as  
> when using facets
>  - ping now can take a timeout value which acts as a maximum time  
> allowed to wait for a response
>  - namespace change to Apache_Solr to avoid confusion with php  
> Solar (unrelated) project
>  - Apache_Solr_Document now implements iterator interface, so its  
> fields can be foreach'd
>  - Reference implementation of a read from slave / write to master  
> balancer has be added
>
>> 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
>>         Attachments: SolrPhpClient.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.
>
>
>
>
> Universidad 2008
>
> Del 11 al 15 de febrero del 2008
> Palacio de Convenciones. La Habana. Cuba.
>
> Sitio Web: http://www.universidad2008.cu
>
>
>
>


RE: [jira] Updated: (SOLR-341) PHP Solr Client

Posted by Yosvanys Aponte Báez <ya...@isch.edu.cu>.
I have this error with your example
search returned with status = 
Fatal error: Call to undefined function json_decode() in C:\AppServ\www\SolrPhpClient1\Apache\Solr\Response.php on line 195

Can you help me
-----Mensaje original-----
De: Donovan Jimenez (JIRA) [mailto:jira@apache.org] 
Enviado el: martes, 02 de octubre de 2007 19:14
Para: solr-dev@lucene.apache.org
Asunto: [jira] Updated: (SOLR-341) PHP Solr Client


     [ https://issues.apache.org/jira/browse/SOLR-341?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Donovan Jimenez updated SOLR-341:
---------------------------------

    Attachment: SolrPhpClient.zip

Updates to the Solr Client:
 - search can now take muliple parameters of the same name, such as when using facets
 - ping now can take a timeout value which acts as a maximum time allowed to wait for a response
 - namespace change to Apache_Solr to avoid confusion with php Solar (unrelated) project
 - Apache_Solr_Document now implements iterator interface, so its fields can be foreach'd
 - Reference implementation of a read from slave / write to master balancer has be added 

> 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
>         Attachments: SolrPhpClient.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.




Universidad 2008 

Del 11 al 15 de febrero del 2008
Palacio de Convenciones. La Habana. Cuba.

Sitio Web: http://www.universidad2008.cu