There's also my Solr module for Drupal: <http://drupal.org/project/solr>
- not sure if that's been mentioned here before.
Looking forward to trying the PHP-serialised response writer.
alf.
Pieter Berkel wrote:
Hi Donovan,
This sounds very promising, I've also recently been working on a php solr
client library for use within my organization but the code is not well
documented nor licensed appropriately just yet. You may note that
eval()-able and serialized php response writers were recently added to svn
trunk (see http://issues.apache.org/jira/browse/SOLR-196 ) so it may be more
efficient to use these rather than converting XML / JSON formatted data.
In terms of licensing, I'm not sure if the new BSD license is compatible
with the Apache 2.0 license (see:
http://www.apache.org/licenses/LICENSE-2.0) that Solr is released
under, this would only be an issue if your php
client was to be included in the Solr distribution (which would be useful
but not manditory).
I'd be interested to take a look at your client library code, are you
planning to release it soon?
regards,
Piete
On 17/08/07, Donovan Jimenez <[EMAIL PROTECTED]> wrote:
The company I work for recently started using Solr for some of our
search functionality. After downloading the files for integrating
with PHP that the Wiki links to I saw that it wasn't usable for our
purposes. So, as part of the project, I developed a PHP Solr Client.
Coming back to the mailing list I see that there was recent talk
about developing a new PHP client, but as of yet I haven't seen it
posted - so I hope I'm not stepping on any toes. I received
permission from my company to release the code to the community under
the new BSD license. The coding style is approximately inline with
the Zend Framework's standards (and somewhat PEAR's) and I feel it's
well documented.
Client Requirements:
- PHP 5 >= 5.2.0 (we developed on 5.2.1) that has the json_decode
function (available by default as of 5.2) and the XmlReader class
(enabled by default as of 5.1)
- allow_url_fopen php.ini setting must be enabled (defaults to
enabled)
We'd love to have the community help us maintain this as Solr
evolves. Let us know what you think. Thanks.
- Donovan Jimenez
For those interested:
The starting point is the Solr_Service class. From this class you
have access to all the major functionality of the Solr HTTP service
(add, delete by id, delete by query, commit, optimize and search).
Below I've include a sample of the client's API for searching:
<?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 the response is
//in json format - done by an XmlReader loop if its XML)
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";
}
?>