- Notifications
You must be signed in to change notification settings - Fork16
GitHub fork for the PHP PECL Solr extension (until the project lead becomes responsive)
License
NotificationsYou must be signed in to change notification settings
Fyb3roptik/php-pecl-solr
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
================================================================================Introducing the Solr PHP Extension================================================================================The Solr extension is an extremely fast, light-weight, feature-rich library that allows PHP developers to communicate effectively with Solr server instances.There are tools to add documents and make updates to the solr server.It also contains tools that allows you to build advanced queries to the serverwhen searching for documents.There are also special objects that simplifies the sending of name-value requeststo the server. This includes the SolrParams class and all its child classes.The SolrClient object allows one to communicate with Solr containers that are behind proxy servers or that require HTTP Authentication to proceed.The SolrClient constructor accepts options such ashttp authentication username and passwor, proxy server name, port, login and passwords etc.Using an advanced http client like libcurl allows us to leverage the featuresavailable with the library. We can reuse the HTTP connections without having to create a separate one for each request.================================================================================How to Install================================================================================Please refer to the README.INSTALLATION file.================================================================================Magic Methods and Interfaces Implemented================================================================================SolrDocument implements the following interfaces.(1) ArrayAccess - to access the fields as array keys using field names.(2) Iterator - to iterate over the document fields using foreach()(3) Serializable - provides custom serialization of the object.SolrDocument also contains the __get and __set magic methods which allows developersto access the fields directly. When setting fields, if the field alreadyhas a value the new value will be appended to the list of values for that field.Each field is a SolrDocumentField object with the following public properties :(a) name - a string with name of the field.(b) boost - a double representing the boost value of the field (intentionally empty)(c) values - an array of all the field values as strings.Custom Serializationstring SolrDocument::serialize(void) returns an XML document representing a SolrDocument as shown below :<?xml version="1.0" encoding="UTF-8"?><solr_document> <fields> <field name="id"> <field_value>A0F43D</field_value> </field> <field name="name"> <field_value>Israel Ekpo</field_value> </field> <field name="email"> <field_value>Israel.Ekpo@israel.ekpo.com</field_value> </field> <field name="skills"> <field_value>Reading</field_value> <field_value>Writing</field_value> <field_value>Soccer</field_value> <field_value>Teaching</field_value> </field> <field name="languages"> <field_value>Inglés</field_value> <field_value>Espanól</field_value> </field> </fields></solr_document>Here is a complete example of a serialized SolrDocument object:C:12:"SolrDocument":679:{<?xml version="1.0" encoding="UTF-8"?><solr_document> <fields> <field name="id"> <field_value>A0F43D</field_value> </field> <field name="name"> <field_value>Israel Ekpo</field_value> </field> <field name="email"> <field_value>Israel.Ekpo@israel.ekpo.com</field_value> </field> <field name="skills"> <field_value>Reading</field_value> <field_value>Writing</field_value> <field_value>Soccer</field_value> <field_value>Teaching</field_value> </field> <field name="languages"> <field_value>Inglés</field_value> <field_value>Espanól</field_value> </field> </fields></solr_document>}One of the items on my todo list is to create a response writer to return serialized SolrDocument objects instead of document arrays.SolrDocument::unserialize(string $serialized) accepts an XML document representing the SolrDocument object. It will the bring the object back to live.The SolrDocument class also has the method SolrDocument::getInputDocument() to allow one do get the SolrInputDocument version of a SolrDocument instance.This method may be helpful if one needs to resubmit the document to the server to updates.The Solr extension has the SolrQuery object (a child of SolrParams) that enablesthe developer to send custom advanced name-value requests to the solr server.The SolrQuery object can also be serialized and reused later, which makes it veryhelpful to saving the state of the application across multiple requests. This may bevery useful in cases such as facet browsing where additional parameters may need to beadded to the current object or removed from it to get the desired results withouthaving to start over from scratch.================================================================================Parsing of XML Responses from the Solr Server================================================================================XML responses from the solr server are expected to be formatted using version 2.2These xml documents are parsed into serialized php code and returned asread-only SolrObject instances whose properties can also be accessed as arraykeys in addition to being accessible directly via the object->member notation.Having the properties accessible via object[member] notation is helpful in caseswhere the property name is not valid (contains dots and other characters not legal in php.================================================================================How to Report Bugs================================================================================Please report bugs to iekpo@php.netIf you experience a crash due to a segmentation fault, please follow the instructions on the link below to get a gdb backtrace and then submit the trace in your bug report as wellhttp://bugs.php.net/bugs-generating-backtrace.phpThank you for using PHP