As you already know, Solr has an API exposed as an HTTP interface. With the use of several provided response writers, we can use virtually any language to connect to Solr, send a query, and fetch the results. In the following recipe, I'll show you how to prepare Solr to use it with PHP, and how to use the PHP language to fetch data from Solr.
To illustrate how to use Solr within a PHP application, I decided to use SolrPHPClient
written by Donovan Jimenez. This can be found at the following address: http://code.google.com/p/solr-php-client/downloads/list
Let's start with the schema.xml
file. We will only need two fields. So the field definition part of the file should look like this:
<field name="id" type="string" indexed="true" stored="true" required="true" /> <field name="name" type="text" indexed="true" stored="true" />
Now let's index some data by running the following PHP file:
<?php require_once 'Apache/Solr/Service.php'; ...