### Eclipse Workspace Patch 1.0
#P lyrics-vu
Index: sites/all/modules/apachesolr/apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.6
diff -u -r1.6 apachesolr_search.module
--- sites/all/modules/apachesolr/apachesolr_search.module 28 Aug 2008 12:46:56 -0000 1.6
+++ sites/all/modules/apachesolr/apachesolr_search.module 5 Sep 2008 08:38:24 -0000
@@ -46,18 +46,72 @@
try {
$params = apachesolr_search_get_params();
- $response = $solr->search($query->get_query(), $params['start'], $params['rows'], $params);
+
+ // Enable spellchecker
+ $search_servlet = null;
+ if(variable_get('apachesolr_spellchecker', false)) {
+
+ //Add new parameter to the search request
+ $params['spellcheck.q'] = $query->get_query();
+ $params['spellcheck'] = 'true';
+
+ //Set the spellchecker component request handler
+ $search_servlet = variable_get('apachesolr_searchservlet', '/spellCheckCompRH');
+
+ }
+
+ //Enable highlighting
+ if(variable_get('apachesolr_solrhighlighting', false)) {
+
+ //Add new parameter to the search request
+ $params['hl'] = 'true';
+ $params['hl.fragsize']= variable_get('apachesolr_textsnippetlength', 100);
+ $params['hl.simple.pre'] = '';
+ $params['hl.simple.post'] = '';
+
+ }
+
+ $response = $solr->search($query->get_query(), $params['start'], $params['rows'], $params, $search_servlet);
+
+ //Get suggestion into an array
+ $suggestionresults = get_object_vars($response->spellcheck->suggestions);
+
+ //If there are any suggestions
+ if($suggestionresults) {
+
+ //Prepage original query and replace wrong words
+ global $suggestions;
+ $suggestions = $query->get_query();
+
+ foreach($suggestionresults as $word => $value) {
+ $suggestions = str_replace($word, $value->suggestion[0], $suggestions);
+ }
+ }
+
apachesolr_has_searched(TRUE);
+
+ //New since json_decode
+ $highlight = $response->highlighting;
+ $response = $response->response;
+
$total = $response->numFound;
// The response is cached so that it is accessible to the blocks and anything
// else that needs it beyond the initial search.
apachesolr_static_response_cache($response);
pager_query("SELECT %d", $params['rows'], 0, NULL, $total);
if ($total > 0) {
- foreach ($response->documents as $doc) {
+ foreach ($response->docs as $doc) {
+
$extra = node_invoke_nodeapi($doc, 'search result');
$extra['score'] = $doc->score;
- $snippet = search_excerpt($keys, $doc->body);
+
+ if(variable_get('apachesolr_solrhighlighting', false)){
+ $snippet = each($highlight);
+ $snippet = $snippet['value']->text[0];
+ }
+ else
+ $snippet = search_excerpt($keys, $doc->body);
+
if (trim($snippet) == '...') {
$snippet = '';
}
@@ -70,6 +124,7 @@
'extra' => $extra,
'score' => $doc->score,
'snippet' => $snippet);
+
}
// Hook to allow modifications of the retrieved results
@@ -102,7 +157,7 @@
'facet' => 'true',
'facet.field' => array('tid', 'type', 'uid', 'language'),
'facet.mincount' => 1,
- 'facet.sort' => 'true'
+ 'facet.sort' => 'true',
);
// Facet limits
@@ -125,3 +180,64 @@
return $params;
}
+
+
+/**
+ * Implementation of hook_form_alter().
+ *
+ * This allows to add spell suggestions
+ */
+function apachesolr_search_form_alter(&$form, $form_state, $form_id) {
+ // Normally a switch is used because you may want to alter more than
+ // one form and it is easy to add a new case for each form.
+ switch ($form_id) {
+ // This is our form ID.
+ case 'search_form':
+
+ global $suggestions;
+
+ if($suggestions) {
+ $item['suggestion'] = array(
+ '#prefix' => '
Documentation is available at Balancer.php
++ Documentation generated on Tue, 02 Sep 2008 10:45:03 -0400 by phpDocumentor 1.4.0 +
+ + Index: sites/all/modules/apachesolr/SolrPhpClient/LICENSE =================================================================== RCS file: sites/all/modules/apachesolr/SolrPhpClient/LICENSE diff -N sites/all/modules/apachesolr/SolrPhpClient/LICENSE --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sites/all/modules/apachesolr/SolrPhpClient/LICENSE 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. Index: sites/all/modules/apachesolr/SolrPhpClient/Apache/Solr/Service/Balancer.php =================================================================== RCS file: sites/all/modules/apachesolr/SolrPhpClient/Apache/Solr/Service/Balancer.php diff -N sites/all/modules/apachesolr/SolrPhpClient/Apache/Solr/Service/Balancer.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sites/all/modules/apachesolr/SolrPhpClient/Apache/Solr/Service/Balancer.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,746 @@ +, Dan Wolfe + */ + +require_once('Apache/Solr/Service.php'); + +/** + * Reference Implementation for using multiple Solr services in a distribution. Functionality + * includes: + * routing of read / write operations + * failover (on selection) for multiple read servers + */ +class Apache_Solr_Service_Balancer +{ + protected $_createDocuments = true; + + protected $_readableServices = array(); + protected $_writeableServices = array(); + + protected $_currentReadService = null; + protected $_currentWriteService = null; + + protected $_readPingTimeout = 2; + protected $_writePingTimeout = 4; + + // Configuration for server selection backoff intervals + protected $_useBackoff = false; // Set to true to use more resillient write server selection + protected $_backoffLimit = 600; // 10 minute default maximum + protected $_backoffEscalation = 2.0; // Rate at which to increase backoff period + protected $_defaultBackoff = 2.0; // Default backoff interval + + /** + * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc. + * + * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead + * + * @param string $value + * @return string + */ + static public function escape($value) + { + return Apache_Solr_Service::escape($value); + } + + /** + * Escape a value meant to be contained in a phrase for special query characters + * + * @param string $value + * @return string + */ + static public function escapePhrase($value) + { + return Apache_Solr_Service::escapePhrase($value); + } + + /** + * Convenience function for creating phrase syntax from a value + * + * @param string $value + * @return string + */ + static public function phrase($value) + { + return Apache_Solr_Service::phrase($value); + } + + /** + * Constructor. Takes arrays of read and write service instances or descriptions + * + * @param array $readableServices + * @param array $writeableServices + */ + public function __construct($readableServices = array(), $writeableServices = array()) + { + //setup readable services + foreach ($readableServices as $service) + { + $this->addReadService($service); + } + + //setup writeable services + foreach ($writeableServices as $service) + { + $this->addWriteService($service); + } + } + + public function setReadPingTimeout($timeout) + { + $this->_readPingTimeout = $timeout; + } + + public function setWritePingTimeout($timeout) + { + $this->_writePingTimeout = $timeout; + } + + public function setUseBackoff($enable) + { + $this->_useBackoff = $enable; + } + + /** + * Generates a service ID + * + * @param string $host + * @param integer $port + * @param string $path + * @return string + */ + protected function _getServiceId($host, $port, $path) + { + return $host . ':' . $port . $path; + } + + /** + * Adds a service instance or service descriptor (if it is already + * not added) + * + * @param mixed $service + * + * @throws Exception If service descriptor is not valid + */ + public function addReadService($service) + { + if ($service instanceof Apache_Solr_Service) + { + $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath()); + + $this->_readableServices[$id] = $service; + } + else if (is_array($service)) + { + if (isset($service['host']) && isset($service['port']) && isset($service['path'])) + { + $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']); + + $this->_readableServices[$id] = $service; + } + else + { + throw new Exception('A Readable Service description array does not have all required elements of host, port, and path'); + } + } + } + + /** + * Removes a service instance or descriptor from the available services + * + * @param mixed $service + * + * @throws Exception If service descriptor is not valid + */ + public function removeReadService($service) + { + $id = ''; + + if ($service instanceof Apache_Solr_Service) + { + $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath()); + } + else if (is_array($service)) + { + if (isset($service['host']) && isset($service['port']) && isset($service['path'])) + { + $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']); + } + else + { + throw new Exception('A Readable Service description array does not have all required elements of host, port, and path'); + } + } + else if (is_string($service)) + { + $id = $service; + } + + if ($id && isset($this->_readableServices[$id])) + { + unset($this->_readableServices[$id]); + } + } + + /** + * Adds a service instance or service descriptor (if it is already + * not added) + * + * @param mixed $service + * + * @throws Exception If service descriptor is not valid + */ + public function addWriteService($service) + { + if ($service instanceof Apache_Solr_Service) + { + $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath()); + + $this->_writeableServices[$id] = $service; + } + else if (is_array($service)) + { + if (isset($service['host']) && isset($service['port']) && isset($service['path'])) + { + $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']); + + $this->_writeableServices[$id] = $service; + } + else + { + throw new Exception('A Writeable Service description array does not have all required elements of host, port, and path'); + } + } + } + + /** + * Removes a service instance or descriptor from the available services + * + * @param mixed $service + * + * @throws Exception If service descriptor is not valid + */ + public function removeWriteService($service) + { + $id = ''; + + if ($service instanceof Apache_Solr_Service) + { + $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath()); + } + else if (is_array($service)) + { + if (isset($service['host']) && isset($service['port']) && isset($service['path'])) + { + $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']); + } + else + { + throw new Exception('A Readable Service description array does not have all required elements of host, port, and path'); + } + } + else if (is_string($service)) + { + $id = $service; + } + + if ($id && isset($this->_writeableServices[$id])) + { + unset($this->_writeableServices[$id]); + } + } + + /** + * Iterate through available read services and select the first with a ping + * that satisfies configured timeout restrictions (or the default) + * + * @return Apache_Solr_Service + * + * @throws Exception If there are no read services that meet requirements + */ + protected function _selectReadService($forceSelect = false) + { + if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect) + { + if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect) + { + // we probably had a communication error, ping the current read service, remove it if it times out + if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false) + { + $this->removeReadService($this->_currentReadService); + } + } + + if (count($this->_readableServices)) + { + // select one of the read services at random + $ids = array_keys($this->_readableServices); + + $id = $ids[rand(0, count($ids) - 1)]; + $service = $this->_readableServices[$id]; + + if (is_array($service)) + { + //convert the array definition to a client object + $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']); + $this->_readableServices[$id] = $service; + } + + $service->setCreateDocuments($this->_createDocuments); + $this->_currentReadService = $id; + } + else + { + throw new Exception('No read services were available'); + } + } + + return $this->_readableServices[$this->_currentReadService]; + } + + /** + * Iterate through available write services and select the first with a ping + * that satisfies configured timeout restrictions (or the default) + * + * @return Apache_Solr_Service + * + * @throws Exception If there are no write services that meet requirements + */ + protected function _selectWriteService($forceSelect = false) + { + if($this->_useBackoff) + { + return $this->_selectWriteServiceSafe($forceSelect); + } + + if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect) + { + if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect) + { + // we probably had a communication error, ping the current read service, remove it if it times out + if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false) + { + $this->removeWriteService($this->_currentWriteService); + } + } + + if (count($this->_writeableServices)) + { + // select one of the read services at random + $ids = array_keys($this->_writeableServices); + + $id = $ids[rand(0, count($ids) - 1)]; + $service = $this->_writeableServices[$id]; + + if (is_array($service)) + { + //convert the array definition to a client object + $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']); + $this->_writeableServices[$id] = $service; + } + + $this->_currentWriteService = $id; + } + else + { + throw new Exception('No write services were available'); + } + } + + return $this->_writeableServices[$this->_currentWriteService]; + } + + /** + * Iterate through available write services and select the first with a ping + * that satisfies configured timeout restrictions (or the default). The + * timeout period will increase until a connection is made or the limit is + * reached. This will allow for increased reliability with heavily loaded + * server(s). + * + * @return Apache_Solr_Service + * + * @throws Exception If there are no write services that meet requirements + */ + + protected function _selectWriteServiceSafe($forceSelect = false) + { + if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect) + { + if (count($this->_writeableServices)) + { + $backoff = $this->_defaultBackoff; + + do { + // select one of the read services at random + $ids = array_keys($this->_writeableServices); + + $id = $ids[rand(0, count($ids) - 1)]; + $service = $this->_writeableServices[$id]; + + if (is_array($service)) + { + //convert the array definition to a client object + $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']); + $this->_writeableServices[$id] = $service; + } + + $this->_currentWriteService = $id; + + $backoff *= $this->_backoffEscalation; + + if($backoff > $this->_backoffLimit) + { + throw new Exception('No write services were available. All timeouts exceeded.'); + } + + } while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false); + } + else + { + throw new Exception('No write services were available'); + } + } + + return $this->_writeableServices[$this->_currentWriteService]; + } + + public function setCreateDocuments($createDocuments) + { + $this->_createDocuments = (bool) $createDocuments; + + if ($this->_currentReadService) + { + $service = $this->_selectReadService(); + $service->setCreateDocuments($createDocuments); + } + } + + public function getCreateDocuments() + { + return $this->_createDocuments; + } + + /** + * Raw Add Method. Takes a raw post body and sends it to the update service. Post body + * should be a complete and well formed "add" xml document. + * + * @param string $rawPost + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function add($rawPost) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->add($rawPost); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Add a Solr Document to the index + * + * @param Apache_Solr_Document $document + * @param boolean $allowDups + * @param boolean $overwritePending + * @param boolean $overwriteCommitted + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->addDocument($document, $allowDups, $overwritePending, $overwriteCommitted); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Add an array of Solr Documents to the index all at once + * + * @param array $documents Should be an array of Apache_Solr_Document instances + * @param boolean $allowDups + * @param boolean $overwritePending + * @param boolean $overwriteCommitted + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->addDocuments($documents, $allowDups, $overwritePending, $overwriteCommitted); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Send a commit command. Will be synchronous unless both wait parameters are set + * to false. + * + * @param boolean $waitFlush + * @param boolean $waitSearcher + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->commit($optimize, $waitFlush, $waitSearcher, $timeout); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be + * a complete and well formed "delete" xml document + * + * @param string $rawPost + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function delete($rawPost) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->delete($rawPost); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Create a delete document based on document ID + * + * @param string $id + * @param boolean $fromPending + * @param boolean $fromCommitted + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function deleteById($id, $fromPending = true, $fromCommitted = true) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->deleteById($id, $fromPending, $fromCommitted); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Create a delete document based on a query and submit it + * + * @param string $rawQuery + * @param boolean $fromPending + * @param boolean $fromCommitted + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->deleteByQuery($rawQuery, $fromPending, $fromCommitted); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Send an optimize command. Will be synchronous unless both wait parameters are set + * to false. + * + * @param boolean $waitFlush + * @param boolean $waitSearcher + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function optimize($waitFlush = true, $waitSearcher = true) + { + $service = $this->_selectWriteService(); + + do + { + try + { + return $service->optimize($waitFlush, $waitSearcher); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectWriteService(true); + } while ($service); + + return false; + } + + /** + * Simple Search interface + * + * @param string $query The raw query string + * @param int $offset The starting offset for result documents + * @param int $limit The maximum number of result documents to return + * @param array $params key / value pairs for query parameters, use arrays for multivalued parameters + * @return Apache_Solr_Response + * + * @throws Exception If an error occurs during the service call + */ + public function search($query, $offset = 0, $limit = 10, $params = array()) + { + $service = $this->_selectReadService(); + + do + { + try + { + return $service->search($query, $offset, $limit, $params); + } + catch (Exception $e) + { + if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR + { + throw $e; + } + } + + $service = $this->_selectReadService(true); + } while ($service); + + return false; + } +} Index: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service.html =================================================================== RCS file: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service.html diff -N sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service.html 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1935 @@ + + + + + +Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.
+Example Usage:
+ Located in /Service.php (line 62) +
+ + + + +Whether Apache_Solr_Response objects should have multivalue fields with only a single value collapsed to appear as a single value would.
+ + + + + + +Whether Apache_Solr_Response objects should create Apache_Solr_Documents in the returned parsed data
+ + + + + + +Server identification strings
+ + + + + + +How NamedLists should be formatted in the output. This specifically effects facet counts. Valid values are Apache_Solr_Service::NAMED_LIST_MAP (default) or Apache_Solr_Service::NAMED_LIST_FLAT.
+ + + + + + +Stream context for posting
+ + + + + + +Query delimiters. Someone might want to be able to change these (to use & instead of & for example), so I've provided them.
+ + + + + + +Constructed servlet full path URLs
+ + + + + + +Keep track of whether our URLs have been constructed
+ + + + + + +Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
+NOTE: inside a phrase fewer characters need escaped, use Apache_Solr_Service::escapePhrase() instead
+ + +Escape a value meant to be contained in a phrase for special query characters
+ + +Convenience function for creating phrase syntax from a value
+ + +Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.
+ + + + +Add a Solr Document to the index
+ + +Add an array of Solr Documents to the index all at once
+ + +Send a commit command. Will be synchronous unless both wait parameters are set to false.
+ + +Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document
+ + + + +Create a delete document based on document ID
+ + +Create a delete document based on a query and submit it
+ + +Get the current state of the collapse single value arrays flag.
+ + +Get the current state of teh create documents flag.
+ + +Get the current setting for named list treatment.
+ + +Constructor. All parameters are optional and will take on default values if not specified.
+ + +Send an optimize command. Will be synchronous unless both wait parameters are set to false.
+ + +Call the /admin/ping servlet, can be used to quickly tell if a connection to the server is able to be made.
+ + +Simple Search interface
+ + +Set the collapse single value arrays flag.
+ + +Set the create documents flag. This determines whether Apache_Solr_Response objects will parse the response and create Apache_Solr_Document instances in place.
+ + +Set the host used. If empty will fallback to constants
+ + +Set how NamedLists should be formatted in the response data. This mainly effects the facet counts format.
+ + +Set the path used. If empty will fallback to constants
+ + +Set the port used. If empty will fallback to constants
+ + +Set the string used to separate the path form the query string.
+Defaulted to '?'
+ + +Set the string used to separate the parameters in thequery string Defaulted to '&'
+ + +Call the /admin/threads servlet and retrieve information about all threads in the Solr servlet's thread group. Useful for diagnostics.
+ + +Return a valid http URL given this server's host, port and path and a provided servlet name
+ + +Create an XML fragment from a Apache_Solr_Document instance appropriate for use inside a Solr add call
+ + + + +Construct the Full URLs for the three servlets we reference
+ + +Central method for making a get operation against this Solr Server
+ + + + +Central method for making a post operation against this Solr Server
+ + +
+
+ NAMED_LIST_FLAT
+ = 'flat'
+ (line 79)
+
+ NamedList Treatment constants
+ + +
+
+ NAMED_LIST_MAP
+ = 'map'
+ (line 80)
+
+
+
+ PING_SERVLET
+ = 'admin/ping'
+ (line 85)
+
+ Servlet mappings
+ + +
+
+ SEARCH_SERVLET
+ = 'select'
+ (line 87)
+
+
+
+ SOLR_VERSION
+ = '1.2'
+ (line 67)
+
+ Response version we support
+ + +
+
+ SOLR_WRITER
+ = 'json'
+ (line 74)
+
+ Response writer we support
+ + + +
+
+ THREADS_SERVLET
+ = 'admin/threads'
+ (line 88)
+
+
+
+ UPDATE_SERVLET
+ = 'update'
+ (line 86)
+
+ + Documentation generated on Tue, 02 Sep 2008 10:45:05 -0400 by phpDocumentor 1.4.0 +
+Documentation is available at Document.php
++ Documentation generated on Tue, 02 Sep 2008 10:45:04 -0400 by phpDocumentor 1.4.0 +
+ + Index: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/blank.html =================================================================== RCS file: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/blank.html diff -N sites/all/modules/apachesolr/SolrPhpClient/phpdocs/blank.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sites/all/modules/apachesolr/SolrPhpClient/phpdocs/blank.html 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,13 @@ + + ++ Implements interfaces: +
Holds Key / Value pairs that represent a Solr Document. Field values can be accessed by direct dereferencing such as:
+$document->title = 'Something'; echo $document->title; ... </code>
Additionally, the field values can be iterated with foreach
+ Located in /Document.php (line 42) +
+ + + + +Iterator implementation function, proxies to _fields. Allows usage:
+Get the names of all fields in this document
+ + +Iterator implementation function, proxies to _fields. Allows usage:
+Iterator implementation function, proxies to _fields. Allows usage:
+Iterator implementation function, proxies to _fields. Allows usage:
+Handle the array manipulation for a multi-valued field
+ + +Iterator implementation function, proxies to _fields. Allows usage:
+Magic get for field values
+ + +Magic isset for fields values. Do no call directly. Allows usage:
+Magic set for field values. Multi-valued fields should be set as arrays or instead use the setMultiValue(...) function which will automatically make sure the field is an array.
+ + +Magic unset for field values. Do no call directly. Allows usage:
++ Documentation generated on Tue, 02 Sep 2008 10:45:04 -0400 by phpDocumentor 1.4.0 +
++ Documentation generated on Tue, 02 Sep 2008 10:45:03 -0400 by phpDocumentor 1.4.0 +
+ + Index: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/_Response.php.html =================================================================== RCS file: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/_Response.php.html diff -N sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/_Response.php.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/_Response.php.html 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,67 @@ + + + + + +| Class | +Description | +
|---|---|
| + Apache_Solr_Response + | ++ Represents a Solr response. Parses the raw response into a set of stdClass objects and associative arrays for easy access. + | +
+ Documentation generated on Tue, 02 Sep 2008 10:45:04 -0400 by phpDocumentor 1.4.0 +
+Represents a Solr response. Parses the raw response into a set of stdClass objects and associative arrays for easy access.
+Currently requires json_decode which is bundled with PHP >= 5.2.0, Alternatively can be installed with PECL. Zend Framework also includes a purely PHP solution.
+ ++ Located in /Response.php (line 32) +
+ + + + +Data parsing flags. Determines what extra processing should be done after the data is initially converted to a data structure.
+ + + + + + +Parsed values from the passed in http headers
+ + + + + + +Whether the raw response has been parsed
+ + + + + + +Parsed representation of the data
+ + + + + + +Holds the raw response used in construction
+ + + + + + +Constructor. Takes the raw HTTP response body and the exploded HTTP headers
+ + +Get character encoding of this response. Should usually be utf-8, but just in case
+ + +Get the HTTP status code
+ + +Get the HTTP status message of the response
+ + +Get the raw response as it was given to this object
+ + +Get content type of this Solr response
+ + +Parse the raw response into the parsed_data array for access
+ + +Magic get to expose the parsed data and to lazily load it
+ + ++ Documentation generated on Tue, 02 Sep 2008 10:45:04 -0400 by phpDocumentor 1.4.0 +
+| Class | +Description | +
|---|---|
| + Apache_Solr_Document + | ++ Holds Key / Value pairs that represent a Solr Document. Field values can be accessed by direct dereferencing such as: + | +
+ Documentation generated on Tue, 02 Sep 2008 10:45:04 -0400 by phpDocumentor 1.4.0 +
+Documentation is available at Service.php
++ Documentation generated on Tue, 02 Sep 2008 10:45:05 -0400 by phpDocumentor 1.4.0 +
+ + Index: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service_Balancer.html =================================================================== RCS file: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service_Balancer.html diff -N sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service_Balancer.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/Apache_Solr_Service_Balancer.html 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1364 @@ + + + + + +Reference Implementation for using multiple Solr services in a distribution. Functionality
+includes: routing of read / write operations failover (on selection) for multiple read servers
++ Located in /Service/Balancer.php (line 31) +
+ + + + +Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
+NOTE: inside a phrase fewer characters need escaped, use Apache_Solr_Service::escapePhrase() instead
+ + +Escape a value meant to be contained in a phrase for special query characters
+ + +Convenience function for creating phrase syntax from a value
+ + +Constructor. Takes arrays of read and write service instances or descriptions
+ + +Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.
+ + + + +Add a Solr Document to the index
+ + +Add an array of Solr Documents to the index all at once
+ + +Adds a service instance or service descriptor (if it is already not added)
+ + +Adds a service instance or service descriptor (if it is already not added)
+ + +Send a commit command. Will be synchronous unless both wait parameters are set to false.
+ + +Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be a complete and well formed "delete" xml document
+ + + + +Create a delete document based on document ID
+ + +Create a delete document based on a query and submit it
+ + +Send an optimize command. Will be synchronous unless both wait parameters are set to false.
+ + +Removes a service instance or descriptor from the available services
+ + +Removes a service instance or descriptor from the available services
+ + +Simple Search interface
+ + +Generates a service ID
+ + +Iterate through available read services and select the first with a ping that satisfies configured timeout restrictions (or the default)
+ + + + +Iterate through available write services and select the first with a ping that satisfies configured timeout restrictions (or the default)
+ + + + +Iterate through available write services and select the first with a ping
+that satisfies configured timeout restrictions (or the default). The timeout period will increase until a connection is made or the limit is reached. This will allow for increased reliability with heavily loaded server(s).
+ + + + ++ Documentation generated on Tue, 02 Sep 2008 10:45:03 -0400 by phpDocumentor 1.4.0 +
+
+ * ...
+ * $document->title = 'Something';
+ * echo $document->title;
+ * ...
+ *
+ *
+ * Additionally, the field values can be iterated with foreach
+ *
+ *
+ * foreach ($document as $key => $value)
+ * {
+ * ...
+ * }
+ *
+ */
+class Apache_Solr_Document implements Iterator
+{
+ protected $_fields = array();
+
+ /**
+ * Magic get for field values
+ *
+ * @param string $key
+ * @return mixed
+ */
+ public function __get($key)
+ {
+ return $this->_fields[$key];
+ }
+
+ /**
+ * Magic set for field values. Multi-valued fields should be set as arrays
+ * or instead use the setMultiValue(...) function which will automatically
+ * make sure the field is an array.
+ *
+ * @param string $key
+ * @param mixed $value
+ */
+ public function __set($key, $value)
+ {
+ $this->_fields[$key] = $value;
+ }
+
+ /**
+ * Magic isset for fields values. Do no call directly. Allows usage:
+ *
+ *
+ * isset($document->some_field);
+ *
+ *
+ * @param string $key
+ * @return boolean
+ */
+ public function __isset($key)
+ {
+ return isset($this->_fields[$key]);
+ }
+
+ /**
+ * Magic unset for field values. Do no call directly. Allows usage:
+ *
+ *
+ * unset($document->some_field);
+ *
+ *
+ * @param string $key
+ */
+ public function __unset($key)
+ {
+ unset($this->_fields[$key]);
+ }
+
+ /**
+ * Handle the array manipulation for a multi-valued field
+ *
+ * @param string $key
+ * @param string $value
+ */
+ public function setMultiValue($key, $value)
+ {
+ if (!isset($this->_fields[$key]))
+ {
+ $this->_fields[$key] = array();
+ }
+
+ if (!is_array($this->_fields[$key]))
+ {
+ $this->_fields[$key] = array($this->_fields[$key]);
+ }
+
+ $this->_fields[$key][] = $value;
+ }
+
+ /**
+ * Get the names of all fields in this document
+ *
+ * @return array
+ */
+ public function getFieldNames()
+ {
+ return array_keys($this->_fields);
+ }
+
+ /**
+ * Iterator implementation function, proxies to _fields. Allows usage:
+ *
+ *
+ * foreach ($document as $key => $value)
+ * {
+ * ...
+ * }
+ *
+ */
+ public function rewind() {
+ reset($this->_fields);
+ }
+
+ /**
+ * Iterator implementation function, proxies to _fields. Allows usage:
+ *
+ *
+ * foreach ($document as $key => $value)
+ * {
+ * ...
+ * }
+ *
+ */
+ public function current() {
+ return current($this->_fields);
+ }
+
+ /**
+ * Iterator implementation function, proxies to _fields. Allows usage:
+ *
+ *
+ * foreach ($document as $key => $value)
+ * {
+ * ...
+ * }
+ *
+ */
+ public function key() {
+ return key($this->_fields);
+ }
+
+ /**
+ * Iterator implementation function, proxies to _fields. Allows usage:
+ *
+ *
+ * foreach ($document as $key => $value)
+ * {
+ * ...
+ * }
+ *
+ */
+ public function next() {
+ return next($this->_fields);
+ }
+
+ /**
+ * Iterator implementation function, proxies to _fields. Allows usage:
+ *
+ *
+ * foreach ($document as $key => $value)
+ * {
+ * ...
+ * }
+ *
+ */
+ public function valid() {
+ return current($this->_fields) !== false;
+ }
+}
Index: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/index.html
===================================================================
RCS file: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/index.html
diff -N sites/all/modules/apachesolr/SolrPhpClient/phpdocs/index.html
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ sites/all/modules/apachesolr/SolrPhpClient/phpdocs/index.html 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ * ...
+ * $solr = new Apache_Solr_Service(); //or explicitly new Apache_Solr_Service('localhost', 8180, '/solr')
+ *
+ * if ($solr->ping())
+ * {
+ * $solr->deleteByQuery('*:*'); //deletes ALL documents - be careful :)
+ *
+ * $document = new Apache_Solr_Document();
+ * $document->id = uniqid(); //or something else suitably unique
+ *
+ * $document->title = 'Some Title';
+ * $document->content = 'Some content for this wonderful document. Blah blah blah.';
+ *
+ * $solr->addDocument($document); //if you're going to be adding documents in bulk using addDocuments
+ * //with an array of documents is faster
+ *
+ * $solr->commit(); //commit to see the deletes and the document
+ * $solr->optimize(); //merges multiple segments into one
+ *
+ * //and the one we all care about, search!
+ * //any other common or custom parameters to the request handler can go in the
+ * //optional 4th array argument.
+ * $solr->search('content:blah', 0, 10, array('sort' => 'timestamp desc'));
+ * }
+ * ...
+ *
+ *
+ * @todo Investigate using other HTTP clients other than file_get_contents built-in handler. Could provide performance
+ * improvements when dealing with multiple requests by using HTTP's keep alive functionality
+ */
+class Apache_Solr_Service
+{
+ /**
+ * Response version we support
+ */
+ const SOLR_VERSION = '1.2';
+
+ /**
+ * Response writer we support
+ *
+ * @todo Solr 1.3 release may change this to SerializedPHP or PHP implementation
+ */
+ const SOLR_WRITER = 'json';
+
+ /**
+ * NamedList Treatment constants
+ */
+ const NAMED_LIST_FLAT = 'flat';
+ const NAMED_LIST_MAP = 'map';
+
+ /**
+ * Servlet mappings
+ */
+ const PING_SERVLET = 'admin/ping';
+ const UPDATE_SERVLET = 'update';
+ const SEARCH_SERVLET = 'select';
+ const THREADS_SERVLET = 'admin/threads';
+
+ /**
+ * Server identification strings
+ *
+ * @var string
+ */
+ protected $_host, $_port, $_path;
+
+ /**
+ * Whether {@link Apache_Solr_Response} objects should create {@link Apache_Solr_Document}s in
+ * the returned parsed data
+ *
+ * @var boolean
+ */
+ protected $_createDocuments = true;
+
+ /**
+ * Whether {@link Apache_Solr_Response} objects should have multivalue fields with only a single value
+ * collapsed to appear as a single value would.
+ *
+ * @var boolean
+ */
+ protected $_collapseSingleValueArrays = true;
+
+ /**
+ * How NamedLists should be formatted in the output. This specifically effects facet counts. Valid values
+ * are {@link Apache_Solr_Service::NAMED_LIST_MAP} (default) or {@link Apache_Solr_Service::NAMED_LIST_FLAT}.
+ *
+ * @var string
+ */
+ protected $_namedListTreatment = self::NAMED_LIST_MAP;
+
+ /**
+ * Query delimiters. Someone might want to be able to change
+ * these (to use & instead of & for example), so I've provided them.
+ *
+ * @var string
+ */
+ protected $_queryDelimiter = '?', $_queryStringDelimiter = '&';
+
+ /**
+ * Constructed servlet full path URLs
+ *
+ * @var string
+ */
+ protected $_updateUrl, $_searchUrl, $_threadsUrl;
+
+ /**
+ * Keep track of whether our URLs have been constructed
+ *
+ * @var boolean
+ */
+ protected $_urlsInited = false;
+
+ /**
+ * Stream context for posting
+ *
+ * @var resource
+ */
+ protected $_postContext;
+
+ /**
+ * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
+ *
+ * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
+ *
+ * @param string $value
+ * @return string
+ */
+ static public function escape($value)
+ {
+ //list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
+ $pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
+ $replace = '\\\$1';
+
+ return preg_replace($pattern, $replace, $value);
+ }
+
+ /**
+ * Escape a value meant to be contained in a phrase for special query characters
+ *
+ * @param string $value
+ * @return string
+ */
+ static public function escapePhrase($value)
+ {
+ $pattern = '/("|\\\)/';
+ $replace = '\\\$1';
+
+ return preg_replace($pattern, $replace, $value);
+ }
+
+ /**
+ * Convenience function for creating phrase syntax from a value
+ *
+ * @param string $value
+ * @return string
+ */
+ static public function phrase($value)
+ {
+ return '"' . self::escapePhrase($value) . '"';
+ }
+
+ /**
+ * Constructor. All parameters are optional and will take on default values
+ * if not specified.
+ *
+ * @param string $host
+ * @param string $port
+ * @param string $path
+ */
+ public function __construct($host = 'localhost', $port = 8180, $path = '/solr/')
+ {
+ $this->setHost($host);
+ $this->setPort($port);
+ $this->setPath($path);
+
+ $this->_initUrls();
+
+ //set up the stream context for posting with file_get_contents
+ $contextOpts = array(
+ 'http' => array(
+ 'method' => 'POST',
+ 'header' => "Content-Type: text/xml; charset=UTF-8\r\n" //php.net example showed \r\n at the end
+ )
+ );
+
+ $this->_postContext = stream_context_create($contextOpts);
+ }
+
+ /**
+ * Return a valid http URL given this server's host, port and path and a provided servlet name
+ *
+ * @param string $servlet
+ * @return string
+ */
+ protected function _constructUrl($servlet, $params = array())
+ {
+ if (count($params))
+ {
+ //escape all parameters appropriately for inclusion in the query string
+ $escapedParams = array();
+
+ foreach ($params as $key => $value)
+ {
+ $escapedParams[] = urlencode($key) . '=' . urlencode($value);
+ }
+
+ $queryString = $this->_queryDelimiter . implode($this->_queryStringDelimiter, $escapedParams);
+ }
+ else
+ {
+ $queryString = '';
+ }
+
+ return 'http://' . $this->_host . ':' . $this->_port . $this->_path . $servlet . $queryString;
+ }
+
+ /**
+ * Construct the Full URLs for the three servlets we reference
+ */
+ protected function _initUrls()
+ {
+ //Initialize our full servlet URLs now that we have server information
+ $this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array('wt' => self::SOLR_WRITER ));
+ $this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET);
+ $this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array('wt' => self::SOLR_WRITER ));
+
+ $this->_urlsInited = true;
+ }
+
+ /**
+ * Central method for making a get operation against this Solr Server
+ *
+ * @param string $url
+ * @param float $timeout Read timeout in seconds
+ * @return Apache_Solr_Response
+ *
+ * @todo implement timeout ability
+ * @throws Exception If a non 200 response status is returned
+ */
+ protected function _sendRawGet($url, $timeout = FALSE)
+ {
+ //$http_response_header is set by file_get_contents
+ $response = new Apache_Solr_Response(@file_get_contents($url), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
+
+ if ($response->getHttpStatus() != 200)
+ {
+ throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus());
+ }
+
+ return $response;
+ }
+
+ /**
+ * Central method for making a post operation against this Solr Server
+ *
+ * @param string $url
+ * @param string $rawPost
+ * @param float $timeout Read timeout in seconds
+ * @param string $contentType
+ * @return Apache_Solr_Response
+ *
+ * @throws Exception If a non 200 response status is returned
+ */
+ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
+ {
+ //ensure content type is correct
+ stream_context_set_option($this->_postContext, 'http', 'header', 'Content-Type: ' . $contentType);
+
+ //set the read timeout if specified
+ if ($timeout !== FALSE)
+ {
+ stream_context_set_option($this->_postContext, 'http', 'timeout', $timeout);
+ }
+
+ //set the content
+ stream_context_set_option($this->_postContext, 'http', 'content', $rawPost);
+
+ //$http_response_header is set by file_get_contents
+ $response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_postContext), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
+
+ if ($response->getHttpStatus() != 200)
+ {
+ throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus());
+ }
+
+ return $response;
+ }
+
+ /**
+ * Returns the set host
+ *
+ * @return string
+ */
+ public function getHost()
+ {
+ return $this->_host;
+ }
+
+ /**
+ * Set the host used. If empty will fallback to constants
+ *
+ * @param string $host
+ */
+ public function setHost($host)
+ {
+ //Use the provided host or use the default
+ if (empty($host))
+ {
+ throw new Exception('Host parameter is empty');
+ }
+ else
+ {
+ $this->_host = $host;
+ }
+
+ if ($this->_urlsInited)
+ {
+ $this->_initUrls();
+ }
+ }
+
+ /**
+ * Get the set port
+ *
+ * @return integer
+ */
+ public function getPort()
+ {
+ return $this->_port;
+ }
+
+ /**
+ * Set the port used. If empty will fallback to constants
+ *
+ * @param integer $port
+ */
+ public function setPort($port)
+ {
+ //Use the provided port or use the default
+ $port = (int) $port;
+
+ if ($port <= 0)
+ {
+ throw new Exception('Port is not a valid port number');
+ }
+ else
+ {
+ $this->_port = $port;
+ }
+
+ if ($this->_urlsInited)
+ {
+ $this->_initUrls();
+ }
+ }
+
+ /**
+ * Get the set path.
+ *
+ * @return string
+ */
+ public function getPath()
+ {
+ return $this->_path;
+ }
+
+ /**
+ * Set the path used. If empty will fallback to constants
+ *
+ * @param string $path
+ */
+ public function setPath($path)
+ {
+ $path = trim($path, '/');
+
+ $this->_path = '/' . $path . '/';
+
+ if ($this->_urlsInited)
+ {
+ $this->_initUrls();
+ }
+ }
+
+ /**
+ * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
+ * parse the response and create {@link Apache_Solr_Document} instances in place.
+ *
+ * @param unknown_type $createDocuments
+ */
+ public function setCreateDocuments($createDocuments)
+ {
+ $this->_createDocuments = (bool) $createDocuments;
+ }
+
+ /**
+ * Get the current state of teh create documents flag.
+ *
+ * @return boolean
+ */
+ public function getCreateDocuments()
+ {
+ return $this->_createDocuments;
+ }
+
+ /**
+ * Set the collapse single value arrays flag.
+ *
+ * @param boolean $collapseSingleValueArrays
+ */
+ public function setCollapseSingleValueArrays($collapseSingleValueArrays)
+ {
+ $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
+ }
+
+ /**
+ * Get the current state of the collapse single value arrays flag.
+ *
+ * @return boolean
+ */
+ public function getCollapseSingleValueArrays()
+ {
+ return $this->_collapseSingleValueArrays;
+ }
+
+ /**
+ * Set how NamedLists should be formatted in the response data. This mainly effects
+ * the facet counts format.
+ *
+ * @param string $namedListTreatment
+ * @throws Exception If invalid option is set
+ */
+ public function setNamedListTreatmet($namedListTreatment)
+ {
+ switch ((string) $namedListTreatment)
+ {
+ case Apache_Solr_Service::NAMED_LIST_FLAT:
+ $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT;
+ break;
+
+ case Apache_Solr_Service::NAMED_LIST_MAP:
+ $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_MAP;
+ break;
+
+ default:
+ throw new Exception('Not a valid named list treatement option');
+ }
+ }
+
+ /**
+ * Get the current setting for named list treatment.
+ *
+ * @return string
+ */
+ public function getNamedListTreatment()
+ {
+ return $this->_namedListTreatment;
+ }
+
+
+ /**
+ * Set the string used to separate the path form the query string.
+ * Defaulted to '?'
+ *
+ * @param string $queryDelimiter
+ */
+ public function setQueryDelimiter($queryDelimiter)
+ {
+ $this->_queryDelimiter = $queryDelimiter;
+ }
+
+ /**
+ * Set the string used to separate the parameters in thequery string
+ * Defaulted to '&'
+ *
+ * @param string $queryStringDelimiter
+ */
+ public function setQueryStringDelimiter($queryStringDelimiter)
+ {
+ $this->_queryStringDelimiter = $queryStringDelimiter;
+ }
+
+ /**
+ * Call the /admin/ping servlet, can be used to quickly tell if a connection to the
+ * server is able to be made.
+ *
+ * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
+ * @return float Actual time taken to ping the server, FALSE if timeout occurs
+ */
+ public function ping($timeout = 2)
+ {
+ $timeout = (float) $timeout;
+
+ if ($timeout <= 0)
+ {
+ $timeout = -1;
+ }
+
+ $start = microtime(true);
+
+ //to prevent strict errors
+ $errno = 0;
+ $errstr = '';
+
+ //try to connect to the host with timeout
+ $fp = fsockopen($this->_host, $this->_port, $errno, $errstr, $timeout);
+
+ if ($fp)
+ {
+ //If we have a timeout set, then determine the amount of time we have left
+ //in the request and set the stream timeout for the write operation
+ if ($timeout > 0)
+ {
+ //do the calculation
+ $writeTimeout = $timeout - (microtime(true) - $start);
+
+ //check if we're out of time
+ if ($writeTimeout <= 0)
+ {
+ fclose($fp);
+ return false;
+ }
+
+ //convert to microseconds and set the stream timeout
+ $writeTimeoutInMicroseconds = (int) $writeTimeout * 1000000;
+ stream_set_timeout($fp, 0, $writeTimeoutInMicroseconds);
+ }
+
+ $request = 'HEAD ' . $this->_path . self::PING_SERVLET . ' HTTP/1.1' . "\r\n" .
+ 'host: ' . $this->_host . "\r\n" .
+ 'Connection: close' . "\r\n" .
+ "\r\n";
+
+ fwrite($fp, $request);
+
+ //check the stream meta data to see if we timed out during the operation
+ $metaData = stream_get_meta_data($fp);
+
+ if (isset($metaData['timeout']) && $metaData['timeout'])
+ {
+ fclose($fp);
+ return false;
+ }
+
+
+ //if we have a timeout set and have made it this far, determine the amount of time
+ //still remaining and set the timeout appropriately before the read operation
+ if ($timeout > 0)
+ {
+ //do the calculation
+ $readTimeout = $timeout - (microtime(true) - $start);
+
+ //check if we've run out of time
+ if ($readTimeout <= 0)
+ {
+ fclose($fp);
+ return false;
+ }
+
+ //convert to microseconds and set the stream timeout
+ $readTimeoutInMicroseconds = $readTimeout * 1000000;
+ stream_set_timeout($fp, 0, $readTimeoutInMicroseconds);
+ }
+
+ //at the very least we should get a response header line of
+ //HTTP/1.1 200 OK
+ $response = fread($fp, 15);
+
+ //check the stream meta data to see if we timed out during the operation
+ $metaData = stream_get_meta_data($fp);
+ fclose($fp); //we're done with the connection - ignore the rest
+
+ if (isset($metaData['timeout']) && $metaData['timeout'])
+ {
+ return false;
+ }
+
+ //finally, check the response header line
+ if ($response != 'HTTP/1.1 200 OK')
+ {
+ return false;
+ }
+
+ //we made it, return the approximate ping time
+ return microtime(true) - $start;
+ }
+
+ //we weren't able to make a connection
+ return false;
+ }
+
+ /**
+ * Call the /admin/threads servlet and retrieve information about all threads in the
+ * Solr servlet's thread group. Useful for diagnostics.
+ *
+ * @return Apache_Solr_Response
+ *
+ * @throws Exception If an error occurs during the service call
+ */
+ public function threads()
+ {
+ return $this->_sendRawGet($this->_threadsUrl);
+ }
+
+ /**
+ * Raw Add Method. Takes a raw post body and sends it to the update service. Post body
+ * should be a complete and well formed "add" xml document.
+ *
+ * @param string $rawPost
+ * @return Apache_Solr_Response
+ *
+ * @throws Exception If an error occurs during the service call
+ */
+ public function add($rawPost)
+ {
+ return $this->_sendRawPost($this->_updateUrl, $rawPost);
+ }
+
+ /**
+ * Add a Solr Document to the index
+ *
+ * @param Apache_Solr_Document $document
+ * @param boolean $allowDups
+ * @param boolean $overwritePending
+ * @param boolean $overwriteCommitted
+ * @return Apache_Solr_Response
+ *
+ * @throws Exception If an error occurs during the service call
+ */
+ public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
+ {
+ $dupValue = $allowDups ? 'true' : 'false';
+ $pendingValue = $overwritePending ? 'true' : 'false';
+ $committedValue = $overwriteCommitted ? 'true' : 'false';
+
+ $rawPost = '| Class | +Description | +
|---|---|
| + Apache_Solr_Service_Balancer + | ++ Reference Implementation for using multiple Solr services in a distribution. Functionality + | +
+ Documentation generated on Tue, 02 Sep 2008 10:45:03 -0400 by phpDocumentor 1.4.0 +
++ Documentation generated on Tue, 02 Sep 2008 10:45:05 -0400 by phpDocumentor 1.4.0 +
+ + Index: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/_Service.php.html =================================================================== RCS file: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/_Service.php.html diff -N sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/_Service.php.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sites/all/modules/apachesolr/SolrPhpClient/phpdocs/Apache/Solr/_Service.php.html 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,108 @@ + + + + + +| Class | +Description | +
|---|---|
| + Apache_Solr_Service + | ++ Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching. + | +
+ Documentation generated on Tue, 02 Sep 2008 10:45:04 -0400 by phpDocumentor 1.4.0 +
+Documentation is available at Response.php
++ Documentation generated on Tue, 02 Sep 2008 10:45:04 -0400 by phpDocumentor 1.4.0 +
+ + Index: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/errors.html =================================================================== RCS file: sites/all/modules/apachesolr/SolrPhpClient/phpdocs/errors.html diff -N sites/all/modules/apachesolr/SolrPhpClient/phpdocs/errors.html --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ sites/all/modules/apachesolr/SolrPhpClient/phpdocs/errors.html 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,40 @@ + + + + + ++ Documentation generated on Tue, 02 Sep 2008 10:45:05 -0400 by phpDocumentor 1.4.0 +
+ +