Generic PHP Client
define("DEFAULT_URL","http://solr.myhost.com:8080/solr/select");
define("DEFAULT_ROWS","15");
define("DEFAULT_FIELDLIST","score,id,title,url,type,created_date,modified_date,icon,logo");
define("DEFAULT_SORT","score desc");
// instantiate a solr class
$s = new solr();
$s->query("google AND microsoft");
/* solr client class definition */
class solr{
public $hostname;
public $queryString;
public $serializedResult;
public $rows;
public $fieldList;
function __construct ($hostname=DEFAULT_URL){
$this->hostname=$hostname;
$this->rows=DEFAULT_ROWS;
$this->fieldList=DEFAULT_FIELDLIST;
}
function query($keywords){
$this->queryString=$this->hostname .
"?q=" . urlencode($keywords) .
"&wt=phps" . "&fl=" . urlencode($this->fieldList) .
"&rows=" . urlencode( $this->rows) .
"&sort=" . urlencode(DEFAULT_SORT) ;
$this->serializedResult = file_get_contents($this->queryString);
$this->result = unserialize($this->serializedResult);
}
function setLimit($rows){
$this->rows = (int)$rows;
}
function setFieldList($fieldList){
$this->fieldList = $fieldList;
}
}