Source for file Balancer.php

Documentation is available at Balancer.php

  1. <?php
  2. /**
  3.  * Copyright (c) 2007-2009, Conduit Internet Technologies, Inc.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions are met:
  8.  *
  9.  *  - Redistributions of source code must retain the above copyright notice,
  10.  *    this list of conditions and the following disclaimer.
  11.  *  - Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  *  - Neither the name of Conduit Internet Technologies, Inc. nor the names of
  15.  *    its contributors may be used to endorse or promote products derived from
  16.  *    this software without specific prior written permission.
  17.  *
  18.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  22.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28.  * POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * @copyright Copyright 2007-2009 Conduit Internet Technologies, Inc. (http://conduit-it.com)
  31.  * @license New BSD (http://solr-php-client.googlecode.com/svn/trunk/COPYING)
  32.  * @version $Id: Balancer.php 15 2009-08-04 17:53:08Z donovan.jimenez $
  33.  *
  34.  * @package Apache
  35.  * @subpackage Solr
  36.  * @author Donovan Jimenez <djimenez@conduit-it.com>, Dan Wolfe
  37.  */
  38.  
  39. // See Issue #1 (http://code.google.com/p/solr-php-client/issues/detail?id=1)
  40. // Doesn't follow typical include path conventions, but is more convenient for users
  41. require_once(dirname(dirname(__FILE__)) '/Service.php');
  42.  
  43. /**
  44.  * Reference Implementation for using multiple Solr services in a distribution. Functionality
  45.  * includes:
  46.  *     routing of read / write operations
  47.  *     failover (on selection) for multiple read servers
  48.  */
  49. {
  50.     /**
  51.      * SVN Revision meta data for this class
  52.      */
  53.     const SVN_REVISION '$Revision: 15 $';
  54.  
  55.     /**
  56.      * SVN ID meta data for this class
  57.      */
  58.     const SVN_ID '$Id: Balancer.php 15 2009-08-04 17:53:08Z donovan.jimenez $';
  59.  
  60.     protected $_createDocuments = true;
  61.  
  62.     protected $_readableServices = array();
  63.     protected $_writeableServices = array();
  64.  
  65.     protected $_currentReadService = null;
  66.     protected $_currentWriteService = null;
  67.  
  68.     protected $_readPingTimeout = 2;
  69.     protected $_writePingTimeout = 4;
  70.  
  71.     // Configuration for server selection backoff intervals
  72.     protected $_useBackoff = false;        // Set to true to use more resillient write server selection
  73.     protected $_backoffLimit = 600;        // 10 minute default maximum
  74.     protected $_backoffEscalation = 2.0;     // Rate at which to increase backoff period
  75.     protected $_defaultBackoff = 2.0;        // Default backoff interval
  76.  
  77.     /**
  78.      * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
  79.      *
  80.      * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
  81.      *
  82.      * @param string $value 
  83.      * @return string 
  84.      */
  85.     static public function escape($value)
  86.     {
  87.         return Apache_Solr_Service::escape($value);
  88.     }
  89.  
  90.     /**
  91.      * Escape a value meant to be contained in a phrase for special query characters
  92.      *
  93.      * @param string $value 
  94.      * @return string 
  95.      */
  96.     static public function escapePhrase($value)
  97.     {
  98.         return Apache_Solr_Service::escapePhrase($value);
  99.     }
  100.  
  101.     /**
  102.      * Convenience function for creating phrase syntax from a value
  103.      *
  104.      * @param string $value 
  105.      * @return string 
  106.      */
  107.     static public function phrase($value)
  108.     {
  109.         return Apache_Solr_Service::phrase($value);
  110.     }
  111.  
  112.     /**
  113.      * Constructor. Takes arrays of read and write service instances or descriptions
  114.      *
  115.      * @param array $readableServices 
  116.      * @param array $writeableServices 
  117.      */
  118.     public function __construct($readableServices array()$writeableServices array())
  119.     {
  120.         //setup readable services
  121.         foreach ($readableServices as $service)
  122.         {
  123.             $this->addReadService($service);
  124.         }
  125.  
  126.         //setup writeable services
  127.         foreach ($writeableServices as $service)
  128.         {
  129.             $this->addWriteService($service);
  130.         }
  131.     }
  132.  
  133.     public function setReadPingTimeout($timeout)
  134.     {
  135.         $this->_readPingTimeout = $timeout;
  136.     }
  137.  
  138.     public function setWritePingTimeout($timeout)
  139.     {
  140.         $this->_writePingTimeout = $timeout;
  141.     }
  142.  
  143.     public function setUseBackoff($enable)
  144.     {
  145.         $this->_useBackoff = $enable;
  146.     }
  147.  
  148.     /**
  149.      * Generates a service ID
  150.      *
  151.      * @param string $host 
  152.      * @param integer $port 
  153.      * @param string $path 
  154.      * @return string 
  155.      */
  156.     protected function _getServiceId($host$port$path)
  157.     {
  158.         return $host ':' $port $path;
  159.     }
  160.  
  161.     /**
  162.      * Adds a service instance or service descriptor (if it is already
  163.      * not added)
  164.      *
  165.      * @param mixed $service 
  166.      *
  167.      * @throws Exception If service descriptor is not valid
  168.      */
  169.     public function addReadService($service)
  170.     {
  171.         if ($service instanceof Apache_Solr_Service)
  172.         {
  173.             $id $this->_getServiceId($service->getHost()$service->getPort()$service->getPath());
  174.  
  175.             $this->_readableServices[$id$service;
  176.         }
  177.         else if (is_array($service))
  178.         {
  179.             if (isset($service['host']&& isset($service['port']&& isset($service['path']))
  180.             {
  181.                 $id $this->_getServiceId((string)$service['host'](int)$service['port'](string)$service['path']);
  182.  
  183.                 $this->_readableServices[$id$service;
  184.             }
  185.             else
  186.             {
  187.                 throw new Exception('A Readable Service description array does not have all required elements of host, port, and path');
  188.             }
  189.         }
  190.     }
  191.  
  192.     /**
  193.      * Removes a service instance or descriptor from the available services
  194.      *
  195.      * @param mixed $service 
  196.      *
  197.      * @throws Exception If service descriptor is not valid
  198.      */
  199.     public function removeReadService($service)
  200.     {
  201.         $id '';
  202.  
  203.         if ($service instanceof Apache_Solr_Service)
  204.         {
  205.             $id $this->_getServiceId($service->getHost()$service->getPort()$service->getPath());
  206.         }
  207.         else if (is_array($service))
  208.         {
  209.             if (isset($service['host']&& isset($service['port']&& isset($service['path']))
  210.             {
  211.                 $id $this->_getServiceId((string)$service['host'](int)$service['port'](string)$service['path']);
  212.             }
  213.             else
  214.             {
  215.                 throw new Exception('A Readable Service description array does not have all required elements of host, port, and path');
  216.             }
  217.         }
  218.         else if (is_string($service))
  219.         {
  220.             $id $service;
  221.         }
  222.  
  223.         if ($id && isset($this->_readableServices[$id]))
  224.         {
  225.             unset($this->_readableServices[$id]);
  226.         }
  227.     }
  228.  
  229.     /**
  230.      * Adds a service instance or service descriptor (if it is already
  231.      * not added)
  232.      *
  233.      * @param mixed $service 
  234.      *
  235.      * @throws Exception If service descriptor is not valid
  236.      */
  237.     public function addWriteService($service)
  238.     {
  239.         if ($service instanceof Apache_Solr_Service)
  240.         {
  241.             $id $this->_getServiceId($service->getHost()$service->getPort()$service->getPath());
  242.  
  243.             $this->_writeableServices[$id$service;
  244.         }
  245.         else if (is_array($service))
  246.         {
  247.             if (isset($service['host']&& isset($service['port']&& isset($service['path']))
  248.             {
  249.                 $id $this->_getServiceId((string)$service['host'](int)$service['port'](string)$service['path']);
  250.  
  251.                 $this->_writeableServices[$id$service;
  252.             }
  253.             else
  254.             {
  255.                 throw new Exception('A Writeable Service description array does not have all required elements of host, port, and path');
  256.             }
  257.         }
  258.     }
  259.  
  260.     /**
  261.      * Removes a service instance or descriptor from the available services
  262.      *
  263.      * @param mixed $service 
  264.      *
  265.      * @throws Exception If service descriptor is not valid
  266.      */
  267.     public function removeWriteService($service)
  268.     {
  269.         $id '';
  270.  
  271.         if ($service instanceof Apache_Solr_Service)
  272.         {
  273.             $id $this->_getServiceId($service->getHost()$service->getPort()$service->getPath());
  274.         }
  275.         else if (is_array($service))
  276.         {
  277.             if (isset($service['host']&& isset($service['port']&& isset($service['path']))
  278.             {
  279.                 $id $this->_getServiceId((string)$service['host'](int)$service['port'](string)$service['path']);
  280.             }
  281.             else
  282.             {
  283.                 throw new Exception('A Readable Service description array does not have all required elements of host, port, and path');
  284.             }
  285.         }
  286.         else if (is_string($service))
  287.         {
  288.             $id $service;
  289.         }
  290.  
  291.         if ($id && isset($this->_writeableServices[$id]))
  292.         {
  293.             unset($this->_writeableServices[$id]);
  294.         }
  295.     }
  296.  
  297.     /**
  298.      * Iterate through available read services and select the first with a ping
  299.      * that satisfies configured timeout restrictions (or the default)
  300.      *
  301.      * @return Apache_Solr_Service 
  302.      *
  303.      * @throws Exception If there are no read services that meet requirements
  304.      */
  305.     protected function _selectReadService($forceSelect false)
  306.     {
  307.         if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]|| $forceSelect)
  308.         {
  309.             if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]&& $forceSelect)
  310.             {
  311.                 // we probably had a communication error, ping the current read service, remove it if it times out
  312.                 if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout=== false)
  313.                 {
  314.                     $this->removeReadService($this->_currentReadService);
  315.                 }
  316.             }
  317.  
  318.             if (count($this->_readableServices))
  319.             {
  320.                 // select one of the read services at random
  321.                 $ids array_keys($this->_readableServices);
  322.  
  323.                 $id $ids[rand(0count($ids1)];
  324.                 $service $this->_readableServices[$id];
  325.  
  326.                 if (is_array($service))
  327.                 {
  328.                     //convert the array definition to a client object
  329.                     $service new Apache_Solr_Service($service['host']$service['port']$service['path']);
  330.                     $this->_readableServices[$id$service;
  331.                 }
  332.  
  333.                 $service->setCreateDocuments($this->_createDocuments);
  334.                 $this->_currentReadService = $id;
  335.             }
  336.             else
  337.             {
  338.                 throw new Exception('No read services were available');
  339.             }
  340.         }
  341.  
  342.         return $this->_readableServices[$this->_currentReadService];
  343.     }
  344.  
  345.     /**
  346.      * Iterate through available write services and select the first with a ping
  347.      * that satisfies configured timeout restrictions (or the default)
  348.      *
  349.      * @return Apache_Solr_Service 
  350.      *
  351.      * @throws Exception If there are no write services that meet requirements
  352.      */
  353.     protected function _selectWriteService($forceSelect false)
  354.     {
  355.         if($this->_useBackoff)
  356.         {
  357.             return $this->_selectWriteServiceSafe($forceSelect);
  358.         }
  359.  
  360.         if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]|| $forceSelect)
  361.         {
  362.             if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]&& $forceSelect)
  363.             {
  364.                 // we probably had a communication error, ping the current read service, remove it if it times out
  365.                 if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout=== false)
  366.                 {
  367.                     $this->removeWriteService($this->_currentWriteService);
  368.                 }
  369.             }
  370.  
  371.             if (count($this->_writeableServices))
  372.             {
  373.                 // select one of the read services at random
  374.                 $ids array_keys($this->_writeableServices);
  375.  
  376.                 $id $ids[rand(0count($ids1)];
  377.                 $service $this->_writeableServices[$id];
  378.  
  379.                 if (is_array($service))
  380.                 {
  381.                     //convert the array definition to a client object
  382.                     $service new Apache_Solr_Service($service['host']$service['port']$service['path']);
  383.                     $this->_writeableServices[$id$service;
  384.                 }
  385.  
  386.                 $this->_currentWriteService = $id;
  387.             }
  388.             else
  389.             {
  390.                 throw new Exception('No write services were available');
  391.             }
  392.         }
  393.  
  394.         return $this->_writeableServices[$this->_currentWriteService];
  395.     }
  396.  
  397.     /**
  398.      * Iterate through available write services and select the first with a ping
  399.      * that satisfies configured timeout restrictions (or the default).  The
  400.      * timeout period will increase until a connection is made or the limit is
  401.      * reached.   This will allow for increased reliability with heavily loaded
  402.      * server(s).
  403.      *
  404.      * @return Apache_Solr_Service 
  405.      *
  406.      * @throws Exception If there are no write services that meet requirements
  407.      */
  408.  
  409.     protected function _selectWriteServiceSafe($forceSelect false)
  410.     {
  411.         if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]|| $forceSelect)
  412.         {
  413.             if (count($this->_writeableServices))
  414.             {
  415.                 $backoff $this->_defaultBackoff;
  416.  
  417.                 do {
  418.                     // select one of the read services at random
  419.                     $ids array_keys($this->_writeableServices);
  420.  
  421.                     $id $ids[rand(0count($ids1)];
  422.                     $service $this->_writeableServices[$id];
  423.  
  424.                     if (is_array($service))
  425.                     {
  426.                         //convert the array definition to a client object
  427.                         $service new Apache_Solr_Service($service['host']$service['port']$service['path']);
  428.                         $this->_writeableServices[$id$service;
  429.                     }
  430.  
  431.                     $this->_currentWriteService = $id;
  432.  
  433.                     $backoff *= $this->_backoffEscalation;
  434.  
  435.                     if($backoff $this->_backoffLimit)
  436.                     {
  437.                         throw new Exception('No write services were available.  All timeouts exceeded.');
  438.                     }
  439.  
  440.                 while($this->_writeableServices[$this->_currentWriteService]->ping($backoff=== false);
  441.             }
  442.             else
  443.             {
  444.                 throw new Exception('No write services were available');
  445.             }
  446.         }
  447.  
  448.         return $this->_writeableServices[$this->_currentWriteService];
  449.     }
  450.  
  451.     public function setCreateDocuments($createDocuments)
  452.     {
  453.         $this->_createDocuments = (bool) $createDocuments;
  454.  
  455.         if ($this->_currentReadService)
  456.         {
  457.             $service $this->_selectReadService();
  458.             $service->setCreateDocuments($createDocuments);
  459.         }
  460.     }
  461.  
  462.     public function getCreateDocuments()
  463.     {
  464.         return $this->_createDocuments;
  465.     }
  466.  
  467.     /**
  468.      * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
  469.      * should be a complete and well formed "add" xml document.
  470.      *
  471.      * @param string $rawPost 
  472.      * @return Apache_Solr_Response 
  473.      *
  474.      * @throws Exception If an error occurs during the service call
  475.      */
  476.     public function add($rawPost)
  477.     {
  478.         $service $this->_selectWriteService();
  479.  
  480.         do
  481.         {
  482.             try
  483.             {
  484.                 return $service->add($rawPost);
  485.             }
  486.             catch (Exception $e)
  487.             {
  488.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  489.                 {
  490.                     throw $e;
  491.                 }
  492.             }
  493.  
  494.             $service $this->_selectWriteService(true);
  495.         while ($service);
  496.  
  497.         return false;
  498.     }
  499.  
  500.     /**
  501.      * Add a Solr Document to the index
  502.      *
  503.      * @param Apache_Solr_Document $document 
  504.      * @param boolean $allowDups 
  505.      * @param boolean $overwritePending 
  506.      * @param boolean $overwriteCommitted 
  507.      * @return Apache_Solr_Response 
  508.      *
  509.      * @throws Exception If an error occurs during the service call
  510.      */
  511.     public function addDocument(Apache_Solr_Document $document$allowDups false$overwritePending true$overwriteCommitted true)
  512.     {
  513.         $service $this->_selectWriteService();
  514.  
  515.         do
  516.         {
  517.             try
  518.             {
  519.                 return $service->addDocument($document$allowDups$overwritePending$overwriteCommitted);
  520.             }
  521.             catch (Exception $e)
  522.             {
  523.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  524.                 {
  525.                     throw $e;
  526.                 }
  527.             }
  528.  
  529.             $service $this->_selectWriteService(true);
  530.         while ($service);
  531.  
  532.         return false;
  533.     }
  534.  
  535.     /**
  536.      * Add an array of Solr Documents to the index all at once
  537.      *
  538.      * @param array $documents Should be an array of Apache_Solr_Document instances
  539.      * @param boolean $allowDups 
  540.      * @param boolean $overwritePending 
  541.      * @param boolean $overwriteCommitted 
  542.      * @return Apache_Solr_Response 
  543.      *
  544.      * @throws Exception If an error occurs during the service call
  545.      */
  546.     public function addDocuments($documents$allowDups false$overwritePending true$overwriteCommitted true)
  547.     {
  548.         $service $this->_selectWriteService();
  549.  
  550.         do
  551.         {
  552.             try
  553.             {
  554.                 return $service->addDocuments($documents$allowDups$overwritePending$overwriteCommitted);
  555.             }
  556.             catch (Exception $e)
  557.             {
  558.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  559.                 {
  560.                     throw $e;
  561.                 }
  562.             }
  563.  
  564.             $service $this->_selectWriteService(true);
  565.         while ($service);
  566.  
  567.         return false;
  568.     }
  569.  
  570.     /**
  571.      * Send a commit command.  Will be synchronous unless both wait parameters are set
  572.      * to false.
  573.      *
  574.      * @param boolean $waitFlush 
  575.      * @param boolean $waitSearcher 
  576.      * @return Apache_Solr_Response 
  577.      *
  578.      * @throws Exception If an error occurs during the service call
  579.      */
  580.     public function commit($optimize true$waitFlush true$waitSearcher true$timeout 3600)
  581.     {
  582.         $service $this->_selectWriteService();
  583.  
  584.         do
  585.         {
  586.             try
  587.             {
  588.                 return $service->commit($optimize$waitFlush$waitSearcher$timeout);
  589.             }
  590.             catch (Exception $e)
  591.             {
  592.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  593.                 {
  594.                     throw $e;
  595.                 }
  596.             }
  597.  
  598.             $service $this->_selectWriteService(true);
  599.         while ($service);
  600.  
  601.         return false;
  602.     }
  603.  
  604.     /**
  605.      * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
  606.      * a complete and well formed "delete" xml document
  607.      *
  608.      * @param string $rawPost 
  609.      * @return Apache_Solr_Response 
  610.      *
  611.      * @throws Exception If an error occurs during the service call
  612.      */
  613.     public function delete($rawPost)
  614.     {
  615.         $service $this->_selectWriteService();
  616.  
  617.         do
  618.         {
  619.             try
  620.             {
  621.                 return $service->delete($rawPost);
  622.             }
  623.             catch (Exception $e)
  624.             {
  625.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  626.                 {
  627.                     throw $e;
  628.                 }
  629.             }
  630.  
  631.             $service $this->_selectWriteService(true);
  632.         while ($service);
  633.  
  634.         return false;
  635.     }
  636.  
  637.     /**
  638.      * Create a delete document based on document ID
  639.      *
  640.      * @param string $id 
  641.      * @param boolean $fromPending 
  642.      * @param boolean $fromCommitted 
  643.      * @return Apache_Solr_Response 
  644.      *
  645.      * @throws Exception If an error occurs during the service call
  646.      */
  647.     public function deleteById($id$fromPending true$fromCommitted true)
  648.     {
  649.         $service $this->_selectWriteService();
  650.  
  651.         do
  652.         {
  653.             try
  654.             {
  655.                 return $service->deleteById($id$fromPending$fromCommitted);
  656.             }
  657.             catch (Exception $e)
  658.             {
  659.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  660.                 {
  661.                     throw $e;
  662.                 }
  663.             }
  664.  
  665.             $service $this->_selectWriteService(true);
  666.         while ($service);
  667.  
  668.         return false;
  669.     }
  670.  
  671.     /**
  672.      * Create a delete document based on a query and submit it
  673.      *
  674.      * @param string $rawQuery 
  675.      * @param boolean $fromPending 
  676.      * @param boolean $fromCommitted 
  677.      * @return Apache_Solr_Response 
  678.      *
  679.      * @throws Exception If an error occurs during the service call
  680.      */
  681.     public function deleteByQuery($rawQuery$fromPending true$fromCommitted true)
  682.     {
  683.         $service $this->_selectWriteService();
  684.  
  685.         do
  686.         {
  687.             try
  688.             {
  689.                 return $service->deleteByQuery($rawQuery$fromPending$fromCommitted);
  690.             }
  691.             catch (Exception $e)
  692.             {
  693.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  694.                 {
  695.                     throw $e;
  696.                 }
  697.             }
  698.  
  699.             $service $this->_selectWriteService(true);
  700.         while ($service);
  701.  
  702.         return false;
  703.     }
  704.  
  705.     /**
  706.      * Send an optimize command.  Will be synchronous unless both wait parameters are set
  707.      * to false.
  708.      *
  709.      * @param boolean $waitFlush 
  710.      * @param boolean $waitSearcher 
  711.      * @return Apache_Solr_Response 
  712.      *
  713.      * @throws Exception If an error occurs during the service call
  714.      */
  715.     public function optimize($waitFlush true$waitSearcher true)
  716.     {
  717.         $service $this->_selectWriteService();
  718.  
  719.         do
  720.         {
  721.             try
  722.             {
  723.                 return $service->optimize($waitFlush$waitSearcher);
  724.             }
  725.             catch (Exception $e)
  726.             {
  727.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  728.                 {
  729.                     throw $e;
  730.                 }
  731.             }
  732.  
  733.             $service $this->_selectWriteService(true);
  734.         while ($service);
  735.  
  736.         return false;
  737.     }
  738.  
  739.     /**
  740.      * Simple Search interface
  741.      *
  742.      * @param string $query The raw query string
  743.      * @param int $offset The starting offset for result documents
  744.      * @param int $limit The maximum number of result documents to return
  745.      * @param array $params key / value pairs for query parameters, use arrays for multivalued parameters
  746.      * @return Apache_Solr_Response 
  747.      *
  748.      * @throws Exception If an error occurs during the service call
  749.      */
  750.     public function search($query$offset 0$limit 10$params array())
  751.     {
  752.         $service $this->_selectReadService();
  753.  
  754.         do
  755.         {
  756.             try
  757.             {
  758.                 return $service->search($query$offset$limit$params);
  759.             }
  760.             catch (Exception $e)
  761.             {
  762.                 if ($e->getCode(!= 0//IF NOT COMMUNICATION ERROR
  763.                 {
  764.                     throw $e;
  765.                 }
  766.             }
  767.  
  768.             $service $this->_selectReadService(true);
  769.         while ($service);
  770.  
  771.         return false;
  772.     }
  773. }

Documentation generated on Mon, 09 Nov 2009 18:15:41 -0500 by phpDocumentor 1.4.2