1================================================================================ 2Introducing the Solr PHP Extension 3================================================================================ 4The Solr extension is an extremely fast, light-weight, feature-rich library that 5allows PHP developers to communicate effectively with Solr server instances. 6 7There are tools to add documents and make updates to the solr server. 8 9It also contains tools that allows you to build advanced queries to the server 10when searching for documents. 11 12There are also special objects that simplifies the sending of name-value requests 13to the server. This includes the SolrParams class and all its child classes. 14 15The SolrClient object allows one to communicate with Solr containers that are 16behind proxy servers or that require HTTP Authentication to proceed. 17 18The SolrClient constructor accepts options such as 19http authentication username and passwor, proxy server name, port, login and 20passwords etc. 21 22Using an advanced http client like libcurl allows us to leverage the features 23available with the library. We can reuse the HTTP connections without having 24to create a separate one for each request. 25 26================================================================================ 27How to Install 28================================================================================ 29 30Please refer to the README.INSTALLATION file. 31 32================================================================================ 33Magic Methods and Interfaces Implemented 34================================================================================ 35 36SolrDocument implements the following interfaces. 37 38(1) ArrayAccess - to access the fields as array keys using field names. 39(2) Iterator - to iterate over the document fields using foreach() 40(3) Serializable - provides custom serialization of the object. 41 42SolrDocument also contains the __get and __set magic methods which allows developers 43to access the fields directly. When setting fields, if the field already 44has a value the new value will be appended to the list of values for that field. 45 46Each field is a SolrDocumentField object with the following public properties : 47 48(a) name - a string with name of the field. 49(b) boost - a double representing the boost value of the field (intentionally empty) 50(c) values - an array of all the field values as strings. 51 52Custom Serialization 53 54string SolrDocument::serialize(void) returns an XML document representing a 55SolrDocument as shown below : 56 57<?xml version="1.0" encoding="UTF-8"?> 58<solr_document> 59 <fields> 60 <field name="id"> 61 <field_value>A0F43D</field_value> 62 </field> 63 <field name="name"> 64 <field_value>Israel Ekpo</field_value> 65 </field> 66 <field name="email"> 67 <field_value>Israel.Ekpo@israel.ekpo.com</field_value> 68 </field> 69 <field name="skills"> 70 <field_value>Reading</field_value> 71 <field_value>Writing</field_value> 72 <field_value>Soccer</field_value> 73 <field_value>Teaching</field_value> 74 </field> 75 <field name="languages"> 76 <field_value>Inglés</field_value> 77 <field_value>Espanól</field_value> 78 </field> 79 </fields> 80</solr_document> 81 82Here is a complete example of a serialized SolrDocument object: 83 84C:12:"SolrDocument":679:{<?xml version="1.0" encoding="UTF-8"?> 85<solr_document> 86 <fields> 87 <field name="id"> 88 <field_value>A0F43D</field_value> 89 </field> 90 <field name="name"> 91 <field_value>Israel Ekpo</field_value> 92 </field> 93 <field name="email"> 94 <field_value>Israel.Ekpo@israel.ekpo.com</field_value> 95 </field> 96 <field name="skills"> 97 <field_value>Reading</field_value> 98 <field_value>Writing</field_value> 99 <field_value>Soccer</field_value> 100 <field_value>Teaching</field_value> 101 </field> 102 <field name="languages"> 103 <field_value>Inglés</field_value> 104 <field_value>Espanól</field_value> 105 </field> 106 </fields> 107</solr_document> 108} 109 110One of the items on my todo list is to create a response writer to return 111serialized SolrDocument objects instead of document arrays. 112 113SolrDocument::unserialize(string $serialized) accepts an XML document 114representing the SolrDocument object. It will the bring the object back to live. 115 116The SolrDocument class also has the method SolrDocument::getInputDocument() to 117allow one do get the SolrInputDocument version of a SolrDocument instance. 118 119This method may be helpful if one needs to resubmit the document to the server to 120updates. 121 122The Solr extension has the SolrQuery object (a child of SolrParams) that enables 123the developer to send custom advanced name-value requests to the solr server. 124 125The SolrQuery object can also be serialized and reused later, which makes it very 126helpful to saving the state of the application across multiple requests. This may be 127very useful in cases such as facet browsing where additional parameters may need to be 128added to the current object or removed from it to get the desired results without 129having to start over from scratch. 130 131================================================================================ 132Parsing of XML Responses from the Solr Server 133================================================================================ 134XML responses from the solr server are expected to be formatted using version 2.2 135These xml documents are parsed into serialized php code and returned as 136read-only SolrObject instances whose properties can also be accessed as array 137keys in addition to being accessible directly via the object->member notation. 138 139Having the properties accessible via object[member] notation is helpful in cases 140where the property name is not valid (contains dots and other characters not 141legal in php. 142 143================================================================================ 144How to Report Bugs 145================================================================================ 146 147Please report bugs to http://bugs.php.net 148 149If you experience a crash due to a segmentation fault, please follow the instructions on the link below 150to get a gdb backtrace and then submit the trace in your bug report as well 151 152http://bugs.php.net/bugs-generating-backtrace.php 153 154Thank you for using PHP 155