Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( b34a1c...06de54 )
by Sebastian
03:26 queued 50s
created
dlf/plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 			// Set default values if not set.
53 53
 			// $this->piVars['page'] may be integer or string (physical structure @ID)
54
-			if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {
54
+			if ((int) $this->piVars['page'] > 0 || empty($this->piVars['page'])) {
55 55
 
56 56
 				$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
57 57
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 					.$this->pi_getLL('fulltext-on', '', TRUE).';fulltext-off:'
85 85
 					.$this->pi_getLL('fulltext-off', '', TRUE).'">&nbsp;</a>';
86 86
 		} else {
87
-			$markerArray['###FULLTEXT_SELECT###'] = '<span class="no-fulltext">' . $this->pi_getLL('fulltext-not-available', '', TRUE) . '</span>';
87
+			$markerArray['###FULLTEXT_SELECT###'] = '<span class="no-fulltext">'.$this->pi_getLL('fulltext-not-available', '', TRUE).'</span>';
88 88
 		}
89 89
 
90 90
 		$content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
Please login to merge, or discard this patch.
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -20,85 +20,85 @@
 block discarded – undo
20 20
  */
21 21
 class tx_dlf_toolsFulltext extends tx_dlf_plugin {
22 22
 
23
-	public $scriptRelPath = 'plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php';
23
+    public $scriptRelPath = 'plugins/toolbox/tools/fulltext/class.tx_dlf_toolsFulltext.php';
24 24
 
25
-	/**
26
-	 * The main method of the PlugIn
27
-	 *
28
-	 * @access	public
29
-	 *
30
-	 * @param	string		$content: The PlugIn content
31
-	 * @param	array		$conf: The PlugIn configuration
32
-	 *
33
-	 * @return	string		The content that is displayed on the website
34
-	 */
35
-	public function main($content, $conf) {
25
+    /**
26
+     * The main method of the PlugIn
27
+     *
28
+     * @access	public
29
+     *
30
+     * @param	string		$content: The PlugIn content
31
+     * @param	array		$conf: The PlugIn configuration
32
+     *
33
+     * @return	string		The content that is displayed on the website
34
+     */
35
+    public function main($content, $conf) {
36 36
 
37
-		$this->init($conf);
37
+        $this->init($conf);
38 38
 
39
-		// Merge configuration with conf array of toolbox.
40
-		$this->conf = tx_dlf_helper::array_merge_recursive_overrule($this->cObj->data['conf'], $this->conf);
39
+        // Merge configuration with conf array of toolbox.
40
+        $this->conf = tx_dlf_helper::array_merge_recursive_overrule($this->cObj->data['conf'], $this->conf);
41 41
 
42
-		// Load current document.
43
-		$this->loadDocument();
42
+        // Load current document.
43
+        $this->loadDocument();
44 44
 
45
-		if ($this->doc === NULL || $this->doc->numPages < 1 || empty($this->conf['fileGrpFulltext'])) {
45
+        if ($this->doc === NULL || $this->doc->numPages < 1 || empty($this->conf['fileGrpFulltext'])) {
46 46
 
47
-			// Quit without doing anything if required variables are not set.
48
-			return $content;
47
+            // Quit without doing anything if required variables are not set.
48
+            return $content;
49 49
 
50
-		} else {
50
+        } else {
51 51
 
52
-			if (!empty($this->piVars['logicalPage'])) {
52
+            if (!empty($this->piVars['logicalPage'])) {
53 53
 
54
-				$this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
55
-				// The logical page parameter should not appear again
56
-				unset($this->piVars['logicalPage']);
54
+                $this->piVars['page'] = $this->doc->getPhysicalPage($this->piVars['logicalPage']);
55
+                // The logical page parameter should not appear again
56
+                unset($this->piVars['logicalPage']);
57 57
 
58
-			}
58
+            }
59 59
 
60
-			// Set default values if not set.
61
-			// $this->piVars['page'] may be integer or string (physical structure @ID)
62
-			if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {
60
+            // Set default values if not set.
61
+            // $this->piVars['page'] may be integer or string (physical structure @ID)
62
+            if ( (int)$this->piVars['page'] > 0 || empty($this->piVars['page'])) {
63 63
 
64
-				$this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
64
+                $this->piVars['page'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange((int) $this->piVars['page'], 1, $this->doc->numPages, 1);
65 65
 
66
-			} else {
66
+            } else {
67 67
 
68
-				$this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
68
+                $this->piVars['page'] = array_search($this->piVars['page'], $this->doc->physicalStructure);
69 69
 
70
-			}
70
+            }
71 71
 
72
-			$this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
72
+            $this->piVars['double'] = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->piVars['double'], 0, 1, 0);
73 73
 
74
-		}
74
+        }
75 75
 
76
-		// Load template file.
77
-		if (!empty($this->conf['toolTemplateFile'])) {
76
+        // Load template file.
77
+        if (!empty($this->conf['toolTemplateFile'])) {
78 78
 
79
-			$this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['toolTemplateFile']), '###TEMPLATE###');
79
+            $this->template = $this->cObj->getSubpart($this->cObj->fileResource($this->conf['toolTemplateFile']), '###TEMPLATE###');
80 80
 
81
-		} else {
81
+        } else {
82 82
 
83
-			$this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toolbox/tools/fulltext/template.tmpl'), '###TEMPLATE###');
83
+            $this->template = $this->cObj->getSubpart($this->cObj->fileResource('EXT:dlf/plugins/toolbox/tools/fulltext/template.tmpl'), '###TEMPLATE###');
84 84
 
85
-		}
85
+        }
86 86
 
87 87
 
88
-		$fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']];
88
+        $fullTextFile = $this->doc->physicalStructureInfo[$this->doc->physicalStructure[$this->piVars['page']]]['files'][$this->conf['fileGrpFulltext']];
89 89
 
90
-		if (!empty($fullTextFile)) {
91
-			$markerArray['###FULLTEXT_SELECT###'] = '<a class="select switchoff" id="tx-dlf-tools-fulltext" title="" data-dic="fulltext-on:'
92
-					.$this->pi_getLL('fulltext-on', '', TRUE).';fulltext-off:'
93
-					.$this->pi_getLL('fulltext-off', '', TRUE).'">&nbsp;</a>';
94
-		} else {
95
-			$markerArray['###FULLTEXT_SELECT###'] = '<span class="no-fulltext">' . $this->pi_getLL('fulltext-not-available', '', TRUE) . '</span>';
96
-		}
90
+        if (!empty($fullTextFile)) {
91
+            $markerArray['###FULLTEXT_SELECT###'] = '<a class="select switchoff" id="tx-dlf-tools-fulltext" title="" data-dic="fulltext-on:'
92
+                    .$this->pi_getLL('fulltext-on', '', TRUE).';fulltext-off:'
93
+                    .$this->pi_getLL('fulltext-off', '', TRUE).'">&nbsp;</a>';
94
+        } else {
95
+            $markerArray['###FULLTEXT_SELECT###'] = '<span class="no-fulltext">' . $this->pi_getLL('fulltext-not-available', '', TRUE) . '</span>';
96
+        }
97 97
 
98
-		$content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
98
+        $content .= $this->cObj->substituteMarkerArray($this->template, $markerArray);
99 99
 
100
-		return $this->pi_wrapInBaseClass($content);
100
+        return $this->pi_wrapInBaseClass($content);
101 101
 
102
-	}
102
+    }
103 103
 
104 104
 }
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/HttpTransport/Interface.php 4 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
  */
38 38
 
39 39
 // require Apache_Solr_HttpTransport_Response
40
-require_once(dirname(__FILE__) . '/Response.php');
40
+require_once(dirname(__FILE__).'/Response.php');
41 41
 
42 42
 /**
43 43
  * Interface that all Transport (HTTP Requester) implementations must implement. These
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -46,49 +46,49 @@
 block discarded – undo
46 46
  */
47 47
 interface Apache_Solr_HttpTransport_Interface
48 48
 {
49
-	/**
50
-	 * Get the current default timeout for all HTTP requests
51
-	 *
52
-	 * @return float
53
-	 */
54
-	public function getDefaultTimeout();
49
+    /**
50
+     * Get the current default timeout for all HTTP requests
51
+     *
52
+     * @return float
53
+     */
54
+    public function getDefaultTimeout();
55 55
 	
56
-	/**
57
-	 * Set the current default timeout for all HTTP requests
58
-	 *
59
-	 * @param float $timeout
60
-	 */
61
-	public function setDefaultTimeout($timeout);
56
+    /**
57
+     * Set the current default timeout for all HTTP requests
58
+     *
59
+     * @param float $timeout
60
+     */
61
+    public function setDefaultTimeout($timeout);
62 62
 		
63
-	/**
64
-	 * Perform a GET HTTP operation with an optional timeout and return the response
65
-	 * contents, use getLastResponseHeaders to retrieve HTTP headers
66
-	 *
67
-	 * @param string $url
68
-	 * @param float $timeout
69
-	 * @return Apache_Solr_HttpTransport_Response HTTP response
70
-	 */
71
-	public function performGetRequest($url, $timeout = false);
63
+    /**
64
+     * Perform a GET HTTP operation with an optional timeout and return the response
65
+     * contents, use getLastResponseHeaders to retrieve HTTP headers
66
+     *
67
+     * @param string $url
68
+     * @param float $timeout
69
+     * @return Apache_Solr_HttpTransport_Response HTTP response
70
+     */
71
+    public function performGetRequest($url, $timeout = false);
72 72
 	
73
-	/**
74
-	 * Perform a HEAD HTTP operation with an optional timeout and return the response
75
-	 * headers - NOTE: head requests have no response body
76
-	 *
77
-	 * @param string $url
78
-	 * @param float $timeout
79
-	 * @return Apache_Solr_HttpTransport_Response HTTP response
80
-	 */
81
-	public function performHeadRequest($url, $timeout = false);
73
+    /**
74
+     * Perform a HEAD HTTP operation with an optional timeout and return the response
75
+     * headers - NOTE: head requests have no response body
76
+     *
77
+     * @param string $url
78
+     * @param float $timeout
79
+     * @return Apache_Solr_HttpTransport_Response HTTP response
80
+     */
81
+    public function performHeadRequest($url, $timeout = false);
82 82
 	
83
-	/**
84
-	 * Perform a POST HTTP operation with an optional timeout and return the response
85
-	 * contents, use getLastResponseHeaders to retrieve HTTP headers
86
-	 *
87
-	 * @param string $url
88
-	 * @param string $rawPost
89
-	 * @param string $contentType
90
-	 * @param float $timeout
91
-	 * @return Apache_Solr_HttpTransport_Response HTTP response
92
-	 */
93
-	public function performPostRequest($url, $rawPost, $contentType, $timeout = false);
83
+    /**
84
+     * Perform a POST HTTP operation with an optional timeout and return the response
85
+     * contents, use getLastResponseHeaders to retrieve HTTP headers
86
+     *
87
+     * @param string $url
88
+     * @param string $rawPost
89
+     * @param string $contentType
90
+     * @param float $timeout
91
+     * @return Apache_Solr_HttpTransport_Response HTTP response
92
+     */
93
+    public function performPostRequest($url, $rawPost, $contentType, $timeout = false);
94 94
 }
95 95
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,8 +44,7 @@
 block discarded – undo
44 44
  * Implementations can then be plugged into the Service instance in order to user their
45 45
  * the desired method for making HTTP requests
46 46
  */
47
-interface Apache_Solr_HttpTransport_Interface
48
-{
47
+interface Apache_Solr_HttpTransport_Interface {
49 48
 	/**
50 49
 	 * Get the current default timeout for all HTTP requests
51 50
 	 *
Please login to merge, or discard this patch.
Upper-Lower-Casing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 * @param float $timeout
69 69
 	 * @return Apache_Solr_HttpTransport_Response HTTP response
70 70
 	 */
71
-	public function performGetRequest($url, $timeout = false);
71
+	public function performGetRequest($url, $timeout = FALSE);
72 72
 	
73 73
 	/**
74 74
 	 * Perform a HEAD HTTP operation with an optional timeout and return the response
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 * @param float $timeout
79 79
 	 * @return Apache_Solr_HttpTransport_Response HTTP response
80 80
 	 */
81
-	public function performHeadRequest($url, $timeout = false);
81
+	public function performHeadRequest($url, $timeout = FALSE);
82 82
 	
83 83
 	/**
84 84
 	 * Perform a POST HTTP operation with an optional timeout and return the response
@@ -90,5 +90,5 @@  discard block
 block discarded – undo
90 90
 	 * @param float $timeout
91 91
 	 * @return Apache_Solr_HttpTransport_Response HTTP response
92 92
 	 */
93
-	public function performPostRequest($url, $rawPost, $contentType, $timeout = false);
93
+	public function performPostRequest($url, $rawPost, $contentType, $timeout = FALSE);
94 94
 }
95 95
\ No newline at end of file
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/Document.php 4 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -57,311 +57,311 @@
 block discarded – undo
57 57
  */
58 58
 class Apache_Solr_Document implements IteratorAggregate
59 59
 {
60
-	/**
61
-	 * SVN Revision meta data for this class
62
-	 */
63
-	const SVN_REVISION = '$Revision: 54 $';
60
+    /**
61
+     * SVN Revision meta data for this class
62
+     */
63
+    const SVN_REVISION = '$Revision: 54 $';
64 64
 
65
-	/**
66
-	 * SVN ID meta data for this class
67
-	 */
68
-	const SVN_ID = '$Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
65
+    /**
66
+     * SVN ID meta data for this class
67
+     */
68
+    const SVN_ID = '$Id: Document.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
69 69
 
70
-	/**
71
-	 * Document boost value
72
-	 *
73
-	 * @var float
74
-	 */
75
-	protected $_documentBoost = false;
70
+    /**
71
+     * Document boost value
72
+     *
73
+     * @var float
74
+     */
75
+    protected $_documentBoost = false;
76 76
 
77
-	/**
78
-	 * Document field values, indexed by name
79
-	 *
80
-	 * @var array
81
-	 */
82
-	protected $_fields = array();
77
+    /**
78
+     * Document field values, indexed by name
79
+     *
80
+     * @var array
81
+     */
82
+    protected $_fields = array();
83 83
 
84
-	/**
85
-	 * Document field boost values, indexed by name
86
-	 *
87
-	 * @var array array of floats
88
-	 */
89
-	protected $_fieldBoosts = array();
84
+    /**
85
+     * Document field boost values, indexed by name
86
+     *
87
+     * @var array array of floats
88
+     */
89
+    protected $_fieldBoosts = array();
90 90
 
91
-	/**
92
-	 * Clear all boosts and fields from this document
93
-	 */
94
-	public function clear()
95
-	{
96
-		$this->_documentBoost = false;
91
+    /**
92
+     * Clear all boosts and fields from this document
93
+     */
94
+    public function clear()
95
+    {
96
+        $this->_documentBoost = false;
97 97
 
98
-		$this->_fields = array();
99
-		$this->_fieldBoosts = array();
100
-	}
98
+        $this->_fields = array();
99
+        $this->_fieldBoosts = array();
100
+    }
101 101
 
102
-	/**
103
-	 * Get current document boost
104
-	 *
105
-	 * @return mixed will be false for default, or else a float
106
-	 */
107
-	public function getBoost()
108
-	{
109
-		return $this->_documentBoost;
110
-	}
102
+    /**
103
+     * Get current document boost
104
+     *
105
+     * @return mixed will be false for default, or else a float
106
+     */
107
+    public function getBoost()
108
+    {
109
+        return $this->_documentBoost;
110
+    }
111 111
 
112
-	/**
113
-	 * Set document boost factor
114
-	 *
115
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
116
-	 */
117
-	public function setBoost($boost)
118
-	{
119
-		$boost = (float) $boost;
112
+    /**
113
+     * Set document boost factor
114
+     *
115
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
116
+     */
117
+    public function setBoost($boost)
118
+    {
119
+        $boost = (float) $boost;
120 120
 
121
-		if ($boost > 0.0)
122
-		{
123
-			$this->_documentBoost = $boost;
124
-		}
125
-		else
126
-		{
127
-			$this->_documentBoost = false;
128
-		}
129
-	}
121
+        if ($boost > 0.0)
122
+        {
123
+            $this->_documentBoost = $boost;
124
+        }
125
+        else
126
+        {
127
+            $this->_documentBoost = false;
128
+        }
129
+    }
130 130
 
131
-	/**
132
-	 * Add a value to a multi-valued field
133
-	 *
134
-	 * NOTE: the solr XML format allows you to specify boosts
135
-	 * PER value even though the underlying Lucene implementation
136
-	 * only allows a boost per field. To remedy this, the final
137
-	 * field boost value will be the product of all specified boosts
138
-	 * on field values - this is similar to SolrJ's functionality.
139
-	 *
140
-	 * <code>
141
-	 * $doc = new Apache_Solr_Document();
142
-	 *
143
-	 * $doc->addField('foo', 'bar', 2.0);
144
-	 * $doc->addField('foo', 'baz', 3.0);
145
-	 *
146
-	 * // resultant field boost will be 6!
147
-	 * echo $doc->getFieldBoost('foo');
148
-	 * </code>
149
-	 *
150
-	 * @param string $key
151
-	 * @param mixed $value
152
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
153
-	 */
154
-	public function addField($key, $value, $boost = false)
155
-	{
156
-		if (!isset($this->_fields[$key]))
157
-		{
158
-			// create holding array if this is the first value
159
-			$this->_fields[$key] = array();
160
-		}
161
-		else if (!is_array($this->_fields[$key]))
162
-		{
163
-			// move existing value into array if it is not already an array
164
-			$this->_fields[$key] = array($this->_fields[$key]);
165
-		}
131
+    /**
132
+     * Add a value to a multi-valued field
133
+     *
134
+     * NOTE: the solr XML format allows you to specify boosts
135
+     * PER value even though the underlying Lucene implementation
136
+     * only allows a boost per field. To remedy this, the final
137
+     * field boost value will be the product of all specified boosts
138
+     * on field values - this is similar to SolrJ's functionality.
139
+     *
140
+     * <code>
141
+     * $doc = new Apache_Solr_Document();
142
+     *
143
+     * $doc->addField('foo', 'bar', 2.0);
144
+     * $doc->addField('foo', 'baz', 3.0);
145
+     *
146
+     * // resultant field boost will be 6!
147
+     * echo $doc->getFieldBoost('foo');
148
+     * </code>
149
+     *
150
+     * @param string $key
151
+     * @param mixed $value
152
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
153
+     */
154
+    public function addField($key, $value, $boost = false)
155
+    {
156
+        if (!isset($this->_fields[$key]))
157
+        {
158
+            // create holding array if this is the first value
159
+            $this->_fields[$key] = array();
160
+        }
161
+        else if (!is_array($this->_fields[$key]))
162
+        {
163
+            // move existing value into array if it is not already an array
164
+            $this->_fields[$key] = array($this->_fields[$key]);
165
+        }
166 166
 
167
-		if ($this->getFieldBoost($key) === false)
168
-		{
169
-			// boost not already set, set it now
170
-			$this->setFieldBoost($key, $boost);
171
-		}
172
-		else if ((float) $boost > 0.0)
173
-		{
174
-			// multiply passed boost with current field boost - similar to SolrJ implementation
175
-			$this->_fieldBoosts[$key] *= (float) $boost;
176
-		}
167
+        if ($this->getFieldBoost($key) === false)
168
+        {
169
+            // boost not already set, set it now
170
+            $this->setFieldBoost($key, $boost);
171
+        }
172
+        else if ((float) $boost > 0.0)
173
+        {
174
+            // multiply passed boost with current field boost - similar to SolrJ implementation
175
+            $this->_fieldBoosts[$key] *= (float) $boost;
176
+        }
177 177
 
178
-		// add value to array
179
-		$this->_fields[$key][] = $value;
180
-	}
178
+        // add value to array
179
+        $this->_fields[$key][] = $value;
180
+    }
181 181
 
182
-	/**
183
-	 * Handle the array manipulation for a multi-valued field
184
-	 *
185
-	 * @param string $key
186
-	 * @param string $value
187
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
188
-	 *
189
-	 * @deprecated Use addField(...) instead
190
-	 */
191
-	public function setMultiValue($key, $value, $boost = false)
192
-	{
193
-		$this->addField($key, $value, $boost);
194
-	}
182
+    /**
183
+     * Handle the array manipulation for a multi-valued field
184
+     *
185
+     * @param string $key
186
+     * @param string $value
187
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
188
+     *
189
+     * @deprecated Use addField(...) instead
190
+     */
191
+    public function setMultiValue($key, $value, $boost = false)
192
+    {
193
+        $this->addField($key, $value, $boost);
194
+    }
195 195
 
196
-	/**
197
-	 * Get field information
198
-	 *
199
-	 * @param string $key
200
-	 * @return mixed associative array of info if field exists, false otherwise
201
-	 */
202
-	public function getField($key)
203
-	{
204
-		if (isset($this->_fields[$key]))
205
-		{
206
-			return array(
207
-				'name' => $key,
208
-				'value' => $this->_fields[$key],
209
-				'boost' => $this->getFieldBoost($key)
210
-			);
211
-		}
196
+    /**
197
+     * Get field information
198
+     *
199
+     * @param string $key
200
+     * @return mixed associative array of info if field exists, false otherwise
201
+     */
202
+    public function getField($key)
203
+    {
204
+        if (isset($this->_fields[$key]))
205
+        {
206
+            return array(
207
+                'name' => $key,
208
+                'value' => $this->_fields[$key],
209
+                'boost' => $this->getFieldBoost($key)
210
+            );
211
+        }
212 212
 
213
-		return false;
214
-	}
213
+        return false;
214
+    }
215 215
 
216
-	/**
217
-	 * Set a field value. Multi-valued fields should be set as arrays
218
-	 * or instead use the addField(...) function which will automatically
219
-	 * make sure the field is an array.
220
-	 *
221
-	 * @param string $key
222
-	 * @param mixed $value
223
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
224
-	 */
225
-	public function setField($key, $value, $boost = false)
226
-	{
227
-		$this->_fields[$key] = $value;
228
-		$this->setFieldBoost($key, $boost);
229
-	}
216
+    /**
217
+     * Set a field value. Multi-valued fields should be set as arrays
218
+     * or instead use the addField(...) function which will automatically
219
+     * make sure the field is an array.
220
+     *
221
+     * @param string $key
222
+     * @param mixed $value
223
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
224
+     */
225
+    public function setField($key, $value, $boost = false)
226
+    {
227
+        $this->_fields[$key] = $value;
228
+        $this->setFieldBoost($key, $boost);
229
+    }
230 230
 
231
-	/**
232
-	 * Get the currently set field boost for a document field
233
-	 *
234
-	 * @param string $key
235
-	 * @return float currently set field boost, false if one is not set
236
-	 */
237
-	public function getFieldBoost($key)
238
-	{
239
-		return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : false;
240
-	}
231
+    /**
232
+     * Get the currently set field boost for a document field
233
+     *
234
+     * @param string $key
235
+     * @return float currently set field boost, false if one is not set
236
+     */
237
+    public function getFieldBoost($key)
238
+    {
239
+        return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : false;
240
+    }
241 241
 
242
-	/**
243
-	 * Set the field boost for a document field
244
-	 *
245
-	 * @param string $key field name for the boost
246
-	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
247
-	 */
248
-	public function setFieldBoost($key, $boost)
249
-	{
250
-		$boost = (float) $boost;
242
+    /**
243
+     * Set the field boost for a document field
244
+     *
245
+     * @param string $key field name for the boost
246
+     * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
247
+     */
248
+    public function setFieldBoost($key, $boost)
249
+    {
250
+        $boost = (float) $boost;
251 251
 
252
-		if ($boost > 0.0)
253
-		{
254
-			$this->_fieldBoosts[$key] = $boost;
255
-		}
256
-		else
257
-		{
258
-			$this->_fieldBoosts[$key] = false;
259
-		}
260
-	}
252
+        if ($boost > 0.0)
253
+        {
254
+            $this->_fieldBoosts[$key] = $boost;
255
+        }
256
+        else
257
+        {
258
+            $this->_fieldBoosts[$key] = false;
259
+        }
260
+    }
261 261
 
262
-	/**
263
-	 * Return current field boosts, indexed by field name
264
-	 *
265
-	 * @return array
266
-	 */
267
-	public function getFieldBoosts()
268
-	{
269
-		return $this->_fieldBoosts;
270
-	}
262
+    /**
263
+     * Return current field boosts, indexed by field name
264
+     *
265
+     * @return array
266
+     */
267
+    public function getFieldBoosts()
268
+    {
269
+        return $this->_fieldBoosts;
270
+    }
271 271
 
272
-	/**
273
-	 * Get the names of all fields in this document
274
-	 *
275
-	 * @return array
276
-	 */
277
-	public function getFieldNames()
278
-	{
279
-		return array_keys($this->_fields);
280
-	}
272
+    /**
273
+     * Get the names of all fields in this document
274
+     *
275
+     * @return array
276
+     */
277
+    public function getFieldNames()
278
+    {
279
+        return array_keys($this->_fields);
280
+    }
281 281
 
282
-	/**
283
-	 * Get the values of all fields in this document
284
-	 *
285
-	 * @return array
286
-	 */
287
-	public function getFieldValues()
288
-	{
289
-		return array_values($this->_fields);
290
-	}
282
+    /**
283
+     * Get the values of all fields in this document
284
+     *
285
+     * @return array
286
+     */
287
+    public function getFieldValues()
288
+    {
289
+        return array_values($this->_fields);
290
+    }
291 291
 
292
-	/**
293
-	 * IteratorAggregate implementation function. Allows usage:
294
-	 *
295
-	 * <code>
296
-	 * foreach ($document as $key => $value)
297
-	 * {
298
-	 * 	...
299
-	 * }
300
-	 * </code>
301
-	 */
302
-	public function getIterator()
303
-	{
304
-		$arrayObject = new ArrayObject($this->_fields);
292
+    /**
293
+     * IteratorAggregate implementation function. Allows usage:
294
+     *
295
+     * <code>
296
+     * foreach ($document as $key => $value)
297
+     * {
298
+     * 	...
299
+     * }
300
+     * </code>
301
+     */
302
+    public function getIterator()
303
+    {
304
+        $arrayObject = new ArrayObject($this->_fields);
305 305
 
306
-		return $arrayObject->getIterator();
307
-	}
306
+        return $arrayObject->getIterator();
307
+    }
308 308
 
309
-	/**
310
-	 * Magic get for field values
311
-	 *
312
-	 * @param string $key
313
-	 * @return mixed
314
-	 */
315
-	public function __get($key)
316
-	{
317
-		if (isset($this->_fields[$key]))
318
-		{
319
-			return $this->_fields[$key];
320
-		}
309
+    /**
310
+     * Magic get for field values
311
+     *
312
+     * @param string $key
313
+     * @return mixed
314
+     */
315
+    public function __get($key)
316
+    {
317
+        if (isset($this->_fields[$key]))
318
+        {
319
+            return $this->_fields[$key];
320
+        }
321 321
 		
322
-		return null;
323
-	}
322
+        return null;
323
+    }
324 324
 
325
-	/**
326
-	 * Magic set for field values. Multi-valued fields should be set as arrays
327
-	 * or instead use the addField(...) function which will automatically
328
-	 * make sure the field is an array.
329
-	 *
330
-	 * @param string $key
331
-	 * @param mixed $value
332
-	 */
333
-	public function __set($key, $value)
334
-	{
335
-		$this->setField($key, $value);
336
-	}
325
+    /**
326
+     * Magic set for field values. Multi-valued fields should be set as arrays
327
+     * or instead use the addField(...) function which will automatically
328
+     * make sure the field is an array.
329
+     *
330
+     * @param string $key
331
+     * @param mixed $value
332
+     */
333
+    public function __set($key, $value)
334
+    {
335
+        $this->setField($key, $value);
336
+    }
337 337
 
338
-	/**
339
-	 * Magic isset for fields values.  Do not call directly. Allows usage:
340
-	 *
341
-	 * <code>
342
-	 * isset($document->some_field);
343
-	 * </code>
344
-	 *
345
-	 * @param string $key
346
-	 * @return boolean
347
-	 */
348
-	public function __isset($key)
349
-	{
350
-		return isset($this->_fields[$key]);
351
-	}
338
+    /**
339
+     * Magic isset for fields values.  Do not call directly. Allows usage:
340
+     *
341
+     * <code>
342
+     * isset($document->some_field);
343
+     * </code>
344
+     *
345
+     * @param string $key
346
+     * @return boolean
347
+     */
348
+    public function __isset($key)
349
+    {
350
+        return isset($this->_fields[$key]);
351
+    }
352 352
 
353
-	/**
354
-	 * Magic unset for field values. Do not call directly. Allows usage:
355
-	 *
356
-	 * <code>
357
-	 * unset($document->some_field);
358
-	 * </code>
359
-	 *
360
-	 * @param string $key
361
-	 */
362
-	public function __unset($key)
363
-	{
364
-		unset($this->_fields[$key]);
365
-		unset($this->_fieldBoosts[$key]);
366
-	}
353
+    /**
354
+     * Magic unset for field values. Do not call directly. Allows usage:
355
+     *
356
+     * <code>
357
+     * unset($document->some_field);
358
+     * </code>
359
+     *
360
+     * @param string $key
361
+     */
362
+    public function __unset($key)
363
+    {
364
+        unset($this->_fields[$key]);
365
+        unset($this->_fieldBoosts[$key]);
366
+    }
367 367
 }
368 368
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 	 *
80 80
 	 * @var array
81 81
 	 */
82
-	protected $_fields = array();
82
+	protected $_fields = array ();
83 83
 
84 84
 	/**
85 85
 	 * Document field boost values, indexed by name
86 86
 	 *
87 87
 	 * @var array array of floats
88 88
 	 */
89
-	protected $_fieldBoosts = array();
89
+	protected $_fieldBoosts = array ();
90 90
 
91 91
 	/**
92 92
 	 * Clear all boosts and fields from this document
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
 	{
96 96
 		$this->_documentBoost = false;
97 97
 
98
-		$this->_fields = array();
99
-		$this->_fieldBoosts = array();
98
+		$this->_fields = array ();
99
+		$this->_fieldBoosts = array ();
100 100
 	}
101 101
 
102 102
 	/**
@@ -156,12 +156,12 @@  discard block
 block discarded – undo
156 156
 		if (!isset($this->_fields[$key]))
157 157
 		{
158 158
 			// create holding array if this is the first value
159
-			$this->_fields[$key] = array();
159
+			$this->_fields[$key] = array ();
160 160
 		}
161 161
 		else if (!is_array($this->_fields[$key]))
162 162
 		{
163 163
 			// move existing value into array if it is not already an array
164
-			$this->_fields[$key] = array($this->_fields[$key]);
164
+			$this->_fields[$key] = array ($this->_fields[$key]);
165 165
 		}
166 166
 
167 167
 		if ($this->getFieldBoost($key) === false)
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	{
204 204
 		if (isset($this->_fields[$key]))
205 205
 		{
206
-			return array(
206
+			return array (
207 207
 				'name' => $key,
208 208
 				'value' => $this->_fields[$key],
209 209
 				'boost' => $this->getFieldBoost($key)
Please login to merge, or discard this patch.
Braces   +28 added lines, -60 removed lines patch added patch discarded remove patch
@@ -55,8 +55,7 @@  discard block
 block discarded – undo
55 55
  * }
56 56
  * </code>
57 57
  */
58
-class Apache_Solr_Document implements IteratorAggregate
59
-{
58
+class Apache_Solr_Document implements IteratorAggregate {
60 59
 	/**
61 60
 	 * SVN Revision meta data for this class
62 61
 	 */
@@ -91,8 +90,7 @@  discard block
 block discarded – undo
91 90
 	/**
92 91
 	 * Clear all boosts and fields from this document
93 92
 	 */
94
-	public function clear()
95
-	{
93
+	public function clear() {
96 94
 		$this->_documentBoost = false;
97 95
 
98 96
 		$this->_fields = array();
@@ -104,8 +102,7 @@  discard block
 block discarded – undo
104 102
 	 *
105 103
 	 * @return mixed will be false for default, or else a float
106 104
 	 */
107
-	public function getBoost()
108
-	{
105
+	public function getBoost() {
109 106
 		return $this->_documentBoost;
110 107
 	}
111 108
 
@@ -114,16 +111,12 @@  discard block
 block discarded – undo
114 111
 	 *
115 112
 	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
116 113
 	 */
117
-	public function setBoost($boost)
118
-	{
114
+	public function setBoost($boost) {
119 115
 		$boost = (float) $boost;
120 116
 
121
-		if ($boost > 0.0)
122
-		{
117
+		if ($boost > 0.0) {
123 118
 			$this->_documentBoost = $boost;
124
-		}
125
-		else
126
-		{
119
+		} else {
127 120
 			$this->_documentBoost = false;
128 121
 		}
129 122
 	}
@@ -151,26 +144,19 @@  discard block
 block discarded – undo
151 144
 	 * @param mixed $value
152 145
 	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
153 146
 	 */
154
-	public function addField($key, $value, $boost = false)
155
-	{
156
-		if (!isset($this->_fields[$key]))
157
-		{
147
+	public function addField($key, $value, $boost = false) {
148
+		if (!isset($this->_fields[$key])) {
158 149
 			// create holding array if this is the first value
159 150
 			$this->_fields[$key] = array();
160
-		}
161
-		else if (!is_array($this->_fields[$key]))
162
-		{
151
+		} else if (!is_array($this->_fields[$key])) {
163 152
 			// move existing value into array if it is not already an array
164 153
 			$this->_fields[$key] = array($this->_fields[$key]);
165 154
 		}
166 155
 
167
-		if ($this->getFieldBoost($key) === false)
168
-		{
156
+		if ($this->getFieldBoost($key) === false) {
169 157
 			// boost not already set, set it now
170 158
 			$this->setFieldBoost($key, $boost);
171
-		}
172
-		else if ((float) $boost > 0.0)
173
-		{
159
+		} else if ((float) $boost > 0.0) {
174 160
 			// multiply passed boost with current field boost - similar to SolrJ implementation
175 161
 			$this->_fieldBoosts[$key] *= (float) $boost;
176 162
 		}
@@ -188,8 +174,7 @@  discard block
 block discarded – undo
188 174
 	 *
189 175
 	 * @deprecated Use addField(...) instead
190 176
 	 */
191
-	public function setMultiValue($key, $value, $boost = false)
192
-	{
177
+	public function setMultiValue($key, $value, $boost = false) {
193 178
 		$this->addField($key, $value, $boost);
194 179
 	}
195 180
 
@@ -199,10 +184,8 @@  discard block
 block discarded – undo
199 184
 	 * @param string $key
200 185
 	 * @return mixed associative array of info if field exists, false otherwise
201 186
 	 */
202
-	public function getField($key)
203
-	{
204
-		if (isset($this->_fields[$key]))
205
-		{
187
+	public function getField($key) {
188
+		if (isset($this->_fields[$key])) {
206 189
 			return array(
207 190
 				'name' => $key,
208 191
 				'value' => $this->_fields[$key],
@@ -222,8 +205,7 @@  discard block
 block discarded – undo
222 205
 	 * @param mixed $value
223 206
 	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
224 207
 	 */
225
-	public function setField($key, $value, $boost = false)
226
-	{
208
+	public function setField($key, $value, $boost = false) {
227 209
 		$this->_fields[$key] = $value;
228 210
 		$this->setFieldBoost($key, $boost);
229 211
 	}
@@ -234,8 +216,7 @@  discard block
 block discarded – undo
234 216
 	 * @param string $key
235 217
 	 * @return float currently set field boost, false if one is not set
236 218
 	 */
237
-	public function getFieldBoost($key)
238
-	{
219
+	public function getFieldBoost($key) {
239 220
 		return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : false;
240 221
 	}
241 222
 
@@ -245,16 +226,12 @@  discard block
 block discarded – undo
245 226
 	 * @param string $key field name for the boost
246 227
 	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
247 228
 	 */
248
-	public function setFieldBoost($key, $boost)
249
-	{
229
+	public function setFieldBoost($key, $boost) {
250 230
 		$boost = (float) $boost;
251 231
 
252
-		if ($boost > 0.0)
253
-		{
232
+		if ($boost > 0.0) {
254 233
 			$this->_fieldBoosts[$key] = $boost;
255
-		}
256
-		else
257
-		{
234
+		} else {
258 235
 			$this->_fieldBoosts[$key] = false;
259 236
 		}
260 237
 	}
@@ -264,8 +241,7 @@  discard block
 block discarded – undo
264 241
 	 *
265 242
 	 * @return array
266 243
 	 */
267
-	public function getFieldBoosts()
268
-	{
244
+	public function getFieldBoosts() {
269 245
 		return $this->_fieldBoosts;
270 246
 	}
271 247
 
@@ -274,8 +250,7 @@  discard block
 block discarded – undo
274 250
 	 *
275 251
 	 * @return array
276 252
 	 */
277
-	public function getFieldNames()
278
-	{
253
+	public function getFieldNames() {
279 254
 		return array_keys($this->_fields);
280 255
 	}
281 256
 
@@ -284,8 +259,7 @@  discard block
 block discarded – undo
284 259
 	 *
285 260
 	 * @return array
286 261
 	 */
287
-	public function getFieldValues()
288
-	{
262
+	public function getFieldValues() {
289 263
 		return array_values($this->_fields);
290 264
 	}
291 265
 
@@ -299,8 +273,7 @@  discard block
 block discarded – undo
299 273
 	 * }
300 274
 	 * </code>
301 275
 	 */
302
-	public function getIterator()
303
-	{
276
+	public function getIterator() {
304 277
 		$arrayObject = new ArrayObject($this->_fields);
305 278
 
306 279
 		return $arrayObject->getIterator();
@@ -312,10 +285,8 @@  discard block
 block discarded – undo
312 285
 	 * @param string $key
313 286
 	 * @return mixed
314 287
 	 */
315
-	public function __get($key)
316
-	{
317
-		if (isset($this->_fields[$key]))
318
-		{
288
+	public function __get($key) {
289
+		if (isset($this->_fields[$key])) {
319 290
 			return $this->_fields[$key];
320 291
 		}
321 292
 		
@@ -330,8 +301,7 @@  discard block
 block discarded – undo
330 301
 	 * @param string $key
331 302
 	 * @param mixed $value
332 303
 	 */
333
-	public function __set($key, $value)
334
-	{
304
+	public function __set($key, $value) {
335 305
 		$this->setField($key, $value);
336 306
 	}
337 307
 
@@ -345,8 +315,7 @@  discard block
 block discarded – undo
345 315
 	 * @param string $key
346 316
 	 * @return boolean
347 317
 	 */
348
-	public function __isset($key)
349
-	{
318
+	public function __isset($key) {
350 319
 		return isset($this->_fields[$key]);
351 320
 	}
352 321
 
@@ -359,8 +328,7 @@  discard block
 block discarded – undo
359 328
 	 *
360 329
 	 * @param string $key
361 330
 	 */
362
-	public function __unset($key)
363
-	{
331
+	public function __unset($key) {
364 332
 		unset($this->_fields[$key]);
365 333
 		unset($this->_fieldBoosts[$key]);
366 334
 	}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @var float
74 74
 	 */
75
-	protected $_documentBoost = false;
75
+	protected $_documentBoost = FALSE;
76 76
 
77 77
 	/**
78 78
 	 * Document field values, indexed by name
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 */
94 94
 	public function clear()
95 95
 	{
96
-		$this->_documentBoost = false;
96
+		$this->_documentBoost = FALSE;
97 97
 
98 98
 		$this->_fields = array();
99 99
 		$this->_fieldBoosts = array();
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		}
125 125
 		else
126 126
 		{
127
-			$this->_documentBoost = false;
127
+			$this->_documentBoost = FALSE;
128 128
 		}
129 129
 	}
130 130
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 * @param mixed $value
152 152
 	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
153 153
 	 */
154
-	public function addField($key, $value, $boost = false)
154
+	public function addField($key, $value, $boost = FALSE)
155 155
 	{
156 156
 		if (!isset($this->_fields[$key]))
157 157
 		{
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 			$this->_fields[$key] = array($this->_fields[$key]);
165 165
 		}
166 166
 
167
-		if ($this->getFieldBoost($key) === false)
167
+		if ($this->getFieldBoost($key) === FALSE)
168 168
 		{
169 169
 			// boost not already set, set it now
170 170
 			$this->setFieldBoost($key, $boost);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 *
189 189
 	 * @deprecated Use addField(...) instead
190 190
 	 */
191
-	public function setMultiValue($key, $value, $boost = false)
191
+	public function setMultiValue($key, $value, $boost = FALSE)
192 192
 	{
193 193
 		$this->addField($key, $value, $boost);
194 194
 	}
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 			);
211 211
 		}
212 212
 
213
-		return false;
213
+		return FALSE;
214 214
 	}
215 215
 
216 216
 	/**
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 	 * @param mixed $value
223 223
 	 * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
224 224
 	 */
225
-	public function setField($key, $value, $boost = false)
225
+	public function setField($key, $value, $boost = FALSE)
226 226
 	{
227 227
 		$this->_fields[$key] = $value;
228 228
 		$this->setFieldBoost($key, $boost);
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 	 */
237 237
 	public function getFieldBoost($key)
238 238
 	{
239
-		return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : false;
239
+		return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : FALSE;
240 240
 	}
241 241
 
242 242
 	/**
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 		}
256 256
 		else
257 257
 		{
258
-			$this->_fieldBoosts[$key] = false;
258
+			$this->_fieldBoosts[$key] = FALSE;
259 259
 		}
260 260
 	}
261 261
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 			return $this->_fields[$key];
320 320
 		}
321 321
 		
322
-		return null;
322
+		return NULL;
323 323
 	}
324 324
 
325 325
 	/**
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/InvalidArgumentException.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
 
39 39
 class Apache_Solr_InvalidArgumentException extends Apache_Solr_Exception
40 40
 {
41
-	/**
42
-	 * SVN Revision meta data for this class
43
-	 */
44
-	const SVN_REVISION = '$Revision: 54 $';
41
+    /**
42
+     * SVN Revision meta data for this class
43
+     */
44
+    const SVN_REVISION = '$Revision: 54 $';
45 45
 
46
-	/**
47
-	 * SVN ID meta data for this class
48
-	 */
49
-	const SVN_ID = '$Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
46
+    /**
47
+     * SVN ID meta data for this class
48
+     */
49
+    const SVN_ID = '$Id: InvalidArgumentException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@
 block discarded – undo
36 36
  * @author Donovan Jimenez <[email protected]>
37 37
  */
38 38
 
39
-class Apache_Solr_InvalidArgumentException extends Apache_Solr_Exception
40
-{
39
+class Apache_Solr_InvalidArgumentException extends Apache_Solr_Exception {
41 40
 	/**
42 41
 	 * SVN Revision meta data for this class
43 42
 	 */
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/NoServiceAvailableException.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
 
39 39
 class Apache_Solr_NoServiceAvailableException extends Apache_Solr_Exception
40 40
 {
41
-	/**
42
-	 * SVN Revision meta data for this class
43
-	 */
44
-	const SVN_REVISION = '$Revision: 54 $';
41
+    /**
42
+     * SVN Revision meta data for this class
43
+     */
44
+    const SVN_REVISION = '$Revision: 54 $';
45 45
 
46
-	/**
47
-	 * SVN ID meta data for this class
48
-	 */
49
-	const SVN_ID = '$Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
46
+    /**
47
+     * SVN ID meta data for this class
48
+     */
49
+    const SVN_ID = '$Id: NoServiceAvailableException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@
 block discarded – undo
36 36
  * @author Donovan Jimenez <[email protected]>
37 37
  */
38 38
 
39
-class Apache_Solr_NoServiceAvailableException extends Apache_Solr_Exception
40
-{
39
+class Apache_Solr_NoServiceAvailableException extends Apache_Solr_Exception {
41 40
 	/**
42 41
 	 * SVN Revision meta data for this class
43 42
 	 */
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/Service/Balancer.php 4 patches
Indentation   +857 added lines, -857 removed lines patch added patch discarded remove patch
@@ -50,865 +50,865 @@
 block discarded – undo
50 50
  */
51 51
 class Apache_Solr_Service_Balancer
52 52
 {
53
-	/**
54
-	 * SVN Revision meta data for this class
55
-	 */
56
-	const SVN_REVISION = '$Revision: 54 $';
57
-
58
-	/**
59
-	 * SVN ID meta data for this class
60
-	 */
61
-	const SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
62
-
63
-	protected $_createDocuments = true;
64
-
65
-	protected $_readableServices = array();
66
-	protected $_writeableServices = array();
67
-
68
-	protected $_currentReadService = null;
69
-	protected $_currentWriteService = null;
70
-
71
-	protected $_readPingTimeout = 2;
72
-	protected $_writePingTimeout = 4;
73
-
74
-	// Configuration for server selection backoff intervals
75
-	protected $_useBackoff = false;		// Set to true to use more resillient write server selection
76
-	protected $_backoffLimit = 600;		// 10 minute default maximum
77
-	protected $_backoffEscalation = 2.0; 	// Rate at which to increase backoff period
78
-	protected $_defaultBackoff = 2.0;		// Default backoff interval
79
-
80
-	/**
81
-	 * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
82
-	 *
83
-	 * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
84
-	 *
85
-	 * @param string $value
86
-	 * @return string
87
-	 */
88
-	static public function escape($value)
89
-	{
90
-		return Apache_Solr_Service::escape($value);
91
-	}
92
-
93
-	/**
94
-	 * Escape a value meant to be contained in a phrase for special query characters
95
-	 *
96
-	 * @param string $value
97
-	 * @return string
98
-	 */
99
-	static public function escapePhrase($value)
100
-	{
101
-		return Apache_Solr_Service::escapePhrase($value);
102
-	}
103
-
104
-	/**
105
-	 * Convenience function for creating phrase syntax from a value
106
-	 *
107
-	 * @param string $value
108
-	 * @return string
109
-	 */
110
-	static public function phrase($value)
111
-	{
112
-		return Apache_Solr_Service::phrase($value);
113
-	}
114
-
115
-	/**
116
-	 * Constructor. Takes arrays of read and write service instances or descriptions
117
-	 *
118
-	 * @param array $readableServices
119
-	 * @param array $writeableServices
120
-	 */
121
-	public function __construct($readableServices = array(), $writeableServices = array())
122
-	{
123
-		//setup readable services
124
-		foreach ($readableServices as $service)
125
-		{
126
-			$this->addReadService($service);
127
-		}
128
-
129
-		//setup writeable services
130
-		foreach ($writeableServices as $service)
131
-		{
132
-			$this->addWriteService($service);
133
-		}
134
-	}
135
-
136
-	public function setReadPingTimeout($timeout)
137
-	{
138
-		$this->_readPingTimeout = $timeout;
139
-	}
140
-
141
-	public function setWritePingTimeout($timeout)
142
-	{
143
-		$this->_writePingTimeout = $timeout;
144
-	}
145
-
146
-	public function setUseBackoff($enable)
147
-	{
148
-		$this->_useBackoff = $enable;
149
-	}
150
-
151
-	/**
152
-	 * Generates a service ID
153
-	 *
154
-	 * @param string $host
155
-	 * @param integer $port
156
-	 * @param string $path
157
-	 * @return string
158
-	 */
159
-	protected function _getServiceId($host, $port, $path)
160
-	{
161
-		return $host . ':' . $port . $path;
162
-	}
163
-
164
-	/**
165
-	 * Adds a service instance or service descriptor (if it is already
166
-	 * not added)
167
-	 *
168
-	 * @param mixed $service
169
-	 *
170
-	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
171
-	 */
172
-	public function addReadService($service)
173
-	{
174
-		if ($service instanceof Apache_Solr_Service)
175
-		{
176
-			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
177
-
178
-			$this->_readableServices[$id] = $service;
179
-		}
180
-		else if (is_array($service))
181
-		{
182
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
183
-			{
184
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
185
-
186
-				$this->_readableServices[$id] = $service;
187
-			}
188
-			else
189
-			{
190
-				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
191
-			}
192
-		}
193
-	}
194
-
195
-	/**
196
-	 * Removes a service instance or descriptor from the available services
197
-	 *
198
-	 * @param mixed $service
199
-	 *
200
-	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
201
-	 */
202
-	public function removeReadService($service)
203
-	{
204
-		$id = '';
205
-
206
-		if ($service instanceof Apache_Solr_Service)
207
-		{
208
-			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
209
-		}
210
-		else if (is_array($service))
211
-		{
212
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
213
-			{
214
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
215
-			}
216
-			else
217
-			{
218
-				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
219
-			}
220
-		}
221
-		else if (is_string($service))
222
-		{
223
-			$id = $service;
224
-		}
225
-
226
-		if ($id && isset($this->_readableServices[$id]))
227
-		{
228
-			unset($this->_readableServices[$id]);
229
-		}
230
-	}
231
-
232
-	/**
233
-	 * Adds a service instance or service descriptor (if it is already
234
-	 * not added)
235
-	 *
236
-	 * @param mixed $service
237
-	 *
238
-	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
239
-	 */
240
-	public function addWriteService($service)
241
-	{
242
-		if ($service instanceof Apache_Solr_Service)
243
-		{
244
-			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
245
-
246
-			$this->_writeableServices[$id] = $service;
247
-		}
248
-		else if (is_array($service))
249
-		{
250
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
251
-			{
252
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
253
-
254
-				$this->_writeableServices[$id] = $service;
255
-			}
256
-			else
257
-			{
258
-				throw new Apache_Solr_InvalidArgumentException('A Writeable Service description array does not have all required elements of host, port, and path');
259
-			}
260
-		}
261
-	}
262
-
263
-	/**
264
-	 * Removes a service instance or descriptor from the available services
265
-	 *
266
-	 * @param mixed $service
267
-	 *
268
-	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
269
-	 */
270
-	public function removeWriteService($service)
271
-	{
272
-		$id = '';
273
-
274
-		if ($service instanceof Apache_Solr_Service)
275
-		{
276
-			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
277
-		}
278
-		else if (is_array($service))
279
-		{
280
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
281
-			{
282
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
283
-			}
284
-			else
285
-			{
286
-				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
287
-			}
288
-		}
289
-		else if (is_string($service))
290
-		{
291
-			$id = $service;
292
-		}
293
-
294
-		if ($id && isset($this->_writeableServices[$id]))
295
-		{
296
-			unset($this->_writeableServices[$id]);
297
-		}
298
-	}
299
-
300
-	/**
301
-	 * Iterate through available read services and select the first with a ping
302
-	 * that satisfies configured timeout restrictions (or the default)
303
-	 *
304
-	 * @return Apache_Solr_Service
305
-	 *
306
-	 * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
307
-	 */
308
-	protected function _selectReadService($forceSelect = false)
309
-	{
310
-		if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect)
311
-		{
312
-			if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect)
313
-			{
314
-				// we probably had a communication error, ping the current read service, remove it if it times out
315
-				if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false)
316
-				{
317
-					$this->removeReadService($this->_currentReadService);
318
-				}
319
-			}
320
-
321
-			if (count($this->_readableServices))
322
-			{
323
-				// select one of the read services at random
324
-				$ids = array_keys($this->_readableServices);
325
-
326
-				$id = $ids[rand(0, count($ids) - 1)];
327
-				$service = $this->_readableServices[$id];
328
-
329
-				if (is_array($service))
330
-				{
331
-					//convert the array definition to a client object
332
-					$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
333
-					$this->_readableServices[$id] = $service;
334
-				}
335
-
336
-				$service->setCreateDocuments($this->_createDocuments);
337
-				$this->_currentReadService = $id;
338
-			}
339
-			else
340
-			{
341
-				throw new Apache_Solr_NoServiceAvailableException('No read services were available');
342
-			}
343
-		}
344
-
345
-		return $this->_readableServices[$this->_currentReadService];
346
-	}
347
-
348
-	/**
349
-	 * Iterate through available write services and select the first with a ping
350
-	 * that satisfies configured timeout restrictions (or the default)
351
-	 *
352
-	 * @return Apache_Solr_Service
353
-	 *
354
-	 * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
355
-	 */
356
-	protected function _selectWriteService($forceSelect = false)
357
-	{
358
-		if($this->_useBackoff)
359
-		{
360
-			return $this->_selectWriteServiceSafe($forceSelect);
361
-		}
362
-
363
-		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
364
-		{
365
-			if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect)
366
-			{
367
-				// we probably had a communication error, ping the current read service, remove it if it times out
368
-				if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false)
369
-				{
370
-					$this->removeWriteService($this->_currentWriteService);
371
-				}
372
-			}
373
-
374
-			if (count($this->_writeableServices))
375
-			{
376
-				// select one of the read services at random
377
-				$ids = array_keys($this->_writeableServices);
378
-
379
-				$id = $ids[rand(0, count($ids) - 1)];
380
-				$service = $this->_writeableServices[$id];
381
-
382
-				if (is_array($service))
383
-				{
384
-					//convert the array definition to a client object
385
-					$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
386
-					$this->_writeableServices[$id] = $service;
387
-				}
388
-
389
-				$this->_currentWriteService = $id;
390
-			}
391
-			else
392
-			{
393
-				throw new Apache_Solr_NoServiceAvailableException('No write services were available');
394
-			}
395
-		}
396
-
397
-		return $this->_writeableServices[$this->_currentWriteService];
398
-	}
399
-
400
-	/**
401
-	 * Iterate through available write services and select the first with a ping
402
-	 * that satisfies configured timeout restrictions (or the default).  The
403
-	 * timeout period will increase until a connection is made or the limit is
404
-	 * reached.   This will allow for increased reliability with heavily loaded
405
-	 * server(s).
406
-	 *
407
-	 * @return Apache_Solr_Service
408
-	 *
409
-	 * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
410
-	 */
411
-
412
-	protected function _selectWriteServiceSafe($forceSelect = false)
413
-	{
414
-		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
415
-		{
416
-			if (count($this->_writeableServices))
417
-			{
418
-				$backoff = $this->_defaultBackoff;
419
-
420
-				do {
421
-					// select one of the read services at random
422
-					$ids = array_keys($this->_writeableServices);
423
-
424
-					$id = $ids[rand(0, count($ids) - 1)];
425
-					$service = $this->_writeableServices[$id];
426
-
427
-					if (is_array($service))
428
-					{
429
-						//convert the array definition to a client object
430
-						$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
431
-						$this->_writeableServices[$id] = $service;
432
-					}
433
-
434
-					$this->_currentWriteService = $id;
435
-
436
-					$backoff *= $this->_backoffEscalation;
437
-
438
-					if($backoff > $this->_backoffLimit)
439
-					{
440
-						throw new Apache_Solr_NoServiceAvailableException('No write services were available.  All timeouts exceeded.');
441
-					}
442
-
443
-				} while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false);
444
-			}
445
-			else
446
-			{
447
-				throw new Apache_Solr_NoServiceAvailableException('No write services were available');
448
-			}
449
-		}
450
-
451
-		return $this->_writeableServices[$this->_currentWriteService];
452
-	}
453
-
454
-	/**
455
-	 * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
456
-	 * parse the response and create {@link Apache_Solr_Document} instances in place.
457
-	 *
458
-	 * @param boolean $createDocuments
459
-	 */
460
-	public function setCreateDocuments($createDocuments)
461
-	{
462
-		$this->_createDocuments = (bool) $createDocuments;
463
-
464
-		// set on current read service
465
-		if ($this->_currentReadService)
466
-		{
467
-			$service = $this->_selectReadService();
468
-			$service->setCreateDocuments($createDocuments);
469
-		}
470
-	}
471
-
472
-	/**
473
-	 * Get the current state of the create documents flag.
474
-	 *
475
-	 * @return boolean
476
-	 */
477
-	public function getCreateDocuments()
478
-	{
479
-		return $this->_createDocuments;
480
-	}
53
+    /**
54
+     * SVN Revision meta data for this class
55
+     */
56
+    const SVN_REVISION = '$Revision: 54 $';
57
+
58
+    /**
59
+     * SVN ID meta data for this class
60
+     */
61
+    const SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
62
+
63
+    protected $_createDocuments = true;
64
+
65
+    protected $_readableServices = array();
66
+    protected $_writeableServices = array();
67
+
68
+    protected $_currentReadService = null;
69
+    protected $_currentWriteService = null;
70
+
71
+    protected $_readPingTimeout = 2;
72
+    protected $_writePingTimeout = 4;
73
+
74
+    // Configuration for server selection backoff intervals
75
+    protected $_useBackoff = false;		// Set to true to use more resillient write server selection
76
+    protected $_backoffLimit = 600;		// 10 minute default maximum
77
+    protected $_backoffEscalation = 2.0; 	// Rate at which to increase backoff period
78
+    protected $_defaultBackoff = 2.0;		// Default backoff interval
79
+
80
+    /**
81
+     * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
82
+     *
83
+     * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
84
+     *
85
+     * @param string $value
86
+     * @return string
87
+     */
88
+    static public function escape($value)
89
+    {
90
+        return Apache_Solr_Service::escape($value);
91
+    }
92
+
93
+    /**
94
+     * Escape a value meant to be contained in a phrase for special query characters
95
+     *
96
+     * @param string $value
97
+     * @return string
98
+     */
99
+    static public function escapePhrase($value)
100
+    {
101
+        return Apache_Solr_Service::escapePhrase($value);
102
+    }
103
+
104
+    /**
105
+     * Convenience function for creating phrase syntax from a value
106
+     *
107
+     * @param string $value
108
+     * @return string
109
+     */
110
+    static public function phrase($value)
111
+    {
112
+        return Apache_Solr_Service::phrase($value);
113
+    }
114
+
115
+    /**
116
+     * Constructor. Takes arrays of read and write service instances or descriptions
117
+     *
118
+     * @param array $readableServices
119
+     * @param array $writeableServices
120
+     */
121
+    public function __construct($readableServices = array(), $writeableServices = array())
122
+    {
123
+        //setup readable services
124
+        foreach ($readableServices as $service)
125
+        {
126
+            $this->addReadService($service);
127
+        }
128
+
129
+        //setup writeable services
130
+        foreach ($writeableServices as $service)
131
+        {
132
+            $this->addWriteService($service);
133
+        }
134
+    }
135
+
136
+    public function setReadPingTimeout($timeout)
137
+    {
138
+        $this->_readPingTimeout = $timeout;
139
+    }
140
+
141
+    public function setWritePingTimeout($timeout)
142
+    {
143
+        $this->_writePingTimeout = $timeout;
144
+    }
145
+
146
+    public function setUseBackoff($enable)
147
+    {
148
+        $this->_useBackoff = $enable;
149
+    }
150
+
151
+    /**
152
+     * Generates a service ID
153
+     *
154
+     * @param string $host
155
+     * @param integer $port
156
+     * @param string $path
157
+     * @return string
158
+     */
159
+    protected function _getServiceId($host, $port, $path)
160
+    {
161
+        return $host . ':' . $port . $path;
162
+    }
163
+
164
+    /**
165
+     * Adds a service instance or service descriptor (if it is already
166
+     * not added)
167
+     *
168
+     * @param mixed $service
169
+     *
170
+     * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
171
+     */
172
+    public function addReadService($service)
173
+    {
174
+        if ($service instanceof Apache_Solr_Service)
175
+        {
176
+            $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
177
+
178
+            $this->_readableServices[$id] = $service;
179
+        }
180
+        else if (is_array($service))
181
+        {
182
+            if (isset($service['host']) && isset($service['port']) && isset($service['path']))
183
+            {
184
+                $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
185
+
186
+                $this->_readableServices[$id] = $service;
187
+            }
188
+            else
189
+            {
190
+                throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
191
+            }
192
+        }
193
+    }
194
+
195
+    /**
196
+     * Removes a service instance or descriptor from the available services
197
+     *
198
+     * @param mixed $service
199
+     *
200
+     * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
201
+     */
202
+    public function removeReadService($service)
203
+    {
204
+        $id = '';
205
+
206
+        if ($service instanceof Apache_Solr_Service)
207
+        {
208
+            $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
209
+        }
210
+        else if (is_array($service))
211
+        {
212
+            if (isset($service['host']) && isset($service['port']) && isset($service['path']))
213
+            {
214
+                $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
215
+            }
216
+            else
217
+            {
218
+                throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
219
+            }
220
+        }
221
+        else if (is_string($service))
222
+        {
223
+            $id = $service;
224
+        }
225
+
226
+        if ($id && isset($this->_readableServices[$id]))
227
+        {
228
+            unset($this->_readableServices[$id]);
229
+        }
230
+    }
231
+
232
+    /**
233
+     * Adds a service instance or service descriptor (if it is already
234
+     * not added)
235
+     *
236
+     * @param mixed $service
237
+     *
238
+     * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
239
+     */
240
+    public function addWriteService($service)
241
+    {
242
+        if ($service instanceof Apache_Solr_Service)
243
+        {
244
+            $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
245
+
246
+            $this->_writeableServices[$id] = $service;
247
+        }
248
+        else if (is_array($service))
249
+        {
250
+            if (isset($service['host']) && isset($service['port']) && isset($service['path']))
251
+            {
252
+                $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
253
+
254
+                $this->_writeableServices[$id] = $service;
255
+            }
256
+            else
257
+            {
258
+                throw new Apache_Solr_InvalidArgumentException('A Writeable Service description array does not have all required elements of host, port, and path');
259
+            }
260
+        }
261
+    }
262
+
263
+    /**
264
+     * Removes a service instance or descriptor from the available services
265
+     *
266
+     * @param mixed $service
267
+     *
268
+     * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
269
+     */
270
+    public function removeWriteService($service)
271
+    {
272
+        $id = '';
273
+
274
+        if ($service instanceof Apache_Solr_Service)
275
+        {
276
+            $id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
277
+        }
278
+        else if (is_array($service))
279
+        {
280
+            if (isset($service['host']) && isset($service['port']) && isset($service['path']))
281
+            {
282
+                $id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
283
+            }
284
+            else
285
+            {
286
+                throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
287
+            }
288
+        }
289
+        else if (is_string($service))
290
+        {
291
+            $id = $service;
292
+        }
293
+
294
+        if ($id && isset($this->_writeableServices[$id]))
295
+        {
296
+            unset($this->_writeableServices[$id]);
297
+        }
298
+    }
299
+
300
+    /**
301
+     * Iterate through available read services and select the first with a ping
302
+     * that satisfies configured timeout restrictions (or the default)
303
+     *
304
+     * @return Apache_Solr_Service
305
+     *
306
+     * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
307
+     */
308
+    protected function _selectReadService($forceSelect = false)
309
+    {
310
+        if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect)
311
+        {
312
+            if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect)
313
+            {
314
+                // we probably had a communication error, ping the current read service, remove it if it times out
315
+                if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false)
316
+                {
317
+                    $this->removeReadService($this->_currentReadService);
318
+                }
319
+            }
320
+
321
+            if (count($this->_readableServices))
322
+            {
323
+                // select one of the read services at random
324
+                $ids = array_keys($this->_readableServices);
325
+
326
+                $id = $ids[rand(0, count($ids) - 1)];
327
+                $service = $this->_readableServices[$id];
328
+
329
+                if (is_array($service))
330
+                {
331
+                    //convert the array definition to a client object
332
+                    $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
333
+                    $this->_readableServices[$id] = $service;
334
+                }
335
+
336
+                $service->setCreateDocuments($this->_createDocuments);
337
+                $this->_currentReadService = $id;
338
+            }
339
+            else
340
+            {
341
+                throw new Apache_Solr_NoServiceAvailableException('No read services were available');
342
+            }
343
+        }
344
+
345
+        return $this->_readableServices[$this->_currentReadService];
346
+    }
347
+
348
+    /**
349
+     * Iterate through available write services and select the first with a ping
350
+     * that satisfies configured timeout restrictions (or the default)
351
+     *
352
+     * @return Apache_Solr_Service
353
+     *
354
+     * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
355
+     */
356
+    protected function _selectWriteService($forceSelect = false)
357
+    {
358
+        if($this->_useBackoff)
359
+        {
360
+            return $this->_selectWriteServiceSafe($forceSelect);
361
+        }
362
+
363
+        if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
364
+        {
365
+            if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect)
366
+            {
367
+                // we probably had a communication error, ping the current read service, remove it if it times out
368
+                if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false)
369
+                {
370
+                    $this->removeWriteService($this->_currentWriteService);
371
+                }
372
+            }
373
+
374
+            if (count($this->_writeableServices))
375
+            {
376
+                // select one of the read services at random
377
+                $ids = array_keys($this->_writeableServices);
378
+
379
+                $id = $ids[rand(0, count($ids) - 1)];
380
+                $service = $this->_writeableServices[$id];
381
+
382
+                if (is_array($service))
383
+                {
384
+                    //convert the array definition to a client object
385
+                    $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
386
+                    $this->_writeableServices[$id] = $service;
387
+                }
388
+
389
+                $this->_currentWriteService = $id;
390
+            }
391
+            else
392
+            {
393
+                throw new Apache_Solr_NoServiceAvailableException('No write services were available');
394
+            }
395
+        }
396
+
397
+        return $this->_writeableServices[$this->_currentWriteService];
398
+    }
399
+
400
+    /**
401
+     * Iterate through available write services and select the first with a ping
402
+     * that satisfies configured timeout restrictions (or the default).  The
403
+     * timeout period will increase until a connection is made or the limit is
404
+     * reached.   This will allow for increased reliability with heavily loaded
405
+     * server(s).
406
+     *
407
+     * @return Apache_Solr_Service
408
+     *
409
+     * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
410
+     */
411
+
412
+    protected function _selectWriteServiceSafe($forceSelect = false)
413
+    {
414
+        if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
415
+        {
416
+            if (count($this->_writeableServices))
417
+            {
418
+                $backoff = $this->_defaultBackoff;
419
+
420
+                do {
421
+                    // select one of the read services at random
422
+                    $ids = array_keys($this->_writeableServices);
423
+
424
+                    $id = $ids[rand(0, count($ids) - 1)];
425
+                    $service = $this->_writeableServices[$id];
426
+
427
+                    if (is_array($service))
428
+                    {
429
+                        //convert the array definition to a client object
430
+                        $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
431
+                        $this->_writeableServices[$id] = $service;
432
+                    }
433
+
434
+                    $this->_currentWriteService = $id;
435
+
436
+                    $backoff *= $this->_backoffEscalation;
437
+
438
+                    if($backoff > $this->_backoffLimit)
439
+                    {
440
+                        throw new Apache_Solr_NoServiceAvailableException('No write services were available.  All timeouts exceeded.');
441
+                    }
442
+
443
+                } while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false);
444
+            }
445
+            else
446
+            {
447
+                throw new Apache_Solr_NoServiceAvailableException('No write services were available');
448
+            }
449
+        }
450
+
451
+        return $this->_writeableServices[$this->_currentWriteService];
452
+    }
453
+
454
+    /**
455
+     * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
456
+     * parse the response and create {@link Apache_Solr_Document} instances in place.
457
+     *
458
+     * @param boolean $createDocuments
459
+     */
460
+    public function setCreateDocuments($createDocuments)
461
+    {
462
+        $this->_createDocuments = (bool) $createDocuments;
463
+
464
+        // set on current read service
465
+        if ($this->_currentReadService)
466
+        {
467
+            $service = $this->_selectReadService();
468
+            $service->setCreateDocuments($createDocuments);
469
+        }
470
+    }
471
+
472
+    /**
473
+     * Get the current state of the create documents flag.
474
+     *
475
+     * @return boolean
476
+     */
477
+    public function getCreateDocuments()
478
+    {
479
+        return $this->_createDocuments;
480
+    }
481 481
 	
482
-	/**
483
-	 * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
484
-	 * should be a complete and well formed "add" xml document.
485
-	 *
486
-	 * @param string $rawPost
487
-	 * @return Apache_Solr_Response
488
-	 *
489
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
490
-	 */
491
-	public function add($rawPost)
492
-	{
493
-		$service = $this->_selectWriteService();
494
-
495
-		do
496
-		{
497
-			try
498
-			{
499
-				return $service->add($rawPost);
500
-			}
501
-			catch (Apache_Solr_HttpTransportException $e)
502
-			{
503
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
504
-				{
505
-					throw $e;
506
-				}
507
-			}
508
-
509
-			$service = $this->_selectWriteService(true);
510
-		} while ($service);
511
-
512
-		return false;
513
-	}
514
-
515
-	/**
516
-	 * Add a Solr Document to the index
517
-	 *
518
-	 * @param Apache_Solr_Document $document
519
-	 * @param boolean $allowDups
520
-	 * @param boolean $overwritePending
521
-	 * @param boolean $overwriteCommitted
522
-	 * @return Apache_Solr_Response
523
-	 *
524
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
525
-	 */
526
-	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
527
-	{
528
-		$service = $this->_selectWriteService();
529
-
530
-		do
531
-		{
532
-			try
533
-			{
534
-				return $service->addDocument($document, $allowDups, $overwritePending, $overwriteCommitted);
535
-			}
536
-			catch (Apache_Solr_HttpTransportException $e)
537
-			{
538
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
539
-				{
540
-					throw $e;
541
-				}
542
-			}
543
-
544
-			$service = $this->_selectWriteService(true);
545
-		} while ($service);
546
-
547
-		return false;
548
-	}
549
-
550
-	/**
551
-	 * Add an array of Solr Documents to the index all at once
552
-	 *
553
-	 * @param array $documents Should be an array of Apache_Solr_Document instances
554
-	 * @param boolean $allowDups
555
-	 * @param boolean $overwritePending
556
-	 * @param boolean $overwriteCommitted
557
-	 * @return Apache_Solr_Response
558
-	 *
559
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
560
-	 */
561
-	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
562
-	{
563
-		$service = $this->_selectWriteService();
564
-
565
-		do
566
-		{
567
-			try
568
-			{
569
-				return $service->addDocuments($documents, $allowDups, $overwritePending, $overwriteCommitted);
570
-			}
571
-			catch (Apache_Solr_HttpTransportException $e)
572
-			{
573
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
574
-				{
575
-					throw $e;
576
-				}
577
-			}
578
-
579
-			$service = $this->_selectWriteService(true);
580
-		} while ($service);
581
-
582
-		return false;
583
-	}
584
-
585
-	/**
586
-	 * Send a commit command.  Will be synchronous unless both wait parameters are set
587
-	 * to false.
588
-	 *
589
-	 * @param boolean $waitFlush
590
-	 * @param boolean $waitSearcher
591
-	 * @return Apache_Solr_Response
592
-	 *
593
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
594
-	 */
595
-	public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
596
-	{
597
-		$service = $this->_selectWriteService();
598
-
599
-		do
600
-		{
601
-			try
602
-			{
603
-				return $service->commit($optimize, $waitFlush, $waitSearcher, $timeout);
604
-			}
605
-			catch (Apache_Solr_HttpTransportException $e)
606
-			{
607
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
608
-				{
609
-					throw $e;
610
-				}
611
-			}
612
-
613
-			$service = $this->_selectWriteService(true);
614
-		} while ($service);
615
-
616
-		return false;
617
-	}
618
-
619
-	/**
620
-	 * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
621
-	 * a complete and well formed "delete" xml document
622
-	 *
623
-	 * @param string $rawPost
624
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
625
-	 * @return Apache_Solr_Response
626
-	 *
627
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
628
-	 */
629
-	public function delete($rawPost, $timeout = 3600)
630
-	{
631
-		$service = $this->_selectWriteService();
632
-
633
-		do
634
-		{
635
-			try
636
-			{
637
-				return $service->delete($rawPost, $timeout);
638
-			}
639
-			catch (Apache_Solr_HttpTransportException $e)
640
-			{
641
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
642
-				{
643
-					throw $e;
644
-				}
645
-			}
646
-
647
-			$service = $this->_selectWriteService(true);
648
-		} while ($service);
649
-
650
-		return false;
651
-	}
652
-
653
-	/**
654
-	 * Create a delete document based on document ID
655
-	 *
656
-	 * @param string $id
657
-	 * @param boolean $fromPending
658
-	 * @param boolean $fromCommitted
659
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
660
-	 * @return Apache_Solr_Response
661
-	 *
662
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
663
-	 */
664
-	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
665
-	{
666
-		$service = $this->_selectWriteService();
667
-
668
-		do
669
-		{
670
-			try
671
-			{
672
-				return $service->deleteById($id, $fromPending, $fromCommitted, $timeout);
673
-			}
674
-			catch (Apache_Solr_HttpTransportException $e)
675
-			{
676
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
677
-				{
678
-					throw $e;
679
-				}
680
-			}
681
-
682
-			$service = $this->_selectWriteService(true);
683
-		} while ($service);
684
-
685
-		return false;
686
-	}
687
-
688
-	/**
689
-	 * Create and post a delete document based on multiple document IDs.
690
-	 *
691
-	 * @param array $ids Expected to be utf-8 encoded strings
692
-	 * @param boolean $fromPending
693
-	 * @param boolean $fromCommitted
694
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
695
-	 * @return Apache_Solr_Response
696
-	 *
697
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
698
-	 */
699
-	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
700
-	{
701
-		$service = $this->_selectWriteService();
702
-
703
-		do
704
-		{
705
-			try
706
-			{
707
-				return $service->deleteByMultipleId($ids, $fromPending, $fromCommitted, $timeout);
708
-			}
709
-			catch (Apache_Solr_HttpTransportException $e)
710
-			{
711
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
712
-				{
713
-					throw $e;
714
-				}
715
-			}
716
-
717
-			$service = $this->_selectWriteService(true);
718
-		} while ($service);
719
-
720
-		return false;
721
-	}
722
-
723
-	/**
724
-	 * Create a delete document based on a query and submit it
725
-	 *
726
-	 * @param string $rawQuery
727
-	 * @param boolean $fromPending
728
-	 * @param boolean $fromCommitted
729
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
730
-	 * @return Apache_Solr_Response
731
-	 *
732
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
733
-	 */
734
-	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
735
-	{
736
-		$service = $this->_selectWriteService();
737
-
738
-		do
739
-		{
740
-			try
741
-			{
742
-				return $service->deleteByQuery($rawQuery, $fromPending, $fromCommitted, $timeout);
743
-			}
744
-			catch (Apache_Solr_HttpTransportException $e)
745
-			{
746
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
747
-				{
748
-					throw $e;
749
-				}
750
-			}
751
-
752
-			$service = $this->_selectWriteService(true);
753
-		} while ($service);
754
-
755
-		return false;
756
-	}
482
+    /**
483
+     * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
484
+     * should be a complete and well formed "add" xml document.
485
+     *
486
+     * @param string $rawPost
487
+     * @return Apache_Solr_Response
488
+     *
489
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
490
+     */
491
+    public function add($rawPost)
492
+    {
493
+        $service = $this->_selectWriteService();
494
+
495
+        do
496
+        {
497
+            try
498
+            {
499
+                return $service->add($rawPost);
500
+            }
501
+            catch (Apache_Solr_HttpTransportException $e)
502
+            {
503
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
504
+                {
505
+                    throw $e;
506
+                }
507
+            }
508
+
509
+            $service = $this->_selectWriteService(true);
510
+        } while ($service);
511
+
512
+        return false;
513
+    }
514
+
515
+    /**
516
+     * Add a Solr Document to the index
517
+     *
518
+     * @param Apache_Solr_Document $document
519
+     * @param boolean $allowDups
520
+     * @param boolean $overwritePending
521
+     * @param boolean $overwriteCommitted
522
+     * @return Apache_Solr_Response
523
+     *
524
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
525
+     */
526
+    public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
527
+    {
528
+        $service = $this->_selectWriteService();
529
+
530
+        do
531
+        {
532
+            try
533
+            {
534
+                return $service->addDocument($document, $allowDups, $overwritePending, $overwriteCommitted);
535
+            }
536
+            catch (Apache_Solr_HttpTransportException $e)
537
+            {
538
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
539
+                {
540
+                    throw $e;
541
+                }
542
+            }
543
+
544
+            $service = $this->_selectWriteService(true);
545
+        } while ($service);
546
+
547
+        return false;
548
+    }
549
+
550
+    /**
551
+     * Add an array of Solr Documents to the index all at once
552
+     *
553
+     * @param array $documents Should be an array of Apache_Solr_Document instances
554
+     * @param boolean $allowDups
555
+     * @param boolean $overwritePending
556
+     * @param boolean $overwriteCommitted
557
+     * @return Apache_Solr_Response
558
+     *
559
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
560
+     */
561
+    public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
562
+    {
563
+        $service = $this->_selectWriteService();
564
+
565
+        do
566
+        {
567
+            try
568
+            {
569
+                return $service->addDocuments($documents, $allowDups, $overwritePending, $overwriteCommitted);
570
+            }
571
+            catch (Apache_Solr_HttpTransportException $e)
572
+            {
573
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
574
+                {
575
+                    throw $e;
576
+                }
577
+            }
578
+
579
+            $service = $this->_selectWriteService(true);
580
+        } while ($service);
581
+
582
+        return false;
583
+    }
584
+
585
+    /**
586
+     * Send a commit command.  Will be synchronous unless both wait parameters are set
587
+     * to false.
588
+     *
589
+     * @param boolean $waitFlush
590
+     * @param boolean $waitSearcher
591
+     * @return Apache_Solr_Response
592
+     *
593
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
594
+     */
595
+    public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
596
+    {
597
+        $service = $this->_selectWriteService();
598
+
599
+        do
600
+        {
601
+            try
602
+            {
603
+                return $service->commit($optimize, $waitFlush, $waitSearcher, $timeout);
604
+            }
605
+            catch (Apache_Solr_HttpTransportException $e)
606
+            {
607
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
608
+                {
609
+                    throw $e;
610
+                }
611
+            }
612
+
613
+            $service = $this->_selectWriteService(true);
614
+        } while ($service);
615
+
616
+        return false;
617
+    }
618
+
619
+    /**
620
+     * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
621
+     * a complete and well formed "delete" xml document
622
+     *
623
+     * @param string $rawPost
624
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
625
+     * @return Apache_Solr_Response
626
+     *
627
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
628
+     */
629
+    public function delete($rawPost, $timeout = 3600)
630
+    {
631
+        $service = $this->_selectWriteService();
632
+
633
+        do
634
+        {
635
+            try
636
+            {
637
+                return $service->delete($rawPost, $timeout);
638
+            }
639
+            catch (Apache_Solr_HttpTransportException $e)
640
+            {
641
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
642
+                {
643
+                    throw $e;
644
+                }
645
+            }
646
+
647
+            $service = $this->_selectWriteService(true);
648
+        } while ($service);
649
+
650
+        return false;
651
+    }
652
+
653
+    /**
654
+     * Create a delete document based on document ID
655
+     *
656
+     * @param string $id
657
+     * @param boolean $fromPending
658
+     * @param boolean $fromCommitted
659
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
660
+     * @return Apache_Solr_Response
661
+     *
662
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
663
+     */
664
+    public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
665
+    {
666
+        $service = $this->_selectWriteService();
667
+
668
+        do
669
+        {
670
+            try
671
+            {
672
+                return $service->deleteById($id, $fromPending, $fromCommitted, $timeout);
673
+            }
674
+            catch (Apache_Solr_HttpTransportException $e)
675
+            {
676
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
677
+                {
678
+                    throw $e;
679
+                }
680
+            }
681
+
682
+            $service = $this->_selectWriteService(true);
683
+        } while ($service);
684
+
685
+        return false;
686
+    }
687
+
688
+    /**
689
+     * Create and post a delete document based on multiple document IDs.
690
+     *
691
+     * @param array $ids Expected to be utf-8 encoded strings
692
+     * @param boolean $fromPending
693
+     * @param boolean $fromCommitted
694
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
695
+     * @return Apache_Solr_Response
696
+     *
697
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
698
+     */
699
+    public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
700
+    {
701
+        $service = $this->_selectWriteService();
702
+
703
+        do
704
+        {
705
+            try
706
+            {
707
+                return $service->deleteByMultipleId($ids, $fromPending, $fromCommitted, $timeout);
708
+            }
709
+            catch (Apache_Solr_HttpTransportException $e)
710
+            {
711
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
712
+                {
713
+                    throw $e;
714
+                }
715
+            }
716
+
717
+            $service = $this->_selectWriteService(true);
718
+        } while ($service);
719
+
720
+        return false;
721
+    }
722
+
723
+    /**
724
+     * Create a delete document based on a query and submit it
725
+     *
726
+     * @param string $rawQuery
727
+     * @param boolean $fromPending
728
+     * @param boolean $fromCommitted
729
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
730
+     * @return Apache_Solr_Response
731
+     *
732
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
733
+     */
734
+    public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
735
+    {
736
+        $service = $this->_selectWriteService();
737
+
738
+        do
739
+        {
740
+            try
741
+            {
742
+                return $service->deleteByQuery($rawQuery, $fromPending, $fromCommitted, $timeout);
743
+            }
744
+            catch (Apache_Solr_HttpTransportException $e)
745
+            {
746
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
747
+                {
748
+                    throw $e;
749
+                }
750
+            }
751
+
752
+            $service = $this->_selectWriteService(true);
753
+        } while ($service);
754
+
755
+        return false;
756
+    }
757 757
 	
758
-	/**
759
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
760
-	 * to use Solr Cell and what parameters are available.
761
-	 *
762
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
763
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
764
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
765
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
766
-	 *
767
-	 * @param string $file Path to file to extract data from
768
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
769
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
770
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
771
-	 *
772
-	 * @return Apache_Solr_Response
773
-	 *
774
-	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
775
-	 */
776
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
777
-	{
778
-		$service = $this->_selectWriteService();
779
-
780
-		do
781
-		{
782
-			try
783
-			{
784
-				return $service->extract($file, $params, $document, $mimetype);
785
-			}
786
-			catch (Apache_Solr_HttpTransportException $e)
787
-			{
788
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
789
-				{
790
-					throw $e;
791
-				}
792
-			}
793
-
794
-			$service = $this->_selectWriteService(true);
795
-		} while ($service);
796
-
797
-		return false;
798
-	}
758
+    /**
759
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
760
+     * to use Solr Cell and what parameters are available.
761
+     *
762
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
763
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
764
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
765
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
766
+     *
767
+     * @param string $file Path to file to extract data from
768
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
769
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
770
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
771
+     *
772
+     * @return Apache_Solr_Response
773
+     *
774
+     * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
775
+     */
776
+    public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
777
+    {
778
+        $service = $this->_selectWriteService();
779
+
780
+        do
781
+        {
782
+            try
783
+            {
784
+                return $service->extract($file, $params, $document, $mimetype);
785
+            }
786
+            catch (Apache_Solr_HttpTransportException $e)
787
+            {
788
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
789
+                {
790
+                    throw $e;
791
+                }
792
+            }
793
+
794
+            $service = $this->_selectWriteService(true);
795
+        } while ($service);
796
+
797
+        return false;
798
+    }
799 799
 	
800
-	/**
801
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
802
-	 * to use Solr Cell and what parameters are available.
803
-	 *
804
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
805
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
806
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
807
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
808
-	 *
809
-	 * @param string $data Data that will be passed to Solr Cell
810
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
811
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
812
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
813
-	 *
814
-	 * @return Apache_Solr_Response
815
-	 *
816
-	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
817
-	 *
818
-	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
819
-	 */
820
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
821
-	{
822
-		$service = $this->_selectWriteService();
823
-
824
-		do
825
-		{
826
-			try
827
-			{
828
-				return $service->extractFromString($data, $params, $document, $mimetype);
829
-			}
830
-			catch (Apache_Solr_HttpTransportException $e)
831
-			{
832
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
833
-				{
834
-					throw $e;
835
-				}
836
-			}
837
-
838
-			$service = $this->_selectWriteService(true);
839
-		} while ($service);
840
-
841
-		return false;
842
-	}
800
+    /**
801
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
802
+     * to use Solr Cell and what parameters are available.
803
+     *
804
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
805
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
806
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
807
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
808
+     *
809
+     * @param string $data Data that will be passed to Solr Cell
810
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
811
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
812
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
813
+     *
814
+     * @return Apache_Solr_Response
815
+     *
816
+     * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
817
+     *
818
+     * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
819
+     */
820
+    public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
821
+    {
822
+        $service = $this->_selectWriteService();
823
+
824
+        do
825
+        {
826
+            try
827
+            {
828
+                return $service->extractFromString($data, $params, $document, $mimetype);
829
+            }
830
+            catch (Apache_Solr_HttpTransportException $e)
831
+            {
832
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
833
+                {
834
+                    throw $e;
835
+                }
836
+            }
837
+
838
+            $service = $this->_selectWriteService(true);
839
+        } while ($service);
840
+
841
+        return false;
842
+    }
843 843
 	
844
-	/**
845
-	 * Send an optimize command.  Will be synchronous unless both wait parameters are set
846
-	 * to false.
847
-	 *
848
-	 * @param boolean $waitFlush
849
-	 * @param boolean $waitSearcher
850
-	 * @param float $timeout Maximum expected duration of the optimize operation on the server (otherwise, will throw a communication exception)
851
-	 * @return Apache_Solr_Response
852
-	 *
853
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
854
-	 */
855
-	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
856
-	{
857
-		$service = $this->_selectWriteService();
858
-
859
-		do
860
-		{
861
-			try
862
-			{
863
-				return $service->optimize($waitFlush, $waitSearcher, $timeout);
864
-			}
865
-			catch (Apache_Solr_HttpTransportException $e)
866
-			{
867
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
868
-				{
869
-					throw $e;
870
-				}
871
-			}
872
-
873
-			$service = $this->_selectWriteService(true);
874
-		} while ($service);
875
-
876
-		return false;
877
-	}
878
-
879
-	/**
880
-	 * Simple Search interface
881
-	 *
882
-	 * @param string $query The raw query string
883
-	 * @param int $offset The starting offset for result documents
884
-	 * @param int $limit The maximum number of result documents to return
885
-	 * @param array $params key / value pairs for query parameters, use arrays for multivalued parameters
886
-	 * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
887
-	 * @return Apache_Solr_Response
888
-	 *
889
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
890
-	 */
891
-	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = Apache_Solr_Service::METHOD_GET)
892
-	{
893
-		$service = $this->_selectReadService();
894
-
895
-		do
896
-		{
897
-			try
898
-			{
899
-				return $service->search($query, $offset, $limit, $params, $method);
900
-			}
901
-			catch (Apache_Solr_HttpTransportException $e)
902
-			{
903
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
904
-				{
905
-					throw $e;
906
-				}
907
-			}
908
-
909
-			$service = $this->_selectReadService(true);
910
-		} while ($service);
911
-
912
-		return false;
913
-	}
844
+    /**
845
+     * Send an optimize command.  Will be synchronous unless both wait parameters are set
846
+     * to false.
847
+     *
848
+     * @param boolean $waitFlush
849
+     * @param boolean $waitSearcher
850
+     * @param float $timeout Maximum expected duration of the optimize operation on the server (otherwise, will throw a communication exception)
851
+     * @return Apache_Solr_Response
852
+     *
853
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
854
+     */
855
+    public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
856
+    {
857
+        $service = $this->_selectWriteService();
858
+
859
+        do
860
+        {
861
+            try
862
+            {
863
+                return $service->optimize($waitFlush, $waitSearcher, $timeout);
864
+            }
865
+            catch (Apache_Solr_HttpTransportException $e)
866
+            {
867
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
868
+                {
869
+                    throw $e;
870
+                }
871
+            }
872
+
873
+            $service = $this->_selectWriteService(true);
874
+        } while ($service);
875
+
876
+        return false;
877
+    }
878
+
879
+    /**
880
+     * Simple Search interface
881
+     *
882
+     * @param string $query The raw query string
883
+     * @param int $offset The starting offset for result documents
884
+     * @param int $limit The maximum number of result documents to return
885
+     * @param array $params key / value pairs for query parameters, use arrays for multivalued parameters
886
+     * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
887
+     * @return Apache_Solr_Response
888
+     *
889
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
890
+     */
891
+    public function search($query, $offset = 0, $limit = 10, $params = array(), $method = Apache_Solr_Service::METHOD_GET)
892
+    {
893
+        $service = $this->_selectReadService();
894
+
895
+        do
896
+        {
897
+            try
898
+            {
899
+                return $service->search($query, $offset, $limit, $params, $method);
900
+            }
901
+            catch (Apache_Solr_HttpTransportException $e)
902
+            {
903
+                if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
904
+                {
905
+                    throw $e;
906
+                }
907
+            }
908
+
909
+            $service = $this->_selectReadService(true);
910
+        } while ($service);
911
+
912
+        return false;
913
+    }
914 914
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 
39 39
 // See Issue #1 (http://code.google.com/p/solr-php-client/issues/detail?id=1)
40 40
 // Doesn't follow typical include path conventions, but is more convenient for users
41
-require_once(dirname(dirname(__FILE__)) . '/Service.php');
41
+require_once(dirname(dirname(__FILE__)).'/Service.php');
42 42
 
43
-require_once(dirname(dirname(__FILE__)) . '/NoServiceAvailableException.php');
43
+require_once(dirname(dirname(__FILE__)).'/NoServiceAvailableException.php');
44 44
 
45 45
 /**
46 46
  * Reference Implementation for using multiple Solr services in a distribution. Functionality
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 
63 63
 	protected $_createDocuments = true;
64 64
 
65
-	protected $_readableServices = array();
66
-	protected $_writeableServices = array();
65
+	protected $_readableServices = array ();
66
+	protected $_writeableServices = array ();
67 67
 
68 68
 	protected $_currentReadService = null;
69 69
 	protected $_currentWriteService = null;
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 	protected $_writePingTimeout = 4;
73 73
 
74 74
 	// Configuration for server selection backoff intervals
75
-	protected $_useBackoff = false;		// Set to true to use more resillient write server selection
76
-	protected $_backoffLimit = 600;		// 10 minute default maximum
77
-	protected $_backoffEscalation = 2.0; 	// Rate at which to increase backoff period
78
-	protected $_defaultBackoff = 2.0;		// Default backoff interval
75
+	protected $_useBackoff = false; // Set to true to use more resillient write server selection
76
+	protected $_backoffLimit = 600; // 10 minute default maximum
77
+	protected $_backoffEscalation = 2.0; // Rate at which to increase backoff period
78
+	protected $_defaultBackoff = 2.0; // Default backoff interval
79 79
 
80 80
 	/**
81 81
 	 * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @param array $readableServices
119 119
 	 * @param array $writeableServices
120 120
 	 */
121
-	public function __construct($readableServices = array(), $writeableServices = array())
121
+	public function __construct($readableServices = array (), $writeableServices = array ())
122 122
 	{
123 123
 		//setup readable services
124 124
 		foreach ($readableServices as $service)
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 */
159 159
 	protected function _getServiceId($host, $port, $path)
160 160
 	{
161
-		return $host . ':' . $port . $path;
161
+		return $host.':'.$port.$path;
162 162
 	}
163 163
 
164 164
 	/**
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		{
182 182
 			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
183 183
 			{
184
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
184
+				$id = $this->_getServiceId((string) $service['host'], (int) $service['port'], (string) $service['path']);
185 185
 
186 186
 				$this->_readableServices[$id] = $service;
187 187
 			}
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 		{
212 212
 			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
213 213
 			{
214
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
214
+				$id = $this->_getServiceId((string) $service['host'], (int) $service['port'], (string) $service['path']);
215 215
 			}
216 216
 			else
217 217
 			{
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 		{
250 250
 			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
251 251
 			{
252
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
252
+				$id = $this->_getServiceId((string) $service['host'], (int) $service['port'], (string) $service['path']);
253 253
 
254 254
 				$this->_writeableServices[$id] = $service;
255 255
 			}
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 		{
280 280
 			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
281 281
 			{
282
-				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
282
+				$id = $this->_getServiceId((string) $service['host'], (int) $service['port'], (string) $service['path']);
283 283
 			}
284 284
 			else
285 285
 			{
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	 */
356 356
 	protected function _selectWriteService($forceSelect = false)
357 357
 	{
358
-		if($this->_useBackoff)
358
+		if ($this->_useBackoff)
359 359
 		{
360 360
 			return $this->_selectWriteServiceSafe($forceSelect);
361 361
 		}
@@ -435,12 +435,12 @@  discard block
 block discarded – undo
435 435
 
436 436
 					$backoff *= $this->_backoffEscalation;
437 437
 
438
-					if($backoff > $this->_backoffLimit)
438
+					if ($backoff > $this->_backoffLimit)
439 439
 					{
440 440
 						throw new Apache_Solr_NoServiceAvailableException('No write services were available.  All timeouts exceeded.');
441 441
 					}
442 442
 
443
-				} while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false);
443
+				} while ($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false);
444 444
 			}
445 445
 			else
446 446
 			{
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 	 *
774 774
 	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
775 775
 	 */
776
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
776
+	public function extract($file, $params = array (), $document = null, $mimetype = 'application/octet-stream')
777 777
 	{
778 778
 		$service = $this->_selectWriteService();
779 779
 
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
 	 *
818 818
 	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
819 819
 	 */
820
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
820
+	public function extractFromString($data, $params = array (), $document = null, $mimetype = 'application/octet-stream')
821 821
 	{
822 822
 		$service = $this->_selectWriteService();
823 823
 
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 	 *
889 889
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
890 890
 	 */
891
-	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = Apache_Solr_Service::METHOD_GET)
891
+	public function search($query, $offset = 0, $limit = 10, $params = array (), $method = Apache_Solr_Service::METHOD_GET)
892 892
 	{
893 893
 		$service = $this->_selectReadService();
894 894
 
Please login to merge, or discard this patch.
Braces   +143 added lines, -251 removed lines patch added patch discarded remove patch
@@ -48,8 +48,7 @@  discard block
 block discarded – undo
48 48
  * 	routing of read / write operations
49 49
  * 	failover (on selection) for multiple read servers
50 50
  */
51
-class Apache_Solr_Service_Balancer
52
-{
51
+class Apache_Solr_Service_Balancer {
53 52
 	/**
54 53
 	 * SVN Revision meta data for this class
55 54
 	 */
@@ -85,8 +84,7 @@  discard block
 block discarded – undo
85 84
 	 * @param string $value
86 85
 	 * @return string
87 86
 	 */
88
-	static public function escape($value)
89
-	{
87
+	static public function escape($value) {
90 88
 		return Apache_Solr_Service::escape($value);
91 89
 	}
92 90
 
@@ -96,8 +94,7 @@  discard block
 block discarded – undo
96 94
 	 * @param string $value
97 95
 	 * @return string
98 96
 	 */
99
-	static public function escapePhrase($value)
100
-	{
97
+	static public function escapePhrase($value) {
101 98
 		return Apache_Solr_Service::escapePhrase($value);
102 99
 	}
103 100
 
@@ -107,8 +104,7 @@  discard block
 block discarded – undo
107 104
 	 * @param string $value
108 105
 	 * @return string
109 106
 	 */
110
-	static public function phrase($value)
111
-	{
107
+	static public function phrase($value) {
112 108
 		return Apache_Solr_Service::phrase($value);
113 109
 	}
114 110
 
@@ -118,33 +114,27 @@  discard block
 block discarded – undo
118 114
 	 * @param array $readableServices
119 115
 	 * @param array $writeableServices
120 116
 	 */
121
-	public function __construct($readableServices = array(), $writeableServices = array())
122
-	{
117
+	public function __construct($readableServices = array(), $writeableServices = array()) {
123 118
 		//setup readable services
124
-		foreach ($readableServices as $service)
125
-		{
119
+		foreach ($readableServices as $service) {
126 120
 			$this->addReadService($service);
127 121
 		}
128 122
 
129 123
 		//setup writeable services
130
-		foreach ($writeableServices as $service)
131
-		{
124
+		foreach ($writeableServices as $service) {
132 125
 			$this->addWriteService($service);
133 126
 		}
134 127
 	}
135 128
 
136
-	public function setReadPingTimeout($timeout)
137
-	{
129
+	public function setReadPingTimeout($timeout) {
138 130
 		$this->_readPingTimeout = $timeout;
139 131
 	}
140 132
 
141
-	public function setWritePingTimeout($timeout)
142
-	{
133
+	public function setWritePingTimeout($timeout) {
143 134
 		$this->_writePingTimeout = $timeout;
144 135
 	}
145 136
 
146
-	public function setUseBackoff($enable)
147
-	{
137
+	public function setUseBackoff($enable) {
148 138
 		$this->_useBackoff = $enable;
149 139
 	}
150 140
 
@@ -156,8 +146,7 @@  discard block
 block discarded – undo
156 146
 	 * @param string $path
157 147
 	 * @return string
158 148
 	 */
159
-	protected function _getServiceId($host, $port, $path)
160
-	{
149
+	protected function _getServiceId($host, $port, $path) {
161 150
 		return $host . ':' . $port . $path;
162 151
 	}
163 152
 
@@ -169,24 +158,17 @@  discard block
 block discarded – undo
169 158
 	 *
170 159
 	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
171 160
 	 */
172
-	public function addReadService($service)
173
-	{
174
-		if ($service instanceof Apache_Solr_Service)
175
-		{
161
+	public function addReadService($service) {
162
+		if ($service instanceof Apache_Solr_Service) {
176 163
 			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
177 164
 
178 165
 			$this->_readableServices[$id] = $service;
179
-		}
180
-		else if (is_array($service))
181
-		{
182
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
183
-			{
166
+		} else if (is_array($service)) {
167
+			if (isset($service['host']) && isset($service['port']) && isset($service['path'])) {
184 168
 				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
185 169
 
186 170
 				$this->_readableServices[$id] = $service;
187
-			}
188
-			else
189
-			{
171
+			} else {
190 172
 				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
191 173
 			}
192 174
 		}
@@ -199,32 +181,22 @@  discard block
 block discarded – undo
199 181
 	 *
200 182
 	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
201 183
 	 */
202
-	public function removeReadService($service)
203
-	{
184
+	public function removeReadService($service) {
204 185
 		$id = '';
205 186
 
206
-		if ($service instanceof Apache_Solr_Service)
207
-		{
187
+		if ($service instanceof Apache_Solr_Service) {
208 188
 			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
209
-		}
210
-		else if (is_array($service))
211
-		{
212
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
213
-			{
189
+		} else if (is_array($service)) {
190
+			if (isset($service['host']) && isset($service['port']) && isset($service['path'])) {
214 191
 				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
215
-			}
216
-			else
217
-			{
192
+			} else {
218 193
 				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
219 194
 			}
220
-		}
221
-		else if (is_string($service))
222
-		{
195
+		} else if (is_string($service)) {
223 196
 			$id = $service;
224 197
 		}
225 198
 
226
-		if ($id && isset($this->_readableServices[$id]))
227
-		{
199
+		if ($id && isset($this->_readableServices[$id])) {
228 200
 			unset($this->_readableServices[$id]);
229 201
 		}
230 202
 	}
@@ -237,24 +209,17 @@  discard block
 block discarded – undo
237 209
 	 *
238 210
 	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
239 211
 	 */
240
-	public function addWriteService($service)
241
-	{
242
-		if ($service instanceof Apache_Solr_Service)
243
-		{
212
+	public function addWriteService($service) {
213
+		if ($service instanceof Apache_Solr_Service) {
244 214
 			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
245 215
 
246 216
 			$this->_writeableServices[$id] = $service;
247
-		}
248
-		else if (is_array($service))
249
-		{
250
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
251
-			{
217
+		} else if (is_array($service)) {
218
+			if (isset($service['host']) && isset($service['port']) && isset($service['path'])) {
252 219
 				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
253 220
 
254 221
 				$this->_writeableServices[$id] = $service;
255
-			}
256
-			else
257
-			{
222
+			} else {
258 223
 				throw new Apache_Solr_InvalidArgumentException('A Writeable Service description array does not have all required elements of host, port, and path');
259 224
 			}
260 225
 		}
@@ -267,32 +232,22 @@  discard block
 block discarded – undo
267 232
 	 *
268 233
 	 * @throws Apache_Solr_InvalidArgumentException If service descriptor is not valid
269 234
 	 */
270
-	public function removeWriteService($service)
271
-	{
235
+	public function removeWriteService($service) {
272 236
 		$id = '';
273 237
 
274
-		if ($service instanceof Apache_Solr_Service)
275
-		{
238
+		if ($service instanceof Apache_Solr_Service) {
276 239
 			$id = $this->_getServiceId($service->getHost(), $service->getPort(), $service->getPath());
277
-		}
278
-		else if (is_array($service))
279
-		{
280
-			if (isset($service['host']) && isset($service['port']) && isset($service['path']))
281
-			{
240
+		} else if (is_array($service)) {
241
+			if (isset($service['host']) && isset($service['port']) && isset($service['path'])) {
282 242
 				$id = $this->_getServiceId((string)$service['host'], (int)$service['port'], (string)$service['path']);
283
-			}
284
-			else
285
-			{
243
+			} else {
286 244
 				throw new Apache_Solr_InvalidArgumentException('A Readable Service description array does not have all required elements of host, port, and path');
287 245
 			}
288
-		}
289
-		else if (is_string($service))
290
-		{
246
+		} else if (is_string($service)) {
291 247
 			$id = $service;
292 248
 		}
293 249
 
294
-		if ($id && isset($this->_writeableServices[$id]))
295
-		{
250
+		if ($id && isset($this->_writeableServices[$id])) {
296 251
 			unset($this->_writeableServices[$id]);
297 252
 		}
298 253
 	}
@@ -305,29 +260,23 @@  discard block
 block discarded – undo
305 260
 	 *
306 261
 	 * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
307 262
 	 */
308
-	protected function _selectReadService($forceSelect = false)
309
-	{
310
-		if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect)
311
-		{
312
-			if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect)
313
-			{
263
+	protected function _selectReadService($forceSelect = false) {
264
+		if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect) {
265
+			if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect) {
314 266
 				// we probably had a communication error, ping the current read service, remove it if it times out
315
-				if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false)
316
-				{
267
+				if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false) {
317 268
 					$this->removeReadService($this->_currentReadService);
318 269
 				}
319 270
 			}
320 271
 
321
-			if (count($this->_readableServices))
322
-			{
272
+			if (count($this->_readableServices)) {
323 273
 				// select one of the read services at random
324 274
 				$ids = array_keys($this->_readableServices);
325 275
 
326 276
 				$id = $ids[rand(0, count($ids) - 1)];
327 277
 				$service = $this->_readableServices[$id];
328 278
 
329
-				if (is_array($service))
330
-				{
279
+				if (is_array($service)) {
331 280
 					//convert the array definition to a client object
332 281
 					$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
333 282
 					$this->_readableServices[$id] = $service;
@@ -335,9 +284,7 @@  discard block
 block discarded – undo
335 284
 
336 285
 				$service->setCreateDocuments($this->_createDocuments);
337 286
 				$this->_currentReadService = $id;
338
-			}
339
-			else
340
-			{
287
+			} else {
341 288
 				throw new Apache_Solr_NoServiceAvailableException('No read services were available');
342 289
 			}
343 290
 		}
@@ -353,43 +300,34 @@  discard block
 block discarded – undo
353 300
 	 *
354 301
 	 * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
355 302
 	 */
356
-	protected function _selectWriteService($forceSelect = false)
357
-	{
358
-		if($this->_useBackoff)
359
-		{
303
+	protected function _selectWriteService($forceSelect = false) {
304
+		if($this->_useBackoff) {
360 305
 			return $this->_selectWriteServiceSafe($forceSelect);
361 306
 		}
362 307
 
363
-		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
364
-		{
365
-			if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect)
366
-			{
308
+		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect) {
309
+			if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect) {
367 310
 				// we probably had a communication error, ping the current read service, remove it if it times out
368
-				if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false)
369
-				{
311
+				if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false) {
370 312
 					$this->removeWriteService($this->_currentWriteService);
371 313
 				}
372 314
 			}
373 315
 
374
-			if (count($this->_writeableServices))
375
-			{
316
+			if (count($this->_writeableServices)) {
376 317
 				// select one of the read services at random
377 318
 				$ids = array_keys($this->_writeableServices);
378 319
 
379 320
 				$id = $ids[rand(0, count($ids) - 1)];
380 321
 				$service = $this->_writeableServices[$id];
381 322
 
382
-				if (is_array($service))
383
-				{
323
+				if (is_array($service)) {
384 324
 					//convert the array definition to a client object
385 325
 					$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
386 326
 					$this->_writeableServices[$id] = $service;
387 327
 				}
388 328
 
389 329
 				$this->_currentWriteService = $id;
390
-			}
391
-			else
392
-			{
330
+			} else {
393 331
 				throw new Apache_Solr_NoServiceAvailableException('No write services were available');
394 332
 			}
395 333
 		}
@@ -409,12 +347,9 @@  discard block
 block discarded – undo
409 347
 	 * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
410 348
 	 */
411 349
 
412
-	protected function _selectWriteServiceSafe($forceSelect = false)
413
-	{
414
-		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
415
-		{
416
-			if (count($this->_writeableServices))
417
-			{
350
+	protected function _selectWriteServiceSafe($forceSelect = false) {
351
+		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect) {
352
+			if (count($this->_writeableServices)) {
418 353
 				$backoff = $this->_defaultBackoff;
419 354
 
420 355
 				do {
@@ -424,8 +359,7 @@  discard block
 block discarded – undo
424 359
 					$id = $ids[rand(0, count($ids) - 1)];
425 360
 					$service = $this->_writeableServices[$id];
426 361
 
427
-					if (is_array($service))
428
-					{
362
+					if (is_array($service)) {
429 363
 						//convert the array definition to a client object
430 364
 						$service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
431 365
 						$this->_writeableServices[$id] = $service;
@@ -435,15 +369,12 @@  discard block
 block discarded – undo
435 369
 
436 370
 					$backoff *= $this->_backoffEscalation;
437 371
 
438
-					if($backoff > $this->_backoffLimit)
439
-					{
372
+					if($backoff > $this->_backoffLimit) {
440 373
 						throw new Apache_Solr_NoServiceAvailableException('No write services were available.  All timeouts exceeded.');
441 374
 					}
442 375
 
443 376
 				} while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false);
444
-			}
445
-			else
446
-			{
377
+			} else {
447 378
 				throw new Apache_Solr_NoServiceAvailableException('No write services were available');
448 379
 			}
449 380
 		}
@@ -457,13 +388,11 @@  discard block
 block discarded – undo
457 388
 	 *
458 389
 	 * @param boolean $createDocuments
459 390
 	 */
460
-	public function setCreateDocuments($createDocuments)
461
-	{
391
+	public function setCreateDocuments($createDocuments) {
462 392
 		$this->_createDocuments = (bool) $createDocuments;
463 393
 
464 394
 		// set on current read service
465
-		if ($this->_currentReadService)
466
-		{
395
+		if ($this->_currentReadService) {
467 396
 			$service = $this->_selectReadService();
468 397
 			$service->setCreateDocuments($createDocuments);
469 398
 		}
@@ -474,8 +403,7 @@  discard block
 block discarded – undo
474 403
 	 *
475 404
 	 * @return boolean
476 405
 	 */
477
-	public function getCreateDocuments()
478
-	{
406
+	public function getCreateDocuments() {
479 407
 		return $this->_createDocuments;
480 408
 	}
481 409
 	
@@ -488,22 +416,19 @@  discard block
 block discarded – undo
488 416
 	 *
489 417
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
490 418
 	 */
491
-	public function add($rawPost)
492
-	{
419
+	public function add($rawPost) {
493 420
 		$service = $this->_selectWriteService();
494 421
 
495
-		do
496
-		{
497
-			try
498
-			{
422
+		do {
423
+			try {
499 424
 				return $service->add($rawPost);
500
-			}
501
-			catch (Apache_Solr_HttpTransportException $e)
502
-			{
503
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
425
+			} catch (Apache_Solr_HttpTransportException $e) {
426
+				if ($e->getCode() != 0) {
427
+				    //IF NOT COMMUNICATION ERROR
504 428
 				{
505 429
 					throw $e;
506 430
 				}
431
+				}
507 432
 			}
508 433
 
509 434
 			$service = $this->_selectWriteService(true);
@@ -523,22 +448,19 @@  discard block
 block discarded – undo
523 448
 	 *
524 449
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
525 450
 	 */
526
-	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
527
-	{
451
+	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true) {
528 452
 		$service = $this->_selectWriteService();
529 453
 
530
-		do
531
-		{
532
-			try
533
-			{
454
+		do {
455
+			try {
534 456
 				return $service->addDocument($document, $allowDups, $overwritePending, $overwriteCommitted);
535
-			}
536
-			catch (Apache_Solr_HttpTransportException $e)
537
-			{
538
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
457
+			} catch (Apache_Solr_HttpTransportException $e) {
458
+				if ($e->getCode() != 0) {
459
+				    //IF NOT COMMUNICATION ERROR
539 460
 				{
540 461
 					throw $e;
541 462
 				}
463
+				}
542 464
 			}
543 465
 
544 466
 			$service = $this->_selectWriteService(true);
@@ -558,22 +480,19 @@  discard block
 block discarded – undo
558 480
 	 *
559 481
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
560 482
 	 */
561
-	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
562
-	{
483
+	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true) {
563 484
 		$service = $this->_selectWriteService();
564 485
 
565
-		do
566
-		{
567
-			try
568
-			{
486
+		do {
487
+			try {
569 488
 				return $service->addDocuments($documents, $allowDups, $overwritePending, $overwriteCommitted);
570
-			}
571
-			catch (Apache_Solr_HttpTransportException $e)
572
-			{
573
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
489
+			} catch (Apache_Solr_HttpTransportException $e) {
490
+				if ($e->getCode() != 0) {
491
+				    //IF NOT COMMUNICATION ERROR
574 492
 				{
575 493
 					throw $e;
576 494
 				}
495
+				}
577 496
 			}
578 497
 
579 498
 			$service = $this->_selectWriteService(true);
@@ -592,22 +511,19 @@  discard block
 block discarded – undo
592 511
 	 *
593 512
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
594 513
 	 */
595
-	public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
596
-	{
514
+	public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600) {
597 515
 		$service = $this->_selectWriteService();
598 516
 
599
-		do
600
-		{
601
-			try
602
-			{
517
+		do {
518
+			try {
603 519
 				return $service->commit($optimize, $waitFlush, $waitSearcher, $timeout);
604
-			}
605
-			catch (Apache_Solr_HttpTransportException $e)
606
-			{
607
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
520
+			} catch (Apache_Solr_HttpTransportException $e) {
521
+				if ($e->getCode() != 0) {
522
+				    //IF NOT COMMUNICATION ERROR
608 523
 				{
609 524
 					throw $e;
610 525
 				}
526
+				}
611 527
 			}
612 528
 
613 529
 			$service = $this->_selectWriteService(true);
@@ -626,22 +542,19 @@  discard block
 block discarded – undo
626 542
 	 *
627 543
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
628 544
 	 */
629
-	public function delete($rawPost, $timeout = 3600)
630
-	{
545
+	public function delete($rawPost, $timeout = 3600) {
631 546
 		$service = $this->_selectWriteService();
632 547
 
633
-		do
634
-		{
635
-			try
636
-			{
548
+		do {
549
+			try {
637 550
 				return $service->delete($rawPost, $timeout);
638
-			}
639
-			catch (Apache_Solr_HttpTransportException $e)
640
-			{
641
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
551
+			} catch (Apache_Solr_HttpTransportException $e) {
552
+				if ($e->getCode() != 0) {
553
+				    //IF NOT COMMUNICATION ERROR
642 554
 				{
643 555
 					throw $e;
644 556
 				}
557
+				}
645 558
 			}
646 559
 
647 560
 			$service = $this->_selectWriteService(true);
@@ -661,22 +574,19 @@  discard block
 block discarded – undo
661 574
 	 *
662 575
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
663 576
 	 */
664
-	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
665
-	{
577
+	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600) {
666 578
 		$service = $this->_selectWriteService();
667 579
 
668
-		do
669
-		{
670
-			try
671
-			{
580
+		do {
581
+			try {
672 582
 				return $service->deleteById($id, $fromPending, $fromCommitted, $timeout);
673
-			}
674
-			catch (Apache_Solr_HttpTransportException $e)
675
-			{
676
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
583
+			} catch (Apache_Solr_HttpTransportException $e) {
584
+				if ($e->getCode() != 0) {
585
+				    //IF NOT COMMUNICATION ERROR
677 586
 				{
678 587
 					throw $e;
679 588
 				}
589
+				}
680 590
 			}
681 591
 
682 592
 			$service = $this->_selectWriteService(true);
@@ -696,22 +606,19 @@  discard block
 block discarded – undo
696 606
 	 *
697 607
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
698 608
 	 */
699
-	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
700
-	{
609
+	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600) {
701 610
 		$service = $this->_selectWriteService();
702 611
 
703
-		do
704
-		{
705
-			try
706
-			{
612
+		do {
613
+			try {
707 614
 				return $service->deleteByMultipleId($ids, $fromPending, $fromCommitted, $timeout);
708
-			}
709
-			catch (Apache_Solr_HttpTransportException $e)
710
-			{
711
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
615
+			} catch (Apache_Solr_HttpTransportException $e) {
616
+				if ($e->getCode() != 0) {
617
+				    //IF NOT COMMUNICATION ERROR
712 618
 				{
713 619
 					throw $e;
714 620
 				}
621
+				}
715 622
 			}
716 623
 
717 624
 			$service = $this->_selectWriteService(true);
@@ -731,22 +638,19 @@  discard block
 block discarded – undo
731 638
 	 *
732 639
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
733 640
 	 */
734
-	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
735
-	{
641
+	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600) {
736 642
 		$service = $this->_selectWriteService();
737 643
 
738
-		do
739
-		{
740
-			try
741
-			{
644
+		do {
645
+			try {
742 646
 				return $service->deleteByQuery($rawQuery, $fromPending, $fromCommitted, $timeout);
743
-			}
744
-			catch (Apache_Solr_HttpTransportException $e)
745
-			{
746
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
647
+			} catch (Apache_Solr_HttpTransportException $e) {
648
+				if ($e->getCode() != 0) {
649
+				    //IF NOT COMMUNICATION ERROR
747 650
 				{
748 651
 					throw $e;
749 652
 				}
653
+				}
750 654
 			}
751 655
 
752 656
 			$service = $this->_selectWriteService(true);
@@ -773,22 +677,19 @@  discard block
 block discarded – undo
773 677
 	 *
774 678
 	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
775 679
 	 */
776
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
777
-	{
680
+	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream') {
778 681
 		$service = $this->_selectWriteService();
779 682
 
780
-		do
781
-		{
782
-			try
783
-			{
683
+		do {
684
+			try {
784 685
 				return $service->extract($file, $params, $document, $mimetype);
785
-			}
786
-			catch (Apache_Solr_HttpTransportException $e)
787
-			{
788
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
686
+			} catch (Apache_Solr_HttpTransportException $e) {
687
+				if ($e->getCode() != 0) {
688
+				    //IF NOT COMMUNICATION ERROR
789 689
 				{
790 690
 					throw $e;
791 691
 				}
692
+				}
792 693
 			}
793 694
 
794 695
 			$service = $this->_selectWriteService(true);
@@ -817,22 +718,19 @@  discard block
 block discarded – undo
817 718
 	 *
818 719
 	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
819 720
 	 */
820
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
821
-	{
721
+	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream') {
822 722
 		$service = $this->_selectWriteService();
823 723
 
824
-		do
825
-		{
826
-			try
827
-			{
724
+		do {
725
+			try {
828 726
 				return $service->extractFromString($data, $params, $document, $mimetype);
829
-			}
830
-			catch (Apache_Solr_HttpTransportException $e)
831
-			{
832
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
727
+			} catch (Apache_Solr_HttpTransportException $e) {
728
+				if ($e->getCode() != 0) {
729
+				    //IF NOT COMMUNICATION ERROR
833 730
 				{
834 731
 					throw $e;
835 732
 				}
733
+				}
836 734
 			}
837 735
 
838 736
 			$service = $this->_selectWriteService(true);
@@ -852,22 +750,19 @@  discard block
 block discarded – undo
852 750
 	 *
853 751
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
854 752
 	 */
855
-	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
856
-	{
753
+	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600) {
857 754
 		$service = $this->_selectWriteService();
858 755
 
859
-		do
860
-		{
861
-			try
862
-			{
756
+		do {
757
+			try {
863 758
 				return $service->optimize($waitFlush, $waitSearcher, $timeout);
864
-			}
865
-			catch (Apache_Solr_HttpTransportException $e)
866
-			{
867
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
759
+			} catch (Apache_Solr_HttpTransportException $e) {
760
+				if ($e->getCode() != 0) {
761
+				    //IF NOT COMMUNICATION ERROR
868 762
 				{
869 763
 					throw $e;
870 764
 				}
765
+				}
871 766
 			}
872 767
 
873 768
 			$service = $this->_selectWriteService(true);
@@ -888,22 +783,19 @@  discard block
 block discarded – undo
888 783
 	 *
889 784
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
890 785
 	 */
891
-	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = Apache_Solr_Service::METHOD_GET)
892
-	{
786
+	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = Apache_Solr_Service::METHOD_GET) {
893 787
 		$service = $this->_selectReadService();
894 788
 
895
-		do
896
-		{
897
-			try
898
-			{
789
+		do {
790
+			try {
899 791
 				return $service->search($query, $offset, $limit, $params, $method);
900
-			}
901
-			catch (Apache_Solr_HttpTransportException $e)
902
-			{
903
-				if ($e->getCode() != 0) //IF NOT COMMUNICATION ERROR
792
+			} catch (Apache_Solr_HttpTransportException $e) {
793
+				if ($e->getCode() != 0) {
794
+				    //IF NOT COMMUNICATION ERROR
904 795
 				{
905 796
 					throw $e;
906 797
 				}
798
+				}
907 799
 			}
908 800
 
909 801
 			$service = $this->_selectReadService(true);
Please login to merge, or discard this patch.
Upper-Lower-Casing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -60,19 +60,19 @@  discard block
 block discarded – undo
60 60
 	 */
61 61
 	const SVN_ID = '$Id: Balancer.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
62 62
 
63
-	protected $_createDocuments = true;
63
+	protected $_createDocuments = TRUE;
64 64
 
65 65
 	protected $_readableServices = array();
66 66
 	protected $_writeableServices = array();
67 67
 
68
-	protected $_currentReadService = null;
69
-	protected $_currentWriteService = null;
68
+	protected $_currentReadService = NULL;
69
+	protected $_currentWriteService = NULL;
70 70
 
71 71
 	protected $_readPingTimeout = 2;
72 72
 	protected $_writePingTimeout = 4;
73 73
 
74 74
 	// Configuration for server selection backoff intervals
75
-	protected $_useBackoff = false;		// Set to true to use more resillient write server selection
75
+	protected $_useBackoff = FALSE;		// Set to true to use more resillient write server selection
76 76
 	protected $_backoffLimit = 600;		// 10 minute default maximum
77 77
 	protected $_backoffEscalation = 2.0; 	// Rate at which to increase backoff period
78 78
 	protected $_defaultBackoff = 2.0;		// Default backoff interval
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
 	 *
306 306
 	 * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
307 307
 	 */
308
-	protected function _selectReadService($forceSelect = false)
308
+	protected function _selectReadService($forceSelect = FALSE)
309 309
 	{
310 310
 		if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect)
311 311
 		{
312 312
 			if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect)
313 313
 			{
314 314
 				// we probably had a communication error, ping the current read service, remove it if it times out
315
-				if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false)
315
+				if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === FALSE)
316 316
 				{
317 317
 					$this->removeReadService($this->_currentReadService);
318 318
 				}
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 	 *
354 354
 	 * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
355 355
 	 */
356
-	protected function _selectWriteService($forceSelect = false)
356
+	protected function _selectWriteService($forceSelect = FALSE)
357 357
 	{
358 358
 		if($this->_useBackoff)
359 359
 		{
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 			if ($this->_currentWriteService && isset($this->_writeableServices[$this->_currentWriteService]) && $forceSelect)
366 366
 			{
367 367
 				// we probably had a communication error, ping the current read service, remove it if it times out
368
-				if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === false)
368
+				if ($this->_writeableServices[$this->_currentWriteService]->ping($this->_writePingTimeout) === FALSE)
369 369
 				{
370 370
 					$this->removeWriteService($this->_currentWriteService);
371 371
 				}
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 	 * @throws Apache_Solr_NoServiceAvailableException If there are no write services that meet requirements
410 410
 	 */
411 411
 
412
-	protected function _selectWriteServiceSafe($forceSelect = false)
412
+	protected function _selectWriteServiceSafe($forceSelect = FALSE)
413 413
 	{
414 414
 		if (!$this->_currentWriteService || !isset($this->_writeableServices[$this->_currentWriteService]) || $forceSelect)
415 415
 		{
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 						throw new Apache_Solr_NoServiceAvailableException('No write services were available.  All timeouts exceeded.');
441 441
 					}
442 442
 
443
-				} while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === false);
443
+				} while($this->_writeableServices[$this->_currentWriteService]->ping($backoff) === FALSE);
444 444
 			}
445 445
 			else
446 446
 			{
@@ -506,10 +506,10 @@  discard block
 block discarded – undo
506 506
 				}
507 507
 			}
508 508
 
509
-			$service = $this->_selectWriteService(true);
509
+			$service = $this->_selectWriteService(TRUE);
510 510
 		} while ($service);
511 511
 
512
-		return false;
512
+		return FALSE;
513 513
 	}
514 514
 
515 515
 	/**
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 	 *
524 524
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
525 525
 	 */
526
-	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
526
+	public function addDocument(Apache_Solr_Document $document, $allowDups = FALSE, $overwritePending = TRUE, $overwriteCommitted = TRUE)
527 527
 	{
528 528
 		$service = $this->_selectWriteService();
529 529
 
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
 				}
542 542
 			}
543 543
 
544
-			$service = $this->_selectWriteService(true);
544
+			$service = $this->_selectWriteService(TRUE);
545 545
 		} while ($service);
546 546
 
547
-		return false;
547
+		return FALSE;
548 548
 	}
549 549
 
550 550
 	/**
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 	 *
559 559
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
560 560
 	 */
561
-	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
561
+	public function addDocuments($documents, $allowDups = FALSE, $overwritePending = TRUE, $overwriteCommitted = TRUE)
562 562
 	{
563 563
 		$service = $this->_selectWriteService();
564 564
 
@@ -576,10 +576,10 @@  discard block
 block discarded – undo
576 576
 				}
577 577
 			}
578 578
 
579
-			$service = $this->_selectWriteService(true);
579
+			$service = $this->_selectWriteService(TRUE);
580 580
 		} while ($service);
581 581
 
582
-		return false;
582
+		return FALSE;
583 583
 	}
584 584
 
585 585
 	/**
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 	 *
593 593
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
594 594
 	 */
595
-	public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
595
+	public function commit($optimize = TRUE, $waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600)
596 596
 	{
597 597
 		$service = $this->_selectWriteService();
598 598
 
@@ -610,10 +610,10 @@  discard block
 block discarded – undo
610 610
 				}
611 611
 			}
612 612
 
613
-			$service = $this->_selectWriteService(true);
613
+			$service = $this->_selectWriteService(TRUE);
614 614
 		} while ($service);
615 615
 
616
-		return false;
616
+		return FALSE;
617 617
 	}
618 618
 
619 619
 	/**
@@ -644,10 +644,10 @@  discard block
 block discarded – undo
644 644
 				}
645 645
 			}
646 646
 
647
-			$service = $this->_selectWriteService(true);
647
+			$service = $this->_selectWriteService(TRUE);
648 648
 		} while ($service);
649 649
 
650
-		return false;
650
+		return FALSE;
651 651
 	}
652 652
 
653 653
 	/**
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
 	 *
662 662
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
663 663
 	 */
664
-	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
664
+	public function deleteById($id, $fromPending = TRUE, $fromCommitted = TRUE, $timeout = 3600)
665 665
 	{
666 666
 		$service = $this->_selectWriteService();
667 667
 
@@ -679,10 +679,10 @@  discard block
 block discarded – undo
679 679
 				}
680 680
 			}
681 681
 
682
-			$service = $this->_selectWriteService(true);
682
+			$service = $this->_selectWriteService(TRUE);
683 683
 		} while ($service);
684 684
 
685
-		return false;
685
+		return FALSE;
686 686
 	}
687 687
 
688 688
 	/**
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 	 *
697 697
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
698 698
 	 */
699
-	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
699
+	public function deleteByMultipleIds($ids, $fromPending = TRUE, $fromCommitted = TRUE, $timeout = 3600)
700 700
 	{
701 701
 		$service = $this->_selectWriteService();
702 702
 
@@ -714,10 +714,10 @@  discard block
 block discarded – undo
714 714
 				}
715 715
 			}
716 716
 
717
-			$service = $this->_selectWriteService(true);
717
+			$service = $this->_selectWriteService(TRUE);
718 718
 		} while ($service);
719 719
 
720
-		return false;
720
+		return FALSE;
721 721
 	}
722 722
 
723 723
 	/**
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 	 *
732 732
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
733 733
 	 */
734
-	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
734
+	public function deleteByQuery($rawQuery, $fromPending = TRUE, $fromCommitted = TRUE, $timeout = 3600)
735 735
 	{
736 736
 		$service = $this->_selectWriteService();
737 737
 
@@ -749,10 +749,10 @@  discard block
 block discarded – undo
749 749
 				}
750 750
 			}
751 751
 
752
-			$service = $this->_selectWriteService(true);
752
+			$service = $this->_selectWriteService(TRUE);
753 753
 		} while ($service);
754 754
 
755
-		return false;
755
+		return FALSE;
756 756
 	}
757 757
 	
758 758
 	/**
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 	 *
774 774
 	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
775 775
 	 */
776
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
776
+	public function extract($file, $params = array(), $document = NULL, $mimetype = 'application/octet-stream')
777 777
 	{
778 778
 		$service = $this->_selectWriteService();
779 779
 
@@ -791,10 +791,10 @@  discard block
 block discarded – undo
791 791
 				}
792 792
 			}
793 793
 
794
-			$service = $this->_selectWriteService(true);
794
+			$service = $this->_selectWriteService(TRUE);
795 795
 		} while ($service);
796 796
 
797
-		return false;
797
+		return FALSE;
798 798
 	}
799 799
 	
800 800
 	/**
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
 	 *
818 818
 	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
819 819
 	 */
820
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
820
+	public function extractFromString($data, $params = array(), $document = NULL, $mimetype = 'application/octet-stream')
821 821
 	{
822 822
 		$service = $this->_selectWriteService();
823 823
 
@@ -835,10 +835,10 @@  discard block
 block discarded – undo
835 835
 				}
836 836
 			}
837 837
 
838
-			$service = $this->_selectWriteService(true);
838
+			$service = $this->_selectWriteService(TRUE);
839 839
 		} while ($service);
840 840
 
841
-		return false;
841
+		return FALSE;
842 842
 	}
843 843
 	
844 844
 	/**
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 	 *
853 853
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
854 854
 	 */
855
-	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
855
+	public function optimize($waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600)
856 856
 	{
857 857
 		$service = $this->_selectWriteService();
858 858
 
@@ -870,10 +870,10 @@  discard block
 block discarded – undo
870 870
 				}
871 871
 			}
872 872
 
873
-			$service = $this->_selectWriteService(true);
873
+			$service = $this->_selectWriteService(TRUE);
874 874
 		} while ($service);
875 875
 
876
-		return false;
876
+		return FALSE;
877 877
 	}
878 878
 
879 879
 	/**
@@ -906,9 +906,9 @@  discard block
 block discarded – undo
906 906
 				}
907 907
 			}
908 908
 
909
-			$service = $this->_selectReadService(true);
909
+			$service = $this->_selectReadService(TRUE);
910 910
 		} while ($service);
911 911
 
912
-		return false;
912
+		return FALSE;
913 913
 	}
914 914
 }
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/Response.php 4 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -47,201 +47,201 @@
 block discarded – undo
47 47
  */
48 48
 class Apache_Solr_Response
49 49
 {
50
-	/**
51
-	 * SVN Revision meta data for this class
52
-	 */
53
-	const SVN_REVISION = '$Revision: 54 $';
54
-
55
-	/**
56
-	 * SVN ID meta data for this class
57
-	 */
58
-	const SVN_ID = '$Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
59
-
60
-	/**
61
-	 * Holds the raw response used in construction
62
-	 *
63
-	 * @var Apache_Solr_HttpTransport_Response HTTP response
64
-	 */
65
-	protected $_response;
66
-
67
-	/**
68
-	 * Whether the raw response has been parsed
69
-	 *
70
-	 * @var boolean
71
-	 */
72
-	protected $_isParsed = false;
73
-
74
-	/**
75
-	 * Parsed representation of the data
76
-	 *
77
-	 * @var mixed
78
-	 */
79
-	protected $_parsedData;
80
-
81
-	/**
82
-	 * Data parsing flags.  Determines what extra processing should be done
83
-	 * after the data is initially converted to a data structure.
84
-	 *
85
-	 * @var boolean
86
-	 */
87
-	protected $_createDocuments = true,
88
-			$_collapseSingleValueArrays = true;
89
-
90
-	/**
91
-	 * Constructor. Takes the raw HTTP response body and the exploded HTTP headers
92
-	 *
93
-	 * @return Apache_Solr_HttpTransport_Response HTTP response
94
-	 * @param boolean $createDocuments Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances
95
-	 * @param boolean $collapseSingleValueArrays Whether to make multivalued fields appear as single values
96
-	 */
97
-	public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = true, $collapseSingleValueArrays = true)
98
-	{
99
-		$this->_response = $response;
100
-		$this->_createDocuments = (bool) $createDocuments;
101
-		$this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
102
-	}
103
-
104
-	/**
105
-	 * Get the HTTP status code
106
-	 *
107
-	 * @return integer
108
-	 */
109
-	public function getHttpStatus()
110
-	{
111
-		return $this->_response->getStatusCode();
112
-	}
113
-
114
-	/**
115
-	 * Get the HTTP status message of the response
116
-	 *
117
-	 * @return string
118
-	 */
119
-	public function getHttpStatusMessage()
120
-	{
121
-		return $this->_response->getStatusMessage();
122
-	}
123
-
124
-	/**
125
-	 * Get content type of this Solr response
126
-	 *
127
-	 * @return string
128
-	 */
129
-	public function getType()
130
-	{
131
-		return $this->_response->getMimeType();
132
-	}
133
-
134
-	/**
135
-	 * Get character encoding of this response. Should usually be utf-8, but just in case
136
-	 *
137
-	 * @return string
138
-	 */
139
-	public function getEncoding()
140
-	{
141
-		return $this->_response->getEncoding();
142
-	}
143
-
144
-	/**
145
-	 * Get the raw response as it was given to this object
146
-	 *
147
-	 * @return string
148
-	 */
149
-	public function getRawResponse()
150
-	{
151
-		return $this->_response->getBody();
152
-	}
153
-
154
-	/**
155
-	 * Magic get to expose the parsed data and to lazily load it
156
-	 *
157
-	 * @param string $key
158
-	 * @return mixed
159
-	 */
160
-	public function __get($key)
161
-	{
162
-		if (!$this->_isParsed)
163
-		{
164
-			$this->_parseData();
165
-			$this->_isParsed = true;
166
-		}
167
-
168
-		if (isset($this->_parsedData->$key))
169
-		{
170
-			return $this->_parsedData->$key;
171
-		}
172
-
173
-		return null;
174
-	}
175
-
176
-	/**
177
-	 * Magic function for isset function on parsed data
178
-	 *
179
-	 * @param string $key
180
-	 * @return boolean
181
-	 */
182
-	public function __isset($key)
183
-	{
184
-		if (!$this->_isParsed)
185
-		{
186
-			$this->_parseData();
187
-			$this->_isParsed = true;
188
-		}
189
-
190
-		return isset($this->_parsedData->$key);
191
-	}
192
-
193
-	/**
194
-	 * Parse the raw response into the parsed_data array for access
195
-	 *
196
-	 * @throws Apache_Solr_ParserException If the data could not be parsed
197
-	 */
198
-	protected function _parseData()
199
-	{
200
-		//An alternative would be to use Zend_Json::decode(...)
201
-		$data = json_decode($this->_response->getBody());
202
-
203
-		// check that we receive a valid JSON response - we should never receive a null
204
-		if ($data === null)
205
-		{
206
-			throw new Apache_Solr_ParserException('Solr response does not appear to be valid JSON, please examine the raw response with getRawResponse() method');
207
-		}
208
-
209
-		//if we're configured to collapse single valued arrays or to convert them to Apache_Solr_Document objects
210
-		//and we have response documents, then try to collapse the values and / or convert them now
211
-		if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs))
212
-		{
213
-			$documents = array();
214
-
215
-			foreach ($data->response->docs as $originalDocument)
216
-			{
217
-				if ($this->_createDocuments)
218
-				{
219
-					$document = new Apache_Solr_Document();
220
-				}
221
-				else
222
-				{
223
-					$document = $originalDocument;
224
-				}
225
-
226
-				foreach ($originalDocument as $key => $value)
227
-				{
228
-					//If a result is an array with only a single
229
-					//value then its nice to be able to access
230
-					//it as if it were always a single value
231
-					if ($this->_collapseSingleValueArrays && is_array($value) && count($value) <= 1)
232
-					{
233
-						$value = array_shift($value);
234
-					}
235
-
236
-					$document->$key = $value;
237
-				}
238
-
239
-				$documents[] = $document;
240
-			}
241
-
242
-			$data->response->docs = $documents;
243
-		}
244
-
245
-		$this->_parsedData = $data;
246
-	}
50
+    /**
51
+     * SVN Revision meta data for this class
52
+     */
53
+    const SVN_REVISION = '$Revision: 54 $';
54
+
55
+    /**
56
+     * SVN ID meta data for this class
57
+     */
58
+    const SVN_ID = '$Id: Response.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
59
+
60
+    /**
61
+     * Holds the raw response used in construction
62
+     *
63
+     * @var Apache_Solr_HttpTransport_Response HTTP response
64
+     */
65
+    protected $_response;
66
+
67
+    /**
68
+     * Whether the raw response has been parsed
69
+     *
70
+     * @var boolean
71
+     */
72
+    protected $_isParsed = false;
73
+
74
+    /**
75
+     * Parsed representation of the data
76
+     *
77
+     * @var mixed
78
+     */
79
+    protected $_parsedData;
80
+
81
+    /**
82
+     * Data parsing flags.  Determines what extra processing should be done
83
+     * after the data is initially converted to a data structure.
84
+     *
85
+     * @var boolean
86
+     */
87
+    protected $_createDocuments = true,
88
+            $_collapseSingleValueArrays = true;
89
+
90
+    /**
91
+     * Constructor. Takes the raw HTTP response body and the exploded HTTP headers
92
+     *
93
+     * @return Apache_Solr_HttpTransport_Response HTTP response
94
+     * @param boolean $createDocuments Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances
95
+     * @param boolean $collapseSingleValueArrays Whether to make multivalued fields appear as single values
96
+     */
97
+    public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = true, $collapseSingleValueArrays = true)
98
+    {
99
+        $this->_response = $response;
100
+        $this->_createDocuments = (bool) $createDocuments;
101
+        $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
102
+    }
103
+
104
+    /**
105
+     * Get the HTTP status code
106
+     *
107
+     * @return integer
108
+     */
109
+    public function getHttpStatus()
110
+    {
111
+        return $this->_response->getStatusCode();
112
+    }
113
+
114
+    /**
115
+     * Get the HTTP status message of the response
116
+     *
117
+     * @return string
118
+     */
119
+    public function getHttpStatusMessage()
120
+    {
121
+        return $this->_response->getStatusMessage();
122
+    }
123
+
124
+    /**
125
+     * Get content type of this Solr response
126
+     *
127
+     * @return string
128
+     */
129
+    public function getType()
130
+    {
131
+        return $this->_response->getMimeType();
132
+    }
133
+
134
+    /**
135
+     * Get character encoding of this response. Should usually be utf-8, but just in case
136
+     *
137
+     * @return string
138
+     */
139
+    public function getEncoding()
140
+    {
141
+        return $this->_response->getEncoding();
142
+    }
143
+
144
+    /**
145
+     * Get the raw response as it was given to this object
146
+     *
147
+     * @return string
148
+     */
149
+    public function getRawResponse()
150
+    {
151
+        return $this->_response->getBody();
152
+    }
153
+
154
+    /**
155
+     * Magic get to expose the parsed data and to lazily load it
156
+     *
157
+     * @param string $key
158
+     * @return mixed
159
+     */
160
+    public function __get($key)
161
+    {
162
+        if (!$this->_isParsed)
163
+        {
164
+            $this->_parseData();
165
+            $this->_isParsed = true;
166
+        }
167
+
168
+        if (isset($this->_parsedData->$key))
169
+        {
170
+            return $this->_parsedData->$key;
171
+        }
172
+
173
+        return null;
174
+    }
175
+
176
+    /**
177
+     * Magic function for isset function on parsed data
178
+     *
179
+     * @param string $key
180
+     * @return boolean
181
+     */
182
+    public function __isset($key)
183
+    {
184
+        if (!$this->_isParsed)
185
+        {
186
+            $this->_parseData();
187
+            $this->_isParsed = true;
188
+        }
189
+
190
+        return isset($this->_parsedData->$key);
191
+    }
192
+
193
+    /**
194
+     * Parse the raw response into the parsed_data array for access
195
+     *
196
+     * @throws Apache_Solr_ParserException If the data could not be parsed
197
+     */
198
+    protected function _parseData()
199
+    {
200
+        //An alternative would be to use Zend_Json::decode(...)
201
+        $data = json_decode($this->_response->getBody());
202
+
203
+        // check that we receive a valid JSON response - we should never receive a null
204
+        if ($data === null)
205
+        {
206
+            throw new Apache_Solr_ParserException('Solr response does not appear to be valid JSON, please examine the raw response with getRawResponse() method');
207
+        }
208
+
209
+        //if we're configured to collapse single valued arrays or to convert them to Apache_Solr_Document objects
210
+        //and we have response documents, then try to collapse the values and / or convert them now
211
+        if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs))
212
+        {
213
+            $documents = array();
214
+
215
+            foreach ($data->response->docs as $originalDocument)
216
+            {
217
+                if ($this->_createDocuments)
218
+                {
219
+                    $document = new Apache_Solr_Document();
220
+                }
221
+                else
222
+                {
223
+                    $document = $originalDocument;
224
+                }
225
+
226
+                foreach ($originalDocument as $key => $value)
227
+                {
228
+                    //If a result is an array with only a single
229
+                    //value then its nice to be able to access
230
+                    //it as if it were always a single value
231
+                    if ($this->_collapseSingleValueArrays && is_array($value) && count($value) <= 1)
232
+                    {
233
+                        $value = array_shift($value);
234
+                    }
235
+
236
+                    $document->$key = $value;
237
+                }
238
+
239
+                $documents[] = $document;
240
+            }
241
+
242
+            $data->response->docs = $documents;
243
+        }
244
+
245
+        $this->_parsedData = $data;
246
+    }
247 247
 }
248 248
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  * @author Donovan Jimenez <[email protected]>
37 37
  */
38 38
 
39
-require_once(dirname(__FILE__) . '/ParserException.php');
39
+require_once(dirname(__FILE__).'/ParserException.php');
40 40
 
41 41
 /**
42 42
  * Represents a Solr response.  Parses the raw response into a set of stdClass objects
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		//and we have response documents, then try to collapse the values and / or convert them now
211 211
 		if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs))
212 212
 		{
213
-			$documents = array();
213
+			$documents = array ();
214 214
 
215 215
 			foreach ($data->response->docs as $originalDocument)
216 216
 			{
Please login to merge, or discard this patch.
Braces   +20 added lines, -41 removed lines patch added patch discarded remove patch
@@ -45,8 +45,7 @@  discard block
 block discarded – undo
45 45
  * Currently requires json_decode which is bundled with PHP >= 5.2.0, Alternatively can be
46 46
  * installed with PECL.  Zend Framework also includes a purely PHP solution.
47 47
  */
48
-class Apache_Solr_Response
49
-{
48
+class Apache_Solr_Response {
50 49
 	/**
51 50
 	 * SVN Revision meta data for this class
52 51
 	 */
@@ -94,8 +93,7 @@  discard block
 block discarded – undo
94 93
 	 * @param boolean $createDocuments Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances
95 94
 	 * @param boolean $collapseSingleValueArrays Whether to make multivalued fields appear as single values
96 95
 	 */
97
-	public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = true, $collapseSingleValueArrays = true)
98
-	{
96
+	public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = true, $collapseSingleValueArrays = true) {
99 97
 		$this->_response = $response;
100 98
 		$this->_createDocuments = (bool) $createDocuments;
101 99
 		$this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
@@ -106,8 +104,7 @@  discard block
 block discarded – undo
106 104
 	 *
107 105
 	 * @return integer
108 106
 	 */
109
-	public function getHttpStatus()
110
-	{
107
+	public function getHttpStatus() {
111 108
 		return $this->_response->getStatusCode();
112 109
 	}
113 110
 
@@ -116,8 +113,7 @@  discard block
 block discarded – undo
116 113
 	 *
117 114
 	 * @return string
118 115
 	 */
119
-	public function getHttpStatusMessage()
120
-	{
116
+	public function getHttpStatusMessage() {
121 117
 		return $this->_response->getStatusMessage();
122 118
 	}
123 119
 
@@ -126,8 +122,7 @@  discard block
 block discarded – undo
126 122
 	 *
127 123
 	 * @return string
128 124
 	 */
129
-	public function getType()
130
-	{
125
+	public function getType() {
131 126
 		return $this->_response->getMimeType();
132 127
 	}
133 128
 
@@ -136,8 +131,7 @@  discard block
 block discarded – undo
136 131
 	 *
137 132
 	 * @return string
138 133
 	 */
139
-	public function getEncoding()
140
-	{
134
+	public function getEncoding() {
141 135
 		return $this->_response->getEncoding();
142 136
 	}
143 137
 
@@ -146,8 +140,7 @@  discard block
 block discarded – undo
146 140
 	 *
147 141
 	 * @return string
148 142
 	 */
149
-	public function getRawResponse()
150
-	{
143
+	public function getRawResponse() {
151 144
 		return $this->_response->getBody();
152 145
 	}
153 146
 
@@ -157,16 +150,13 @@  discard block
 block discarded – undo
157 150
 	 * @param string $key
158 151
 	 * @return mixed
159 152
 	 */
160
-	public function __get($key)
161
-	{
162
-		if (!$this->_isParsed)
163
-		{
153
+	public function __get($key) {
154
+		if (!$this->_isParsed) {
164 155
 			$this->_parseData();
165 156
 			$this->_isParsed = true;
166 157
 		}
167 158
 
168
-		if (isset($this->_parsedData->$key))
169
-		{
159
+		if (isset($this->_parsedData->$key)) {
170 160
 			return $this->_parsedData->$key;
171 161
 		}
172 162
 
@@ -179,10 +169,8 @@  discard block
 block discarded – undo
179 169
 	 * @param string $key
180 170
 	 * @return boolean
181 171
 	 */
182
-	public function __isset($key)
183
-	{
184
-		if (!$this->_isParsed)
185
-		{
172
+	public function __isset($key) {
173
+		if (!$this->_isParsed) {
186 174
 			$this->_parseData();
187 175
 			$this->_isParsed = true;
188 176
 		}
@@ -195,41 +183,32 @@  discard block
 block discarded – undo
195 183
 	 *
196 184
 	 * @throws Apache_Solr_ParserException If the data could not be parsed
197 185
 	 */
198
-	protected function _parseData()
199
-	{
186
+	protected function _parseData() {
200 187
 		//An alternative would be to use Zend_Json::decode(...)
201 188
 		$data = json_decode($this->_response->getBody());
202 189
 
203 190
 		// check that we receive a valid JSON response - we should never receive a null
204
-		if ($data === null)
205
-		{
191
+		if ($data === null) {
206 192
 			throw new Apache_Solr_ParserException('Solr response does not appear to be valid JSON, please examine the raw response with getRawResponse() method');
207 193
 		}
208 194
 
209 195
 		//if we're configured to collapse single valued arrays or to convert them to Apache_Solr_Document objects
210 196
 		//and we have response documents, then try to collapse the values and / or convert them now
211
-		if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs))
212
-		{
197
+		if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs)) {
213 198
 			$documents = array();
214 199
 
215
-			foreach ($data->response->docs as $originalDocument)
216
-			{
217
-				if ($this->_createDocuments)
218
-				{
200
+			foreach ($data->response->docs as $originalDocument) {
201
+				if ($this->_createDocuments) {
219 202
 					$document = new Apache_Solr_Document();
220
-				}
221
-				else
222
-				{
203
+				} else {
223 204
 					$document = $originalDocument;
224 205
 				}
225 206
 
226
-				foreach ($originalDocument as $key => $value)
227
-				{
207
+				foreach ($originalDocument as $key => $value) {
228 208
 					//If a result is an array with only a single
229 209
 					//value then its nice to be able to access
230 210
 					//it as if it were always a single value
231
-					if ($this->_collapseSingleValueArrays && is_array($value) && count($value) <= 1)
232
-					{
211
+					if ($this->_collapseSingleValueArrays && is_array($value) && count($value) <= 1) {
233 212
 						$value = array_shift($value);
234 213
 					}
235 214
 
Please login to merge, or discard this patch.
Upper-Lower-Casing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @var boolean
71 71
 	 */
72
-	protected $_isParsed = false;
72
+	protected $_isParsed = FALSE;
73 73
 
74 74
 	/**
75 75
 	 * Parsed representation of the data
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @var boolean
86 86
 	 */
87
-	protected $_createDocuments = true,
88
-			$_collapseSingleValueArrays = true;
87
+	protected $_createDocuments = TRUE,
88
+			$_collapseSingleValueArrays = TRUE;
89 89
 
90 90
 	/**
91 91
 	 * Constructor. Takes the raw HTTP response body and the exploded HTTP headers
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 * @param boolean $createDocuments Whether to convert the documents json_decoded as stdClass instances to Apache_Solr_Document instances
95 95
 	 * @param boolean $collapseSingleValueArrays Whether to make multivalued fields appear as single values
96 96
 	 */
97
-	public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = true, $collapseSingleValueArrays = true)
97
+	public function __construct(Apache_Solr_HttpTransport_Response $response, $createDocuments = TRUE, $collapseSingleValueArrays = TRUE)
98 98
 	{
99 99
 		$this->_response = $response;
100 100
 		$this->_createDocuments = (bool) $createDocuments;
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		if (!$this->_isParsed)
163 163
 		{
164 164
 			$this->_parseData();
165
-			$this->_isParsed = true;
165
+			$this->_isParsed = TRUE;
166 166
 		}
167 167
 
168 168
 		if (isset($this->_parsedData->$key))
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 			return $this->_parsedData->$key;
171 171
 		}
172 172
 
173
-		return null;
173
+		return NULL;
174 174
 	}
175 175
 
176 176
 	/**
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 		if (!$this->_isParsed)
185 185
 		{
186 186
 			$this->_parseData();
187
-			$this->_isParsed = true;
187
+			$this->_isParsed = TRUE;
188 188
 		}
189 189
 
190 190
 		return isset($this->_parsedData->$key);
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 		$data = json_decode($this->_response->getBody());
202 202
 
203 203
 		// check that we receive a valid JSON response - we should never receive a null
204
-		if ($data === null)
204
+		if ($data === NULL)
205 205
 		{
206 206
 			throw new Apache_Solr_ParserException('Solr response does not appear to be valid JSON, please examine the raw response with getRawResponse() method');
207 207
 		}
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/ParserException.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
38 38
 
39 39
 class Apache_Solr_ParserException extends Apache_Solr_Exception
40 40
 {
41
-	/**
42
-	 * SVN Revision meta data for this class
43
-	 */
44
-	const SVN_REVISION = '$Revision: 54 $';
41
+    /**
42
+     * SVN Revision meta data for this class
43
+     */
44
+    const SVN_REVISION = '$Revision: 54 $';
45 45
 
46
-	/**
47
-	 * SVN ID meta data for this class
48
-	 */
49
-	const SVN_ID = '$Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
46
+    /**
47
+     * SVN ID meta data for this class
48
+     */
49
+    const SVN_ID = '$Id: ParserException.php 54 2011-02-04 16:29:18Z donovan.jimenez $';
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@
 block discarded – undo
36 36
  * @author Donovan Jimenez <[email protected]>
37 37
  */
38 38
 
39
-class Apache_Solr_ParserException extends Apache_Solr_Exception
40
-{
39
+class Apache_Solr_ParserException extends Apache_Solr_Exception {
41 40
 	/**
42 41
 	 * SVN Revision meta data for this class
43 42
 	 */
Please login to merge, or discard this patch.
dlf/lib/SolrPhpClient/Apache/Solr/Service.php 4 patches
Indentation   +1083 added lines, -1083 removed lines patch added patch discarded remove patch
@@ -85,1097 +85,1097 @@
 block discarded – undo
85 85
  */
86 86
 class Apache_Solr_Service
87 87
 {
88
-	/**
89
-	 * SVN Revision meta data for this class
90
-	 */
91
-	const SVN_REVISION = '$Revision: 59 $';
92
-
93
-	/**
94
-	 * SVN ID meta data for this class
95
-	 */
96
-	const SVN_ID = '$Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $';
97
-
98
-	/**
99
-	 * Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning
100
-	 */
101
-	const SOLR_WRITER = 'json';
102
-
103
-	/**
104
-	 * NamedList Treatment constants
105
-	 */
106
-	const NAMED_LIST_FLAT = 'flat';
107
-	const NAMED_LIST_MAP = 'map';
108
-
109
-	/**
110
-	 * Search HTTP Methods
111
-	 */
112
-	const METHOD_GET = 'GET';
113
-	const METHOD_POST = 'POST';
114
-
115
-	/**
116
-	 * Servlet mappings
117
-	 */
118
-	const PING_SERVLET = 'admin/ping';
119
-	const UPDATE_SERVLET = 'update';
120
-	const SEARCH_SERVLET = 'select';
121
-	const THREADS_SERVLET = 'admin/threads';
122
-	const EXTRACT_SERVLET = 'update/extract';
123
-
124
-	/**
125
-	 * Server identification strings
126
-	 *
127
-	 * @var string
128
-	 */
129
-	protected $_host, $_port, $_path;
130
-
131
-	/**
132
-	 * Whether {@link Apache_Solr_Response} objects should create {@link Apache_Solr_Document}s in
133
-	 * the returned parsed data
134
-	 *
135
-	 * @var boolean
136
-	 */
137
-	protected $_createDocuments = true;
138
-
139
-	/**
140
-	 * Whether {@link Apache_Solr_Response} objects should have multivalue fields with only a single value
141
-	 * collapsed to appear as a single value would.
142
-	 *
143
-	 * @var boolean
144
-	 */
145
-	protected $_collapseSingleValueArrays = true;
146
-
147
-	/**
148
-	 * How NamedLists should be formatted in the output.  This specifically effects facet counts. Valid values
149
-	 * are {@link Apache_Solr_Service::NAMED_LIST_MAP} (default) or {@link Apache_Solr_Service::NAMED_LIST_FLAT}.
150
-	 *
151
-	 * @var string
152
-	 */
153
-	protected $_namedListTreatment = self::NAMED_LIST_MAP;
154
-
155
-	/**
156
-	 * Query delimiters. Someone might want to be able to change
157
-	 * these (to use &amp; instead of & for example), so I've provided them.
158
-	 *
159
-	 * @var string
160
-	 */
161
-	protected $_queryDelimiter = '?', $_queryStringDelimiter = '&', $_queryBracketsEscaped = true;
162
-
163
-	/**
164
-	 * Constructed servlet full path URLs
165
-	 *
166
-	 * @var string
167
-	 */
168
-	protected $_pingUrl, $_updateUrl, $_searchUrl, $_threadsUrl;
169
-
170
-	/**
171
-	 * Keep track of whether our URLs have been constructed
172
-	 *
173
-	 * @var boolean
174
-	 */
175
-	protected $_urlsInited = false;
176
-
177
-	/**
178
-	 * HTTP Transport implementation (pluggable)
179
-	 *
180
-	 * @var Apache_Solr_HttpTransport_Interface
181
-	 */
182
-	protected $_httpTransport = false;
183
-
184
-	/**
185
-	 * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
186
-	 *
187
-	 * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
188
-	 *
189
-	 * @param string $value
190
-	 * @return string
191
-	 */
192
-	static public function escape($value)
193
-	{
194
-		//list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
195
-		$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
196
-		$replace = '\\\$1';
197
-
198
-		return preg_replace($pattern, $replace, $value);
199
-	}
200
-
201
-	/**
202
-	 * Escape a value meant to be contained in a phrase for special query characters
203
-	 *
204
-	 * @param string $value
205
-	 * @return string
206
-	 */
207
-	static public function escapePhrase($value)
208
-	{
209
-		$pattern = '/("|\\\)/';
210
-		$replace = '\\\$1';
211
-
212
-		return preg_replace($pattern, $replace, $value);
213
-	}
214
-
215
-	/**
216
-	 * Convenience function for creating phrase syntax from a value
217
-	 *
218
-	 * @param string $value
219
-	 * @return string
220
-	 */
221
-	static public function phrase($value)
222
-	{
223
-		return '"' . self::escapePhrase($value) . '"';
224
-	}
225
-
226
-	/**
227
-	 * Constructor. All parameters are optional and will take on default values
228
-	 * if not specified.
229
-	 *
230
-	 * @param string $host
231
-	 * @param string $port
232
-	 * @param string $path
233
-	 * @param Apache_Solr_HttpTransport_Interface $httpTransport
234
-	 */
235
-	public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = false)
236
-	{
237
-		$this->setHost($host);
238
-		$this->setPort($port);
239
-		$this->setPath($path);
240
-
241
-		$this->_initUrls();
242
-
243
-		if ($httpTransport)
244
-		{
245
-			$this->setHttpTransport($httpTransport);
246
-		}
247
-
248
-		// check that our php version is >= 5.1.3 so we can correct for http_build_query behavior later
249
-		$this->_queryBracketsEscaped = version_compare(phpversion(), '5.1.3', '>=');
250
-	}
251
-
252
-	/**
253
-	 * Return a valid http URL given this server's host, port and path and a provided servlet name
254
-	 *
255
-	 * @param string $servlet
256
-	 * @return string
257
-	 */
258
-	protected function _constructUrl($servlet, $params = array())
259
-	{
260
-		if (count($params))
261
-		{
262
-			//escape all parameters appropriately for inclusion in the query string
263
-			$escapedParams = array();
264
-
265
-			foreach ($params as $key => $value)
266
-			{
267
-				$escapedParams[] = urlencode($key) . '=' . urlencode($value);
268
-			}
269
-
270
-			$queryString = $this->_queryDelimiter . implode($this->_queryStringDelimiter, $escapedParams);
271
-		}
272
-		else
273
-		{
274
-			$queryString = '';
275
-		}
276
-
277
-		return 'http://' . $this->_host . ':' . $this->_port . $this->_path . $servlet . $queryString;
278
-	}
279
-
280
-	/**
281
-	 * Construct the Full URLs for the three servlets we reference
282
-	 */
283
-	protected function _initUrls()
284
-	{
285
-		//Initialize our full servlet URLs now that we have server information
286
-		$this->_extractUrl = $this->_constructUrl(self::EXTRACT_SERVLET);
287
-		$this->_pingUrl = $this->_constructUrl(self::PING_SERVLET);
288
-		$this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET);
289
-		$this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array('wt' => self::SOLR_WRITER ));
290
-		$this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array('wt' => self::SOLR_WRITER ));
291
-
292
-		$this->_urlsInited = true;
293
-	}
294
-
295
-	protected function _generateQueryString($params)
296
-	{
297
-		// use http_build_query to encode our arguments because its faster
298
-		// than urlencoding all the parts ourselves in a loop
299
-		//
300
-		// because http_build_query treats arrays differently than we want to, correct the query
301
-		// string by changing foo[#]=bar (# being an actual number) parameter strings to just
302
-		// multiple foo=bar strings. This regex should always work since '=' will be urlencoded
303
-		// anywhere else the regex isn't expecting it
304
-		//
305
-		// NOTE: before php 5.1.3 brackets were not url encoded by http_build query - we've checked
306
-		// the php version in the constructor and put the results in the instance variable. Also, before
307
-		// 5.1.2 the arg_separator parameter was not available, so don't use it
308
-		if ($this->_queryBracketsEscaped)
309
-		{
310
-			$queryString = http_build_query($params, null, $this->_queryStringDelimiter);
311
-			return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
312
-		}
313
-		else
314
-		{
315
-			$queryString = http_build_query($params);
316
-			return preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/', '=', $queryString);
317
-		}
318
-	}
319
-
320
-	/**
321
-	 * Central method for making a get operation against this Solr Server
322
-	 *
323
-	 * @param string $url
324
-	 * @param float $timeout Read timeout in seconds
325
-	 * @return Apache_Solr_Response
326
-	 *
327
-	 * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
328
-	 */
329
-	protected function _sendRawGet($url, $timeout = FALSE)
330
-	{
331
-		$httpTransport = $this->getHttpTransport();
332
-
333
-		$httpResponse = $httpTransport->performGetRequest($url, $timeout);
334
-		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
335
-
336
-		if ($solrResponse->getHttpStatus() != 200)
337
-		{
338
-			throw new Apache_Solr_HttpTransportException($solrResponse);
339
-		}
340
-
341
-		return $solrResponse;
342
-	}
343
-
344
-	/**
345
-	 * Central method for making a post operation against this Solr Server
346
-	 *
347
-	 * @param string $url
348
-	 * @param string $rawPost
349
-	 * @param float $timeout Read timeout in seconds
350
-	 * @param string $contentType
351
-	 * @return Apache_Solr_Response
352
-	 *
353
-	 * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
354
-	 */
355
-	protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
356
-	{
357
-		$httpTransport = $this->getHttpTransport();
358
-
359
-		$httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout);
360
-		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
361
-
362
-		if ($solrResponse->getHttpStatus() != 200)
363
-		{
364
-			throw new Apache_Solr_HttpTransportException($solrResponse);
365
-		}
366
-
367
-		return $solrResponse;
368
-	}
369
-
370
-	/**
371
-	 * Returns the set host
372
-	 *
373
-	 * @return string
374
-	 */
375
-	public function getHost()
376
-	{
377
-		return $this->_host;
378
-	}
379
-
380
-	/**
381
-	 * Set the host used. If empty will fallback to constants
382
-	 *
383
-	 * @param string $host
384
-	 *
385
-	 * @throws Apache_Solr_InvalidArgumentException If the host parameter is empty
386
-	 */
387
-	public function setHost($host)
388
-	{
389
-		//Use the provided host or use the default
390
-		if (empty($host))
391
-		{
392
-			throw new Apache_Solr_InvalidArgumentException('Host parameter is empty');
393
-		}
394
-		else
395
-		{
396
-			$this->_host = $host;
397
-		}
398
-
399
-		if ($this->_urlsInited)
400
-		{
401
-			$this->_initUrls();
402
-		}
403
-	}
404
-
405
-	/**
406
-	 * Get the set port
407
-	 *
408
-	 * @return integer
409
-	 */
410
-	public function getPort()
411
-	{
412
-		return $this->_port;
413
-	}
414
-
415
-	/**
416
-	 * Set the port used. If empty will fallback to constants
417
-	 *
418
-	 * @param integer $port
419
-	 *
420
-	 * @throws Apache_Solr_InvalidArgumentException If the port parameter is empty
421
-	 */
422
-	public function setPort($port)
423
-	{
424
-		//Use the provided port or use the default
425
-		$port = (int) $port;
426
-
427
-		if ($port <= 0)
428
-		{
429
-			throw new Apache_Solr_InvalidArgumentException('Port is not a valid port number');
430
-		}
431
-		else
432
-		{
433
-			$this->_port = $port;
434
-		}
435
-
436
-		if ($this->_urlsInited)
437
-		{
438
-			$this->_initUrls();
439
-		}
440
-	}
441
-
442
-	/**
443
-	 * Get the set path.
444
-	 *
445
-	 * @return string
446
-	 */
447
-	public function getPath()
448
-	{
449
-		return $this->_path;
450
-	}
451
-
452
-	/**
453
-	 * Set the path used. If empty will fallback to constants
454
-	 *
455
-	 * @param string $path
456
-	 */
457
-	public function setPath($path)
458
-	{
459
-		$path = trim($path, '/');
460
-
461
-		$this->_path = '/' . $path . '/';
462
-
463
-		if ($this->_urlsInited)
464
-		{
465
-			$this->_initUrls();
466
-		}
467
-	}
468
-
469
-	/**
470
-	 * Get the current configured HTTP Transport
471
-	 *
472
-	 * @return HttpTransportInterface
473
-	 */
474
-	public function getHttpTransport()
475
-	{
476
-		// lazy load a default if one has not be set
477
-		if ($this->_httpTransport === false)
478
-		{
479
-			require_once(dirname(__FILE__) . '/HttpTransport/FileGetContents.php');
480
-
481
-			$this->_httpTransport = new Apache_Solr_HttpTransport_FileGetContents();
482
-		}
483
-
484
-		return $this->_httpTransport;
485
-	}
486
-
487
-	/**
488
-	 * Set the HTTP Transport implemenation that will be used for all HTTP requests
489
-	 *
490
-	 * @param Apache_Solr_HttpTransport_Interface
491
-	 */
492
-	public function setHttpTransport(Apache_Solr_HttpTransport_Interface $httpTransport)
493
-	{
494
-		$this->_httpTransport = $httpTransport;
495
-	}
496
-
497
-	/**
498
-	 * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
499
-	 * parse the response and create {@link Apache_Solr_Document} instances in place.
500
-	 *
501
-	 * @param boolean $createDocuments
502
-	 */
503
-	public function setCreateDocuments($createDocuments)
504
-	{
505
-		$this->_createDocuments = (bool) $createDocuments;
506
-	}
507
-
508
-	/**
509
-	 * Get the current state of the create documents flag.
510
-	 *
511
-	 * @return boolean
512
-	 */
513
-	public function getCreateDocuments()
514
-	{
515
-		return $this->_createDocuments;
516
-	}
517
-
518
-	/**
519
-	 * Set the collapse single value arrays flag.
520
-	 *
521
-	 * @param boolean $collapseSingleValueArrays
522
-	 */
523
-	public function setCollapseSingleValueArrays($collapseSingleValueArrays)
524
-	{
525
-		$this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
526
-	}
527
-
528
-	/**
529
-	 * Get the current state of the collapse single value arrays flag.
530
-	 *
531
-	 * @return boolean
532
-	 */
533
-	public function getCollapseSingleValueArrays()
534
-	{
535
-		return $this->_collapseSingleValueArrays;
536
-	}
537
-
538
-	/**
539
-	 * Get the current default timeout setting (initially the default_socket_timeout ini setting)
540
-	 * in seconds
541
-	 *
542
-	 * @return float
543
-	 *
544
-	 * @deprecated Use the getDefaultTimeout method on the HTTP transport implementation
545
-	 */
546
-	public function getDefaultTimeout()
547
-	{
548
-		return $this->getHttpTransport()->getDefaultTimeout();
549
-	}
550
-
551
-	/**
552
-	 * Set the default timeout for all calls that aren't passed a specific timeout
553
-	 *
554
-	 * @param float $timeout Timeout value in seconds
555
-	 *
556
-	 * @deprecated Use the setDefaultTimeout method on the HTTP transport implementation
557
-	 */
558
-	public function setDefaultTimeout($timeout)
559
-	{
560
-		$this->getHttpTransport()->setDefaultTimeout($timeout);
561
-	}
562
-
563
-	/**
564
-	 * Set how NamedLists should be formatted in the response data. This mainly effects
565
-	 * the facet counts format.
566
-	 *
567
-	 * @param string $namedListTreatment
568
-	 * @throws Apache_Solr_InvalidArgumentException If invalid option is set
569
-	 */
570
-	public function setNamedListTreatment($namedListTreatment)
571
-	{
572
-		switch ((string) $namedListTreatment)
573
-		{
574
-			case Apache_Solr_Service::NAMED_LIST_FLAT:
575
-				$this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT;
576
-				break;
577
-
578
-			case Apache_Solr_Service::NAMED_LIST_MAP:
579
-				$this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_MAP;
580
-				break;
581
-
582
-			default:
583
-				throw new Apache_Solr_InvalidArgumentException('Not a valid named list treatement option');
584
-		}
585
-	}
586
-
587
-	/**
588
-	 * Get the current setting for named list treatment.
589
-	 *
590
-	 * @return string
591
-	 */
592
-	public function getNamedListTreatment()
593
-	{
594
-		return $this->_namedListTreatment;
595
-	}
596
-
597
-	/**
598
-	 * Set the string used to separate the path form the query string.
599
-	 * Defaulted to '?'
600
-	 *
601
-	 * @param string $queryDelimiter
602
-	 */
603
-	public function setQueryDelimiter($queryDelimiter)
604
-	{
605
-		$this->_queryDelimiter = $queryDelimiter;
606
-	}
607
-
608
-	/**
609
-	 * Set the string used to separate the parameters in thequery string
610
-	 * Defaulted to '&'
611
-	 *
612
-	 * @param string $queryStringDelimiter
613
-	 */
614
-	public function setQueryStringDelimiter($queryStringDelimiter)
615
-	{
616
-		$this->_queryStringDelimiter = $queryStringDelimiter;
617
-	}
618
-
619
-	/**
620
-	 * Call the /admin/ping servlet, can be used to quickly tell if a connection to the
621
-	 * server is able to be made.
622
-	 *
623
-	 * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
624
-	 * @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
625
-	 */
626
-	public function ping($timeout = 2)
627
-	{
628
-		$start = microtime(true);
88
+    /**
89
+     * SVN Revision meta data for this class
90
+     */
91
+    const SVN_REVISION = '$Revision: 59 $';
92
+
93
+    /**
94
+     * SVN ID meta data for this class
95
+     */
96
+    const SVN_ID = '$Id: Service.php 59 2011-02-08 20:38:59Z donovan.jimenez $';
97
+
98
+    /**
99
+     * Response writer we'll request - JSON. See http://code.google.com/p/solr-php-client/issues/detail?id=6#c1 for reasoning
100
+     */
101
+    const SOLR_WRITER = 'json';
102
+
103
+    /**
104
+     * NamedList Treatment constants
105
+     */
106
+    const NAMED_LIST_FLAT = 'flat';
107
+    const NAMED_LIST_MAP = 'map';
108
+
109
+    /**
110
+     * Search HTTP Methods
111
+     */
112
+    const METHOD_GET = 'GET';
113
+    const METHOD_POST = 'POST';
114
+
115
+    /**
116
+     * Servlet mappings
117
+     */
118
+    const PING_SERVLET = 'admin/ping';
119
+    const UPDATE_SERVLET = 'update';
120
+    const SEARCH_SERVLET = 'select';
121
+    const THREADS_SERVLET = 'admin/threads';
122
+    const EXTRACT_SERVLET = 'update/extract';
123
+
124
+    /**
125
+     * Server identification strings
126
+     *
127
+     * @var string
128
+     */
129
+    protected $_host, $_port, $_path;
130
+
131
+    /**
132
+     * Whether {@link Apache_Solr_Response} objects should create {@link Apache_Solr_Document}s in
133
+     * the returned parsed data
134
+     *
135
+     * @var boolean
136
+     */
137
+    protected $_createDocuments = true;
138
+
139
+    /**
140
+     * Whether {@link Apache_Solr_Response} objects should have multivalue fields with only a single value
141
+     * collapsed to appear as a single value would.
142
+     *
143
+     * @var boolean
144
+     */
145
+    protected $_collapseSingleValueArrays = true;
146
+
147
+    /**
148
+     * How NamedLists should be formatted in the output.  This specifically effects facet counts. Valid values
149
+     * are {@link Apache_Solr_Service::NAMED_LIST_MAP} (default) or {@link Apache_Solr_Service::NAMED_LIST_FLAT}.
150
+     *
151
+     * @var string
152
+     */
153
+    protected $_namedListTreatment = self::NAMED_LIST_MAP;
154
+
155
+    /**
156
+     * Query delimiters. Someone might want to be able to change
157
+     * these (to use &amp; instead of & for example), so I've provided them.
158
+     *
159
+     * @var string
160
+     */
161
+    protected $_queryDelimiter = '?', $_queryStringDelimiter = '&', $_queryBracketsEscaped = true;
162
+
163
+    /**
164
+     * Constructed servlet full path URLs
165
+     *
166
+     * @var string
167
+     */
168
+    protected $_pingUrl, $_updateUrl, $_searchUrl, $_threadsUrl;
169
+
170
+    /**
171
+     * Keep track of whether our URLs have been constructed
172
+     *
173
+     * @var boolean
174
+     */
175
+    protected $_urlsInited = false;
176
+
177
+    /**
178
+     * HTTP Transport implementation (pluggable)
179
+     *
180
+     * @var Apache_Solr_HttpTransport_Interface
181
+     */
182
+    protected $_httpTransport = false;
183
+
184
+    /**
185
+     * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
186
+     *
187
+     * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
188
+     *
189
+     * @param string $value
190
+     * @return string
191
+     */
192
+    static public function escape($value)
193
+    {
194
+        //list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
195
+        $pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
196
+        $replace = '\\\$1';
197
+
198
+        return preg_replace($pattern, $replace, $value);
199
+    }
200
+
201
+    /**
202
+     * Escape a value meant to be contained in a phrase for special query characters
203
+     *
204
+     * @param string $value
205
+     * @return string
206
+     */
207
+    static public function escapePhrase($value)
208
+    {
209
+        $pattern = '/("|\\\)/';
210
+        $replace = '\\\$1';
211
+
212
+        return preg_replace($pattern, $replace, $value);
213
+    }
214
+
215
+    /**
216
+     * Convenience function for creating phrase syntax from a value
217
+     *
218
+     * @param string $value
219
+     * @return string
220
+     */
221
+    static public function phrase($value)
222
+    {
223
+        return '"' . self::escapePhrase($value) . '"';
224
+    }
225
+
226
+    /**
227
+     * Constructor. All parameters are optional and will take on default values
228
+     * if not specified.
229
+     *
230
+     * @param string $host
231
+     * @param string $port
232
+     * @param string $path
233
+     * @param Apache_Solr_HttpTransport_Interface $httpTransport
234
+     */
235
+    public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = false)
236
+    {
237
+        $this->setHost($host);
238
+        $this->setPort($port);
239
+        $this->setPath($path);
240
+
241
+        $this->_initUrls();
242
+
243
+        if ($httpTransport)
244
+        {
245
+            $this->setHttpTransport($httpTransport);
246
+        }
247
+
248
+        // check that our php version is >= 5.1.3 so we can correct for http_build_query behavior later
249
+        $this->_queryBracketsEscaped = version_compare(phpversion(), '5.1.3', '>=');
250
+    }
251
+
252
+    /**
253
+     * Return a valid http URL given this server's host, port and path and a provided servlet name
254
+     *
255
+     * @param string $servlet
256
+     * @return string
257
+     */
258
+    protected function _constructUrl($servlet, $params = array())
259
+    {
260
+        if (count($params))
261
+        {
262
+            //escape all parameters appropriately for inclusion in the query string
263
+            $escapedParams = array();
264
+
265
+            foreach ($params as $key => $value)
266
+            {
267
+                $escapedParams[] = urlencode($key) . '=' . urlencode($value);
268
+            }
269
+
270
+            $queryString = $this->_queryDelimiter . implode($this->_queryStringDelimiter, $escapedParams);
271
+        }
272
+        else
273
+        {
274
+            $queryString = '';
275
+        }
276
+
277
+        return 'http://' . $this->_host . ':' . $this->_port . $this->_path . $servlet . $queryString;
278
+    }
279
+
280
+    /**
281
+     * Construct the Full URLs for the three servlets we reference
282
+     */
283
+    protected function _initUrls()
284
+    {
285
+        //Initialize our full servlet URLs now that we have server information
286
+        $this->_extractUrl = $this->_constructUrl(self::EXTRACT_SERVLET);
287
+        $this->_pingUrl = $this->_constructUrl(self::PING_SERVLET);
288
+        $this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET);
289
+        $this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array('wt' => self::SOLR_WRITER ));
290
+        $this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array('wt' => self::SOLR_WRITER ));
291
+
292
+        $this->_urlsInited = true;
293
+    }
294
+
295
+    protected function _generateQueryString($params)
296
+    {
297
+        // use http_build_query to encode our arguments because its faster
298
+        // than urlencoding all the parts ourselves in a loop
299
+        //
300
+        // because http_build_query treats arrays differently than we want to, correct the query
301
+        // string by changing foo[#]=bar (# being an actual number) parameter strings to just
302
+        // multiple foo=bar strings. This regex should always work since '=' will be urlencoded
303
+        // anywhere else the regex isn't expecting it
304
+        //
305
+        // NOTE: before php 5.1.3 brackets were not url encoded by http_build query - we've checked
306
+        // the php version in the constructor and put the results in the instance variable. Also, before
307
+        // 5.1.2 the arg_separator parameter was not available, so don't use it
308
+        if ($this->_queryBracketsEscaped)
309
+        {
310
+            $queryString = http_build_query($params, null, $this->_queryStringDelimiter);
311
+            return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
312
+        }
313
+        else
314
+        {
315
+            $queryString = http_build_query($params);
316
+            return preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/', '=', $queryString);
317
+        }
318
+    }
319
+
320
+    /**
321
+     * Central method for making a get operation against this Solr Server
322
+     *
323
+     * @param string $url
324
+     * @param float $timeout Read timeout in seconds
325
+     * @return Apache_Solr_Response
326
+     *
327
+     * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
328
+     */
329
+    protected function _sendRawGet($url, $timeout = FALSE)
330
+    {
331
+        $httpTransport = $this->getHttpTransport();
332
+
333
+        $httpResponse = $httpTransport->performGetRequest($url, $timeout);
334
+        $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
335
+
336
+        if ($solrResponse->getHttpStatus() != 200)
337
+        {
338
+            throw new Apache_Solr_HttpTransportException($solrResponse);
339
+        }
340
+
341
+        return $solrResponse;
342
+    }
343
+
344
+    /**
345
+     * Central method for making a post operation against this Solr Server
346
+     *
347
+     * @param string $url
348
+     * @param string $rawPost
349
+     * @param float $timeout Read timeout in seconds
350
+     * @param string $contentType
351
+     * @return Apache_Solr_Response
352
+     *
353
+     * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
354
+     */
355
+    protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
356
+    {
357
+        $httpTransport = $this->getHttpTransport();
358
+
359
+        $httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout);
360
+        $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
361
+
362
+        if ($solrResponse->getHttpStatus() != 200)
363
+        {
364
+            throw new Apache_Solr_HttpTransportException($solrResponse);
365
+        }
366
+
367
+        return $solrResponse;
368
+    }
369
+
370
+    /**
371
+     * Returns the set host
372
+     *
373
+     * @return string
374
+     */
375
+    public function getHost()
376
+    {
377
+        return $this->_host;
378
+    }
379
+
380
+    /**
381
+     * Set the host used. If empty will fallback to constants
382
+     *
383
+     * @param string $host
384
+     *
385
+     * @throws Apache_Solr_InvalidArgumentException If the host parameter is empty
386
+     */
387
+    public function setHost($host)
388
+    {
389
+        //Use the provided host or use the default
390
+        if (empty($host))
391
+        {
392
+            throw new Apache_Solr_InvalidArgumentException('Host parameter is empty');
393
+        }
394
+        else
395
+        {
396
+            $this->_host = $host;
397
+        }
398
+
399
+        if ($this->_urlsInited)
400
+        {
401
+            $this->_initUrls();
402
+        }
403
+    }
404
+
405
+    /**
406
+     * Get the set port
407
+     *
408
+     * @return integer
409
+     */
410
+    public function getPort()
411
+    {
412
+        return $this->_port;
413
+    }
414
+
415
+    /**
416
+     * Set the port used. If empty will fallback to constants
417
+     *
418
+     * @param integer $port
419
+     *
420
+     * @throws Apache_Solr_InvalidArgumentException If the port parameter is empty
421
+     */
422
+    public function setPort($port)
423
+    {
424
+        //Use the provided port or use the default
425
+        $port = (int) $port;
426
+
427
+        if ($port <= 0)
428
+        {
429
+            throw new Apache_Solr_InvalidArgumentException('Port is not a valid port number');
430
+        }
431
+        else
432
+        {
433
+            $this->_port = $port;
434
+        }
435
+
436
+        if ($this->_urlsInited)
437
+        {
438
+            $this->_initUrls();
439
+        }
440
+    }
441
+
442
+    /**
443
+     * Get the set path.
444
+     *
445
+     * @return string
446
+     */
447
+    public function getPath()
448
+    {
449
+        return $this->_path;
450
+    }
451
+
452
+    /**
453
+     * Set the path used. If empty will fallback to constants
454
+     *
455
+     * @param string $path
456
+     */
457
+    public function setPath($path)
458
+    {
459
+        $path = trim($path, '/');
460
+
461
+        $this->_path = '/' . $path . '/';
462
+
463
+        if ($this->_urlsInited)
464
+        {
465
+            $this->_initUrls();
466
+        }
467
+    }
468
+
469
+    /**
470
+     * Get the current configured HTTP Transport
471
+     *
472
+     * @return HttpTransportInterface
473
+     */
474
+    public function getHttpTransport()
475
+    {
476
+        // lazy load a default if one has not be set
477
+        if ($this->_httpTransport === false)
478
+        {
479
+            require_once(dirname(__FILE__) . '/HttpTransport/FileGetContents.php');
480
+
481
+            $this->_httpTransport = new Apache_Solr_HttpTransport_FileGetContents();
482
+        }
483
+
484
+        return $this->_httpTransport;
485
+    }
486
+
487
+    /**
488
+     * Set the HTTP Transport implemenation that will be used for all HTTP requests
489
+     *
490
+     * @param Apache_Solr_HttpTransport_Interface
491
+     */
492
+    public function setHttpTransport(Apache_Solr_HttpTransport_Interface $httpTransport)
493
+    {
494
+        $this->_httpTransport = $httpTransport;
495
+    }
496
+
497
+    /**
498
+     * Set the create documents flag. This determines whether {@link Apache_Solr_Response} objects will
499
+     * parse the response and create {@link Apache_Solr_Document} instances in place.
500
+     *
501
+     * @param boolean $createDocuments
502
+     */
503
+    public function setCreateDocuments($createDocuments)
504
+    {
505
+        $this->_createDocuments = (bool) $createDocuments;
506
+    }
507
+
508
+    /**
509
+     * Get the current state of the create documents flag.
510
+     *
511
+     * @return boolean
512
+     */
513
+    public function getCreateDocuments()
514
+    {
515
+        return $this->_createDocuments;
516
+    }
517
+
518
+    /**
519
+     * Set the collapse single value arrays flag.
520
+     *
521
+     * @param boolean $collapseSingleValueArrays
522
+     */
523
+    public function setCollapseSingleValueArrays($collapseSingleValueArrays)
524
+    {
525
+        $this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
526
+    }
527
+
528
+    /**
529
+     * Get the current state of the collapse single value arrays flag.
530
+     *
531
+     * @return boolean
532
+     */
533
+    public function getCollapseSingleValueArrays()
534
+    {
535
+        return $this->_collapseSingleValueArrays;
536
+    }
537
+
538
+    /**
539
+     * Get the current default timeout setting (initially the default_socket_timeout ini setting)
540
+     * in seconds
541
+     *
542
+     * @return float
543
+     *
544
+     * @deprecated Use the getDefaultTimeout method on the HTTP transport implementation
545
+     */
546
+    public function getDefaultTimeout()
547
+    {
548
+        return $this->getHttpTransport()->getDefaultTimeout();
549
+    }
550
+
551
+    /**
552
+     * Set the default timeout for all calls that aren't passed a specific timeout
553
+     *
554
+     * @param float $timeout Timeout value in seconds
555
+     *
556
+     * @deprecated Use the setDefaultTimeout method on the HTTP transport implementation
557
+     */
558
+    public function setDefaultTimeout($timeout)
559
+    {
560
+        $this->getHttpTransport()->setDefaultTimeout($timeout);
561
+    }
562
+
563
+    /**
564
+     * Set how NamedLists should be formatted in the response data. This mainly effects
565
+     * the facet counts format.
566
+     *
567
+     * @param string $namedListTreatment
568
+     * @throws Apache_Solr_InvalidArgumentException If invalid option is set
569
+     */
570
+    public function setNamedListTreatment($namedListTreatment)
571
+    {
572
+        switch ((string) $namedListTreatment)
573
+        {
574
+            case Apache_Solr_Service::NAMED_LIST_FLAT:
575
+                $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT;
576
+                break;
577
+
578
+            case Apache_Solr_Service::NAMED_LIST_MAP:
579
+                $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_MAP;
580
+                break;
581
+
582
+            default:
583
+                throw new Apache_Solr_InvalidArgumentException('Not a valid named list treatement option');
584
+        }
585
+    }
586
+
587
+    /**
588
+     * Get the current setting for named list treatment.
589
+     *
590
+     * @return string
591
+     */
592
+    public function getNamedListTreatment()
593
+    {
594
+        return $this->_namedListTreatment;
595
+    }
596
+
597
+    /**
598
+     * Set the string used to separate the path form the query string.
599
+     * Defaulted to '?'
600
+     *
601
+     * @param string $queryDelimiter
602
+     */
603
+    public function setQueryDelimiter($queryDelimiter)
604
+    {
605
+        $this->_queryDelimiter = $queryDelimiter;
606
+    }
607
+
608
+    /**
609
+     * Set the string used to separate the parameters in thequery string
610
+     * Defaulted to '&'
611
+     *
612
+     * @param string $queryStringDelimiter
613
+     */
614
+    public function setQueryStringDelimiter($queryStringDelimiter)
615
+    {
616
+        $this->_queryStringDelimiter = $queryStringDelimiter;
617
+    }
618
+
619
+    /**
620
+     * Call the /admin/ping servlet, can be used to quickly tell if a connection to the
621
+     * server is able to be made.
622
+     *
623
+     * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
624
+     * @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
625
+     */
626
+    public function ping($timeout = 2)
627
+    {
628
+        $start = microtime(true);
629 629
 		
630
-		$httpTransport = $this->getHttpTransport();
631
-
632
-		$httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout);
633
-		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
634
-
635
-		if ($solrResponse->getHttpStatus() == 200)
636
-		{
637
-			return microtime(true) - $start;
638
-		}
639
-		else
640
-		{
641
-			return false;
642
-		}
643
-	}
644
-
645
-	/**
646
-	 * Call the /admin/threads servlet and retrieve information about all threads in the
647
-	 * Solr servlet's thread group. Useful for diagnostics.
648
-	 *
649
-	 * @return Apache_Solr_Response
650
-	 *
651
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
652
-	 */
653
-	public function threads()
654
-	{
655
-		return $this->_sendRawGet($this->_threadsUrl);
656
-	}
657
-
658
-	/**
659
-	 * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
660
-	 * should be a complete and well formed "add" xml document.
661
-	 *
662
-	 * @param string $rawPost
663
-	 * @return Apache_Solr_Response
664
-	 *
665
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
666
-	 */
667
-	public function add($rawPost)
668
-	{
669
-		return $this->_sendRawPost($this->_updateUrl, $rawPost);
670
-	}
671
-
672
-	/**
673
-	 * Add a Solr Document to the index
674
-	 *
675
-	 * @param Apache_Solr_Document $document
676
-	 * @param boolean $allowDups
677
-	 * @param boolean $overwritePending
678
-	 * @param boolean $overwriteCommitted
679
-	 * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
680
-	 * @return Apache_Solr_Response
681
-	 *
682
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
683
-	 */
684
-	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
685
-	{
686
-		$dupValue = $allowDups ? 'true' : 'false';
687
-		$pendingValue = $overwritePending ? 'true' : 'false';
688
-		$committedValue = $overwriteCommitted ? 'true' : 'false';
630
+        $httpTransport = $this->getHttpTransport();
631
+
632
+        $httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout);
633
+        $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
634
+
635
+        if ($solrResponse->getHttpStatus() == 200)
636
+        {
637
+            return microtime(true) - $start;
638
+        }
639
+        else
640
+        {
641
+            return false;
642
+        }
643
+    }
644
+
645
+    /**
646
+     * Call the /admin/threads servlet and retrieve information about all threads in the
647
+     * Solr servlet's thread group. Useful for diagnostics.
648
+     *
649
+     * @return Apache_Solr_Response
650
+     *
651
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
652
+     */
653
+    public function threads()
654
+    {
655
+        return $this->_sendRawGet($this->_threadsUrl);
656
+    }
657
+
658
+    /**
659
+     * Raw Add Method. Takes a raw post body and sends it to the update service.  Post body
660
+     * should be a complete and well formed "add" xml document.
661
+     *
662
+     * @param string $rawPost
663
+     * @return Apache_Solr_Response
664
+     *
665
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
666
+     */
667
+    public function add($rawPost)
668
+    {
669
+        return $this->_sendRawPost($this->_updateUrl, $rawPost);
670
+    }
671
+
672
+    /**
673
+     * Add a Solr Document to the index
674
+     *
675
+     * @param Apache_Solr_Document $document
676
+     * @param boolean $allowDups
677
+     * @param boolean $overwritePending
678
+     * @param boolean $overwriteCommitted
679
+     * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
680
+     * @return Apache_Solr_Response
681
+     *
682
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
683
+     */
684
+    public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
685
+    {
686
+        $dupValue = $allowDups ? 'true' : 'false';
687
+        $pendingValue = $overwritePending ? 'true' : 'false';
688
+        $committedValue = $overwriteCommitted ? 'true' : 'false';
689 689
 		
690
-		$commitWithin = (int) $commitWithin;
691
-		$commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
690
+        $commitWithin = (int) $commitWithin;
691
+        $commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
692 692
 		
693
-		$rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
694
-		$rawPost .= $this->_documentToXmlFragment($document);
695
-		$rawPost .= '</add>';
696
-
697
-		return $this->add($rawPost);
698
-	}
699
-
700
-	/**
701
-	 * Add an array of Solr Documents to the index all at once
702
-	 *
703
-	 * @param array $documents Should be an array of Apache_Solr_Document instances
704
-	 * @param boolean $allowDups
705
-	 * @param boolean $overwritePending
706
-	 * @param boolean $overwriteCommitted
707
-	 * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
708
-	 * @return Apache_Solr_Response
709
-	 *
710
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
711
-	 */
712
-	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
713
-	{
714
-		$dupValue = $allowDups ? 'true' : 'false';
715
-		$pendingValue = $overwritePending ? 'true' : 'false';
716
-		$committedValue = $overwriteCommitted ? 'true' : 'false';
717
-
718
-		$commitWithin = (int) $commitWithin;
719
-		$commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
720
-
721
-		$rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
722
-
723
-		foreach ($documents as $document)
724
-		{
725
-			if ($document instanceof Apache_Solr_Document)
726
-			{
727
-				$rawPost .= $this->_documentToXmlFragment($document);
728
-			}
729
-		}
730
-
731
-		$rawPost .= '</add>';
732
-
733
-		return $this->add($rawPost);
734
-	}
735
-
736
-	/**
737
-	 * Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
738
-	 *
739
-	 * @return string
740
-	 */
741
-	protected function _documentToXmlFragment(Apache_Solr_Document $document)
742
-	{
743
-		$xml = '<doc';
744
-
745
-		if ($document->getBoost() !== false)
746
-		{
747
-			$xml .= ' boost="' . $document->getBoost() . '"';
748
-		}
749
-
750
-		$xml .= '>';
751
-
752
-		foreach ($document as $key => $value)
753
-		{
754
-			$key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
755
-			$fieldBoost = $document->getFieldBoost($key);
756
-
757
-			if (is_array($value))
758
-			{
759
-				foreach ($value as $multivalue)
760
-				{
761
-					$xml .= '<field name="' . $key . '"';
762
-
763
-					if ($fieldBoost !== false)
764
-					{
765
-						$xml .= ' boost="' . $fieldBoost . '"';
766
-
767
-						// only set the boost for the first field in the set
768
-						$fieldBoost = false;
769
-					}
770
-
771
-					$multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
772
-
773
-					$xml .= '>' . $multivalue . '</field>';
774
-				}
775
-			}
776
-			else
777
-			{
778
-				$xml .= '<field name="' . $key . '"';
779
-
780
-				if ($fieldBoost !== false)
781
-				{
782
-					$xml .= ' boost="' . $fieldBoost . '"';
783
-				}
784
-
785
-				$value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
786
-
787
-				$xml .= '>' . $value . '</field>';
788
-			}
789
-		}
790
-
791
-		$xml .= '</doc>';
792
-
793
-		// replace any control characters to avoid Solr XML parser exception
794
-		return $this->_stripCtrlChars($xml);
795
-	}
796
-
797
-	/**
798
-	 * Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space.
799
-	 *
800
-	 * @param string $string
801
-	 * @return string
802
-	 */
803
-	protected function _stripCtrlChars($string)
804
-	{
805
-		// See:  http://w3.org/International/questions/qa-forms-utf-8.html
806
-		// Printable utf-8 does not include any of these chars below x7F
807
-		return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@', ' ', $string);
808
-	}
809
-
810
-	/**
811
-	 * Send a commit command.  Will be synchronous unless both wait parameters are set to false.
812
-	 *
813
-	 * @param boolean $expungeDeletes Defaults to false, merge segments with deletes away
814
-	 * @param boolean $waitFlush Defaults to true,  block until index changes are flushed to disk
815
-	 * @param boolean $waitSearcher Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible
816
-	 * @param float $timeout Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour
817
-	 * @return Apache_Solr_Response
818
-	 *
819
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
820
-	 */
821
-	public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
822
-	{
823
-		$expungeValue = $expungeDeletes ? 'true' : 'false';
824
-		$flushValue = $waitFlush ? 'true' : 'false';
825
-		$searcherValue = $waitSearcher ? 'true' : 'false';
826
-
827
-		$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
828
-
829
-		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
830
-	}
831
-
832
-	/**
833
-	 * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
834
-	 * a complete and well formed "delete" xml document
835
-	 *
836
-	 * @param string $rawPost Expected to be utf-8 encoded xml document
837
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
838
-	 * @return Apache_Solr_Response
839
-	 *
840
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
841
-	 */
842
-	public function delete($rawPost, $timeout = 3600)
843
-	{
844
-		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
845
-	}
846
-
847
-	/**
848
-	 * Create a delete document based on document ID
849
-	 *
850
-	 * @param string $id Expected to be utf-8 encoded
851
-	 * @param boolean $fromPending
852
-	 * @param boolean $fromCommitted
853
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
854
-	 * @return Apache_Solr_Response
855
-	 *
856
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
857
-	 */
858
-	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
859
-	{
860
-		$pendingValue = $fromPending ? 'true' : 'false';
861
-		$committedValue = $fromCommitted ? 'true' : 'false';
862
-
863
-		//escape special xml characters
864
-		$id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
865
-
866
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><id>' . $id . '</id></delete>';
867
-
868
-		return $this->delete($rawPost, $timeout);
869
-	}
870
-
871
-	/**
872
-	 * Create and post a delete document based on multiple document IDs.
873
-	 *
874
-	 * @param array $ids Expected to be utf-8 encoded strings
875
-	 * @param boolean $fromPending
876
-	 * @param boolean $fromCommitted
877
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
878
-	 * @return Apache_Solr_Response
879
-	 *
880
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
881
-	 */
882
-	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
883
-	{
884
-		$pendingValue = $fromPending ? 'true' : 'false';
885
-		$committedValue = $fromCommitted ? 'true' : 'false';
886
-
887
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '">';
888
-
889
-		foreach ($ids as $id)
890
-		{
891
-			//escape special xml characters
892
-			$id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
893
-
894
-			$rawPost .= '<id>' . $id . '</id>';
895
-		}
896
-
897
-		$rawPost .= '</delete>';
898
-
899
-		return $this->delete($rawPost, $timeout);
900
-	}
901
-
902
-	/**
903
-	 * Create a delete document based on a query and submit it
904
-	 *
905
-	 * @param string $rawQuery Expected to be utf-8 encoded
906
-	 * @param boolean $fromPending
907
-	 * @param boolean $fromCommitted
908
-	 * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
909
-	 * @return Apache_Solr_Response
910
-	 *
911
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
912
-	 */
913
-	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
914
-	{
915
-		$pendingValue = $fromPending ? 'true' : 'false';
916
-		$committedValue = $fromCommitted ? 'true' : 'false';
917
-
918
-		// escape special xml characters
919
-		$rawQuery = htmlspecialchars($rawQuery, ENT_NOQUOTES, 'UTF-8');
920
-
921
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><query>' . $rawQuery . '</query></delete>';
922
-
923
-		return $this->delete($rawPost, $timeout);
924
-	}
925
-
926
-	/**
927
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
928
-	 * to use Solr Cell and what parameters are available.
929
-	 *
930
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
931
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
932
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
933
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
934
-	 *
935
-	 * @param string $file Path to file to extract data from
936
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
937
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
938
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
939
-	 *
940
-	 * @return Apache_Solr_Response
941
-	 *
942
-	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
943
-	 */
944
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
945
-	{
946
-		// check if $params is an array (allow null for default empty array)
947
-		if (!is_null($params))
948
-		{
949
-			if (!is_array($params))
950
-			{
951
-				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
952
-			}
953
-		}
954
-		else
955
-		{
956
-			$params = array();
957
-		}
693
+        $rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
694
+        $rawPost .= $this->_documentToXmlFragment($document);
695
+        $rawPost .= '</add>';
696
+
697
+        return $this->add($rawPost);
698
+    }
699
+
700
+    /**
701
+     * Add an array of Solr Documents to the index all at once
702
+     *
703
+     * @param array $documents Should be an array of Apache_Solr_Document instances
704
+     * @param boolean $allowDups
705
+     * @param boolean $overwritePending
706
+     * @param boolean $overwriteCommitted
707
+     * @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages#The_Update_Schema} for details.  If left empty this property will not be set in the request.
708
+     * @return Apache_Solr_Response
709
+     *
710
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
711
+     */
712
+    public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
713
+    {
714
+        $dupValue = $allowDups ? 'true' : 'false';
715
+        $pendingValue = $overwritePending ? 'true' : 'false';
716
+        $committedValue = $overwriteCommitted ? 'true' : 'false';
717
+
718
+        $commitWithin = (int) $commitWithin;
719
+        $commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
720
+
721
+        $rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
722
+
723
+        foreach ($documents as $document)
724
+        {
725
+            if ($document instanceof Apache_Solr_Document)
726
+            {
727
+                $rawPost .= $this->_documentToXmlFragment($document);
728
+            }
729
+        }
730
+
731
+        $rawPost .= '</add>';
732
+
733
+        return $this->add($rawPost);
734
+    }
735
+
736
+    /**
737
+     * Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call
738
+     *
739
+     * @return string
740
+     */
741
+    protected function _documentToXmlFragment(Apache_Solr_Document $document)
742
+    {
743
+        $xml = '<doc';
744
+
745
+        if ($document->getBoost() !== false)
746
+        {
747
+            $xml .= ' boost="' . $document->getBoost() . '"';
748
+        }
749
+
750
+        $xml .= '>';
751
+
752
+        foreach ($document as $key => $value)
753
+        {
754
+            $key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
755
+            $fieldBoost = $document->getFieldBoost($key);
756
+
757
+            if (is_array($value))
758
+            {
759
+                foreach ($value as $multivalue)
760
+                {
761
+                    $xml .= '<field name="' . $key . '"';
762
+
763
+                    if ($fieldBoost !== false)
764
+                    {
765
+                        $xml .= ' boost="' . $fieldBoost . '"';
766
+
767
+                        // only set the boost for the first field in the set
768
+                        $fieldBoost = false;
769
+                    }
770
+
771
+                    $multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
772
+
773
+                    $xml .= '>' . $multivalue . '</field>';
774
+                }
775
+            }
776
+            else
777
+            {
778
+                $xml .= '<field name="' . $key . '"';
779
+
780
+                if ($fieldBoost !== false)
781
+                {
782
+                    $xml .= ' boost="' . $fieldBoost . '"';
783
+                }
784
+
785
+                $value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
786
+
787
+                $xml .= '>' . $value . '</field>';
788
+            }
789
+        }
790
+
791
+        $xml .= '</doc>';
792
+
793
+        // replace any control characters to avoid Solr XML parser exception
794
+        return $this->_stripCtrlChars($xml);
795
+    }
796
+
797
+    /**
798
+     * Replace control (non-printable) characters from string that are invalid to Solr's XML parser with a space.
799
+     *
800
+     * @param string $string
801
+     * @return string
802
+     */
803
+    protected function _stripCtrlChars($string)
804
+    {
805
+        // See:  http://w3.org/International/questions/qa-forms-utf-8.html
806
+        // Printable utf-8 does not include any of these chars below x7F
807
+        return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@', ' ', $string);
808
+    }
809
+
810
+    /**
811
+     * Send a commit command.  Will be synchronous unless both wait parameters are set to false.
812
+     *
813
+     * @param boolean $expungeDeletes Defaults to false, merge segments with deletes away
814
+     * @param boolean $waitFlush Defaults to true,  block until index changes are flushed to disk
815
+     * @param boolean $waitSearcher Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible
816
+     * @param float $timeout Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour
817
+     * @return Apache_Solr_Response
818
+     *
819
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
820
+     */
821
+    public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
822
+    {
823
+        $expungeValue = $expungeDeletes ? 'true' : 'false';
824
+        $flushValue = $waitFlush ? 'true' : 'false';
825
+        $searcherValue = $waitSearcher ? 'true' : 'false';
826
+
827
+        $rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
828
+
829
+        return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
830
+    }
831
+
832
+    /**
833
+     * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be
834
+     * a complete and well formed "delete" xml document
835
+     *
836
+     * @param string $rawPost Expected to be utf-8 encoded xml document
837
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
838
+     * @return Apache_Solr_Response
839
+     *
840
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
841
+     */
842
+    public function delete($rawPost, $timeout = 3600)
843
+    {
844
+        return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
845
+    }
846
+
847
+    /**
848
+     * Create a delete document based on document ID
849
+     *
850
+     * @param string $id Expected to be utf-8 encoded
851
+     * @param boolean $fromPending
852
+     * @param boolean $fromCommitted
853
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
854
+     * @return Apache_Solr_Response
855
+     *
856
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
857
+     */
858
+    public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
859
+    {
860
+        $pendingValue = $fromPending ? 'true' : 'false';
861
+        $committedValue = $fromCommitted ? 'true' : 'false';
862
+
863
+        //escape special xml characters
864
+        $id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
865
+
866
+        $rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><id>' . $id . '</id></delete>';
867
+
868
+        return $this->delete($rawPost, $timeout);
869
+    }
870
+
871
+    /**
872
+     * Create and post a delete document based on multiple document IDs.
873
+     *
874
+     * @param array $ids Expected to be utf-8 encoded strings
875
+     * @param boolean $fromPending
876
+     * @param boolean $fromCommitted
877
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
878
+     * @return Apache_Solr_Response
879
+     *
880
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
881
+     */
882
+    public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
883
+    {
884
+        $pendingValue = $fromPending ? 'true' : 'false';
885
+        $committedValue = $fromCommitted ? 'true' : 'false';
886
+
887
+        $rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '">';
888
+
889
+        foreach ($ids as $id)
890
+        {
891
+            //escape special xml characters
892
+            $id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
893
+
894
+            $rawPost .= '<id>' . $id . '</id>';
895
+        }
896
+
897
+        $rawPost .= '</delete>';
898
+
899
+        return $this->delete($rawPost, $timeout);
900
+    }
901
+
902
+    /**
903
+     * Create a delete document based on a query and submit it
904
+     *
905
+     * @param string $rawQuery Expected to be utf-8 encoded
906
+     * @param boolean $fromPending
907
+     * @param boolean $fromCommitted
908
+     * @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception)
909
+     * @return Apache_Solr_Response
910
+     *
911
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
912
+     */
913
+    public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
914
+    {
915
+        $pendingValue = $fromPending ? 'true' : 'false';
916
+        $committedValue = $fromCommitted ? 'true' : 'false';
917
+
918
+        // escape special xml characters
919
+        $rawQuery = htmlspecialchars($rawQuery, ENT_NOQUOTES, 'UTF-8');
920
+
921
+        $rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><query>' . $rawQuery . '</query></delete>';
922
+
923
+        return $this->delete($rawPost, $timeout);
924
+    }
925
+
926
+    /**
927
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
928
+     * to use Solr Cell and what parameters are available.
929
+     *
930
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
931
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
932
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
933
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
934
+     *
935
+     * @param string $file Path to file to extract data from
936
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
937
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
938
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
939
+     *
940
+     * @return Apache_Solr_Response
941
+     *
942
+     * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
943
+     */
944
+    public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
945
+    {
946
+        // check if $params is an array (allow null for default empty array)
947
+        if (!is_null($params))
948
+        {
949
+            if (!is_array($params))
950
+            {
951
+                throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
952
+            }
953
+        }
954
+        else
955
+        {
956
+            $params = array();
957
+        }
958 958
 		
959
-		// if $file is an http request, defer to extractFromUrl instead
960
-		if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://')
961
-		{
962
-			return $this->extractFromUrl($file, $params, $document, $mimetype);
963
-		}
959
+        // if $file is an http request, defer to extractFromUrl instead
960
+        if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://')
961
+        {
962
+            return $this->extractFromUrl($file, $params, $document, $mimetype);
963
+        }
964 964
 		
965
-		// read the contents of the file
966
-		$contents = @file_get_contents($file);
967
-
968
-		if ($contents !== false)
969
-		{
970
-			// add the resource.name parameter if not specified
971
-			if (!isset($params['resource.name']))
972
-			{
973
-				$params['resource.name'] = basename($file);
974
-			}
975
-
976
-			// delegate the rest to extractFromString
977
-			return $this->extractFromString($contents, $params, $document, $mimetype);
978
-		}
979
-		else
980
-		{
981
-			throw new Apache_Solr_InvalidArgumentException("File '{$file}' is empty or could not be read");
982
-		}
983
-	}
965
+        // read the contents of the file
966
+        $contents = @file_get_contents($file);
967
+
968
+        if ($contents !== false)
969
+        {
970
+            // add the resource.name parameter if not specified
971
+            if (!isset($params['resource.name']))
972
+            {
973
+                $params['resource.name'] = basename($file);
974
+            }
975
+
976
+            // delegate the rest to extractFromString
977
+            return $this->extractFromString($contents, $params, $document, $mimetype);
978
+        }
979
+        else
980
+        {
981
+            throw new Apache_Solr_InvalidArgumentException("File '{$file}' is empty or could not be read");
982
+        }
983
+    }
984 984
 	
985
-	/**
986
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
987
-	 * to use Solr Cell and what parameters are available.
988
-	 *
989
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
990
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
991
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
992
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
993
-	 *
994
-	 * @param string $data Data that will be passed to Solr Cell
995
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
996
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
997
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
998
-	 *
999
-	 * @return Apache_Solr_Response
1000
-	 *
1001
-	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
1002
-	 *
1003
-	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
1004
-	 */
1005
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1006
-	{
1007
-		// check if $params is an array (allow null for default empty array)
1008
-		if (!is_null($params))
1009
-		{
1010
-			if (!is_array($params))
1011
-			{
1012
-				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1013
-			}
1014
-		}
1015
-		else
1016
-		{
1017
-			$params = array();
1018
-		}
1019
-
1020
-		// make sure we receive our response in JSON and have proper name list treatment
1021
-		$params['wt'] = self::SOLR_WRITER;
1022
-		$params['json.nl'] = $this->_namedListTreatment;
1023
-
1024
-		// check if $document is an Apache_Solr_Document instance
1025
-		if (!is_null($document) && $document instanceof Apache_Solr_Document)
1026
-		{
1027
-			// iterate document, adding literal.* and boost.* fields to $params as appropriate
1028
-			foreach ($document as $field => $fieldValue)
1029
-			{
1030
-				// check if we need to add a boost.* parameters
1031
-				$fieldBoost = $document->getFieldBoost($field);
1032
-
1033
-				if ($fieldBoost !== false)
1034
-				{
1035
-					$params["boost.{$field}"] = $fieldBoost;
1036
-				}
1037
-
1038
-				// add the literal.* parameter
1039
-				$params["literal.{$field}"] = $fieldValue;
1040
-			}
1041
-		}
1042
-
1043
-		// params will be sent to SOLR in the QUERY STRING
1044
-		$queryString = $this->_generateQueryString($params);
1045
-
1046
-		// the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype
1047
-		return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, false, $mimetype);
1048
-	}
985
+    /**
986
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
987
+     * to use Solr Cell and what parameters are available.
988
+     *
989
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
990
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
991
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
992
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
993
+     *
994
+     * @param string $data Data that will be passed to Solr Cell
995
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
996
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
997
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
998
+     *
999
+     * @return Apache_Solr_Response
1000
+     *
1001
+     * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
1002
+     *
1003
+     * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
1004
+     */
1005
+    public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1006
+    {
1007
+        // check if $params is an array (allow null for default empty array)
1008
+        if (!is_null($params))
1009
+        {
1010
+            if (!is_array($params))
1011
+            {
1012
+                throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1013
+            }
1014
+        }
1015
+        else
1016
+        {
1017
+            $params = array();
1018
+        }
1019
+
1020
+        // make sure we receive our response in JSON and have proper name list treatment
1021
+        $params['wt'] = self::SOLR_WRITER;
1022
+        $params['json.nl'] = $this->_namedListTreatment;
1023
+
1024
+        // check if $document is an Apache_Solr_Document instance
1025
+        if (!is_null($document) && $document instanceof Apache_Solr_Document)
1026
+        {
1027
+            // iterate document, adding literal.* and boost.* fields to $params as appropriate
1028
+            foreach ($document as $field => $fieldValue)
1029
+            {
1030
+                // check if we need to add a boost.* parameters
1031
+                $fieldBoost = $document->getFieldBoost($field);
1032
+
1033
+                if ($fieldBoost !== false)
1034
+                {
1035
+                    $params["boost.{$field}"] = $fieldBoost;
1036
+                }
1037
+
1038
+                // add the literal.* parameter
1039
+                $params["literal.{$field}"] = $fieldValue;
1040
+            }
1041
+        }
1042
+
1043
+        // params will be sent to SOLR in the QUERY STRING
1044
+        $queryString = $this->_generateQueryString($params);
1045
+
1046
+        // the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype
1047
+        return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, false, $mimetype);
1048
+    }
1049 1049
 	
1050
-	/**
1051
-	 * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
1052
-	 * to use Solr Cell and what parameters are available.
1053
-	 *
1054
-	 * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
1055
-	 * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
1056
-	 * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
1057
-	 * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
1058
-	 *
1059
-	 * @param string $url URL
1060
-	 * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
1061
-	 * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
1062
-	 * @param string $mimetype optional mimetype specification (for the file being extracted)
1063
-	 *
1064
-	 * @return Apache_Solr_Response
1065
-	 *
1066
-	 * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
1067
-	 */
1068
-	public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1069
-	{
1070
-		// check if $params is an array (allow null for default empty array)
1071
-		if (!is_null($params))
1072
-		{
1073
-			if (!is_array($params))
1074
-			{
1075
-				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1076
-			}
1077
-		}
1078
-		else
1079
-		{
1080
-			$params = array();
1081
-		}
1082
-
1083
-		$httpTransport = $this->getHttpTransport();
1050
+    /**
1051
+     * Use Solr Cell to extract document contents. See {@link http://wiki.apache.org/solr/ExtractingRequestHandler} for information on how
1052
+     * to use Solr Cell and what parameters are available.
1053
+     *
1054
+     * NOTE: when passing an Apache_Solr_Document instance, field names and boosts will automatically be prepended by "literal." and "boost."
1055
+     * as appropriate. Any keys from the $params array will NOT be treated this way. Any mappings from the document will overwrite key / value
1056
+     * pairs in the params array if they have the same name (e.g. you pass a "literal.id" key and value in your $params array but you also
1057
+     * pass in a document isntance with an "id" field" - the document's value(s) will take precedence).
1058
+     *
1059
+     * @param string $url URL
1060
+     * @param array $params optional array of key value pairs that will be sent with the post (see Solr Cell documentation)
1061
+     * @param Apache_Solr_Document $document optional document that will be used to generate post parameters (literal.* and boost.* params)
1062
+     * @param string $mimetype optional mimetype specification (for the file being extracted)
1063
+     *
1064
+     * @return Apache_Solr_Response
1065
+     *
1066
+     * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
1067
+     */
1068
+    public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1069
+    {
1070
+        // check if $params is an array (allow null for default empty array)
1071
+        if (!is_null($params))
1072
+        {
1073
+            if (!is_array($params))
1074
+            {
1075
+                throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1076
+            }
1077
+        }
1078
+        else
1079
+        {
1080
+            $params = array();
1081
+        }
1082
+
1083
+        $httpTransport = $this->getHttpTransport();
1084 1084
 		
1085
-		// read the contents of the URL using our configured Http Transport and default timeout
1086
-		$httpResponse = $httpTransport->performGetRequest($url);
1085
+        // read the contents of the URL using our configured Http Transport and default timeout
1086
+        $httpResponse = $httpTransport->performGetRequest($url);
1087 1087
 		
1088
-		// check that its a 200 response
1089
-		if ($httpResponse->getStatusCode() == 200)
1090
-		{
1091
-			// add the resource.name parameter if not specified
1092
-			if (!isset($params['resource.name']))
1093
-			{
1094
-				$params['resource.name'] = $url;
1095
-			}
1096
-
1097
-			// delegate the rest to extractFromString
1098
-			return $this->extractFromString($httpResponse->getBody(), $params, $document, $mimetype);
1099
-		}
1100
-		else
1101
-		{
1102
-			throw new Apache_Solr_InvalidArgumentException("URL '{$url}' returned non 200 response code");
1103
-		}
1104
-	}
1105
-
1106
-	/**
1107
-	 * Send an optimize command.  Will be synchronous unless both wait parameters are set
1108
-	 * to false.
1109
-	 *
1110
-	 * @param boolean $waitFlush
1111
-	 * @param boolean $waitSearcher
1112
-	 * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
1113
-	 * @return Apache_Solr_Response
1114
-	 *
1115
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1116
-	 */
1117
-	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
1118
-	{
1119
-		$flushValue = $waitFlush ? 'true' : 'false';
1120
-		$searcherValue = $waitSearcher ? 'true' : 'false';
1121
-
1122
-		$rawPost = '<optimize waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
1123
-
1124
-		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
1125
-	}
1126
-
1127
-	/**
1128
-	 * Simple Search interface
1129
-	 *
1130
-	 * @param string $query The raw query string
1131
-	 * @param int $offset The starting offset for result documents
1132
-	 * @param int $limit The maximum number of result documents to return
1133
-	 * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
1134
-	 * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
1135
-	 * @return Apache_Solr_Response
1136
-	 *
1137
-	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1138
-	 * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
1139
-	 */
1140
-	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET)
1141
-	{
1142
-		// ensure params is an array
1143
-		if (!is_null($params))
1144
-		{
1145
-			if (!is_array($params))
1146
-			{
1147
-				// params was specified but was not an array - invalid
1148
-				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1149
-			}
1150
-		}
1151
-		else
1152
-		{
1153
-			$params = array();
1154
-		}
1088
+        // check that its a 200 response
1089
+        if ($httpResponse->getStatusCode() == 200)
1090
+        {
1091
+            // add the resource.name parameter if not specified
1092
+            if (!isset($params['resource.name']))
1093
+            {
1094
+                $params['resource.name'] = $url;
1095
+            }
1096
+
1097
+            // delegate the rest to extractFromString
1098
+            return $this->extractFromString($httpResponse->getBody(), $params, $document, $mimetype);
1099
+        }
1100
+        else
1101
+        {
1102
+            throw new Apache_Solr_InvalidArgumentException("URL '{$url}' returned non 200 response code");
1103
+        }
1104
+    }
1105
+
1106
+    /**
1107
+     * Send an optimize command.  Will be synchronous unless both wait parameters are set
1108
+     * to false.
1109
+     *
1110
+     * @param boolean $waitFlush
1111
+     * @param boolean $waitSearcher
1112
+     * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
1113
+     * @return Apache_Solr_Response
1114
+     *
1115
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1116
+     */
1117
+    public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
1118
+    {
1119
+        $flushValue = $waitFlush ? 'true' : 'false';
1120
+        $searcherValue = $waitSearcher ? 'true' : 'false';
1121
+
1122
+        $rawPost = '<optimize waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
1123
+
1124
+        return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
1125
+    }
1126
+
1127
+    /**
1128
+     * Simple Search interface
1129
+     *
1130
+     * @param string $query The raw query string
1131
+     * @param int $offset The starting offset for result documents
1132
+     * @param int $limit The maximum number of result documents to return
1133
+     * @param array $params key / value pairs for other query parameters (see Solr documentation), use arrays for parameter keys used more than once (e.g. facet.field)
1134
+     * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST)
1135
+     * @return Apache_Solr_Response
1136
+     *
1137
+     * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1138
+     * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
1139
+     */
1140
+    public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET)
1141
+    {
1142
+        // ensure params is an array
1143
+        if (!is_null($params))
1144
+        {
1145
+            if (!is_array($params))
1146
+            {
1147
+                // params was specified but was not an array - invalid
1148
+                throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1149
+            }
1150
+        }
1151
+        else
1152
+        {
1153
+            $params = array();
1154
+        }
1155 1155
 		
1156
-		// construct our full parameters
1157
-
1158
-		// common parameters in this interface
1159
-		$params['wt'] = self::SOLR_WRITER;
1160
-		$params['json.nl'] = $this->_namedListTreatment;
1161
-
1162
-		$params['q'] = $query;
1163
-		$params['start'] = $offset;
1164
-		$params['rows'] = $limit;
1165
-
1166
-		$queryString = $this->_generateQueryString($params);
1167
-
1168
-		if ($method == self::METHOD_GET)
1169
-		{
1170
-			return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
1171
-		}
1172
-		else if ($method == self::METHOD_POST)
1173
-		{
1174
-			return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8');
1175
-		}
1176
-		else
1177
-		{
1178
-			throw new Apache_Solr_InvalidArgumentException("Unsupported method '$method', please use the Apache_Solr_Service::METHOD_* constants");
1179
-		}
1180
-	}
1156
+        // construct our full parameters
1157
+
1158
+        // common parameters in this interface
1159
+        $params['wt'] = self::SOLR_WRITER;
1160
+        $params['json.nl'] = $this->_namedListTreatment;
1161
+
1162
+        $params['q'] = $query;
1163
+        $params['start'] = $offset;
1164
+        $params['rows'] = $limit;
1165
+
1166
+        $queryString = $this->_generateQueryString($params);
1167
+
1168
+        if ($method == self::METHOD_GET)
1169
+        {
1170
+            return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
1171
+        }
1172
+        else if ($method == self::METHOD_POST)
1173
+        {
1174
+            return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8');
1175
+        }
1176
+        else
1177
+        {
1178
+            throw new Apache_Solr_InvalidArgumentException("Unsupported method '$method', please use the Apache_Solr_Service::METHOD_* constants");
1179
+        }
1180
+    }
1181 1181
 }
1182 1182
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 
39 39
 // See Issue #1 (http://code.google.com/p/solr-php-client/issues/detail?id=1)
40 40
 // Doesn't follow typical include path conventions, but is more convenient for users
41
-require_once(dirname(__FILE__) . '/Exception.php');
42
-require_once(dirname(__FILE__) . '/HttpTransportException.php');
43
-require_once(dirname(__FILE__) . '/InvalidArgumentException.php');
41
+require_once(dirname(__FILE__).'/Exception.php');
42
+require_once(dirname(__FILE__).'/HttpTransportException.php');
43
+require_once(dirname(__FILE__).'/InvalidArgumentException.php');
44 44
 
45
-require_once(dirname(__FILE__) . '/Document.php');
46
-require_once(dirname(__FILE__) . '/Response.php');
45
+require_once(dirname(__FILE__).'/Document.php');
46
+require_once(dirname(__FILE__).'/Response.php');
47 47
 
48
-require_once(dirname(__FILE__) . '/HttpTransport/Interface.php');
48
+require_once(dirname(__FILE__).'/HttpTransport/Interface.php');
49 49
 
50 50
 /**
51 51
  * Starting point for the Solr API. Represents a Solr server resource and has
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 */
221 221
 	static public function phrase($value)
222 222
 	{
223
-		return '"' . self::escapePhrase($value) . '"';
223
+		return '"'.self::escapePhrase($value).'"';
224 224
 	}
225 225
 
226 226
 	/**
@@ -255,26 +255,26 @@  discard block
 block discarded – undo
255 255
 	 * @param string $servlet
256 256
 	 * @return string
257 257
 	 */
258
-	protected function _constructUrl($servlet, $params = array())
258
+	protected function _constructUrl($servlet, $params = array ())
259 259
 	{
260 260
 		if (count($params))
261 261
 		{
262 262
 			//escape all parameters appropriately for inclusion in the query string
263
-			$escapedParams = array();
263
+			$escapedParams = array ();
264 264
 
265 265
 			foreach ($params as $key => $value)
266 266
 			{
267
-				$escapedParams[] = urlencode($key) . '=' . urlencode($value);
267
+				$escapedParams[] = urlencode($key).'='.urlencode($value);
268 268
 			}
269 269
 
270
-			$queryString = $this->_queryDelimiter . implode($this->_queryStringDelimiter, $escapedParams);
270
+			$queryString = $this->_queryDelimiter.implode($this->_queryStringDelimiter, $escapedParams);
271 271
 		}
272 272
 		else
273 273
 		{
274 274
 			$queryString = '';
275 275
 		}
276 276
 
277
-		return 'http://' . $this->_host . ':' . $this->_port . $this->_path . $servlet . $queryString;
277
+		return 'http://'.$this->_host.':'.$this->_port.$this->_path.$servlet.$queryString;
278 278
 	}
279 279
 
280 280
 	/**
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 		$this->_extractUrl = $this->_constructUrl(self::EXTRACT_SERVLET);
287 287
 		$this->_pingUrl = $this->_constructUrl(self::PING_SERVLET);
288 288
 		$this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET);
289
-		$this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array('wt' => self::SOLR_WRITER ));
290
-		$this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array('wt' => self::SOLR_WRITER ));
289
+		$this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array ('wt' => self::SOLR_WRITER));
290
+		$this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array ('wt' => self::SOLR_WRITER));
291 291
 
292 292
 		$this->_urlsInited = true;
293 293
 	}
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 	{
459 459
 		$path = trim($path, '/');
460 460
 
461
-		$this->_path = '/' . $path . '/';
461
+		$this->_path = '/'.$path.'/';
462 462
 
463 463
 		if ($this->_urlsInited)
464 464
 		{
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 		// lazy load a default if one has not be set
477 477
 		if ($this->_httpTransport === false)
478 478
 		{
479
-			require_once(dirname(__FILE__) . '/HttpTransport/FileGetContents.php');
479
+			require_once(dirname(__FILE__).'/HttpTransport/FileGetContents.php');
480 480
 
481 481
 			$this->_httpTransport = new Apache_Solr_HttpTransport_FileGetContents();
482 482
 		}
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 
745 745
 		if ($document->getBoost() !== false)
746 746
 		{
747
-			$xml .= ' boost="' . $document->getBoost() . '"';
747
+			$xml .= ' boost="'.$document->getBoost().'"';
748 748
 		}
749 749
 
750 750
 		$xml .= '>';
@@ -758,11 +758,11 @@  discard block
 block discarded – undo
758 758
 			{
759 759
 				foreach ($value as $multivalue)
760 760
 				{
761
-					$xml .= '<field name="' . $key . '"';
761
+					$xml .= '<field name="'.$key.'"';
762 762
 
763 763
 					if ($fieldBoost !== false)
764 764
 					{
765
-						$xml .= ' boost="' . $fieldBoost . '"';
765
+						$xml .= ' boost="'.$fieldBoost.'"';
766 766
 
767 767
 						// only set the boost for the first field in the set
768 768
 						$fieldBoost = false;
@@ -770,21 +770,21 @@  discard block
 block discarded – undo
770 770
 
771 771
 					$multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
772 772
 
773
-					$xml .= '>' . $multivalue . '</field>';
773
+					$xml .= '>'.$multivalue.'</field>';
774 774
 				}
775 775
 			}
776 776
 			else
777 777
 			{
778
-				$xml .= '<field name="' . $key . '"';
778
+				$xml .= '<field name="'.$key.'"';
779 779
 
780 780
 				if ($fieldBoost !== false)
781 781
 				{
782
-					$xml .= ' boost="' . $fieldBoost . '"';
782
+					$xml .= ' boost="'.$fieldBoost.'"';
783 783
 				}
784 784
 
785 785
 				$value = htmlspecialchars($value, ENT_NOQUOTES, 'UTF-8');
786 786
 
787
-				$xml .= '>' . $value . '</field>';
787
+				$xml .= '>'.$value.'</field>';
788 788
 			}
789 789
 		}
790 790
 
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 		$flushValue = $waitFlush ? 'true' : 'false';
825 825
 		$searcherValue = $waitSearcher ? 'true' : 'false';
826 826
 
827
-		$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
827
+		$rawPost = '<commit expungeDeletes="'.$expungeValue.'" waitFlush="'.$flushValue.'" waitSearcher="'.$searcherValue.'" />';
828 828
 
829 829
 		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
830 830
 	}
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
 		//escape special xml characters
864 864
 		$id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
865 865
 
866
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><id>' . $id . '</id></delete>';
866
+		$rawPost = '<delete fromPending="'.$pendingValue.'" fromCommitted="'.$committedValue.'"><id>'.$id.'</id></delete>';
867 867
 
868 868
 		return $this->delete($rawPost, $timeout);
869 869
 	}
@@ -884,14 +884,14 @@  discard block
 block discarded – undo
884 884
 		$pendingValue = $fromPending ? 'true' : 'false';
885 885
 		$committedValue = $fromCommitted ? 'true' : 'false';
886 886
 
887
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '">';
887
+		$rawPost = '<delete fromPending="'.$pendingValue.'" fromCommitted="'.$committedValue.'">';
888 888
 
889 889
 		foreach ($ids as $id)
890 890
 		{
891 891
 			//escape special xml characters
892 892
 			$id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
893 893
 
894
-			$rawPost .= '<id>' . $id . '</id>';
894
+			$rawPost .= '<id>'.$id.'</id>';
895 895
 		}
896 896
 
897 897
 		$rawPost .= '</delete>';
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
 		// escape special xml characters
919 919
 		$rawQuery = htmlspecialchars($rawQuery, ENT_NOQUOTES, 'UTF-8');
920 920
 
921
-		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '"><query>' . $rawQuery . '</query></delete>';
921
+		$rawPost = '<delete fromPending="'.$pendingValue.'" fromCommitted="'.$committedValue.'"><query>'.$rawQuery.'</query></delete>';
922 922
 
923 923
 		return $this->delete($rawPost, $timeout);
924 924
 	}
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
 	 *
942 942
 	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
943 943
 	 */
944
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
944
+	public function extract($file, $params = array (), $document = null, $mimetype = 'application/octet-stream')
945 945
 	{
946 946
 		// check if $params is an array (allow null for default empty array)
947 947
 		if (!is_null($params))
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
 		}
954 954
 		else
955 955
 		{
956
-			$params = array();
956
+			$params = array ();
957 957
 		}
958 958
 		
959 959
 		// if $file is an http request, defer to extractFromUrl instead
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
 	 *
1003 1003
 	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
1004 1004
 	 */
1005
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1005
+	public function extractFromString($data, $params = array (), $document = null, $mimetype = 'application/octet-stream')
1006 1006
 	{
1007 1007
 		// check if $params is an array (allow null for default empty array)
1008 1008
 		if (!is_null($params))
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
 		}
1015 1015
 		else
1016 1016
 		{
1017
-			$params = array();
1017
+			$params = array ();
1018 1018
 		}
1019 1019
 
1020 1020
 		// make sure we receive our response in JSON and have proper name list treatment
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
 		$queryString = $this->_generateQueryString($params);
1045 1045
 
1046 1046
 		// the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype
1047
-		return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, false, $mimetype);
1047
+		return $this->_sendRawPost($this->_extractUrl.$this->_queryDelimiter.$queryString, $data, false, $mimetype);
1048 1048
 	}
1049 1049
 	
1050 1050
 	/**
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 	 *
1066 1066
 	 * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
1067 1067
 	 */
1068
-	public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1068
+	public function extractFromUrl($url, $params = array (), $document = null, $mimetype = 'application/octet-stream')
1069 1069
 	{
1070 1070
 		// check if $params is an array (allow null for default empty array)
1071 1071
 		if (!is_null($params))
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
 		}
1078 1078
 		else
1079 1079
 		{
1080
-			$params = array();
1080
+			$params = array ();
1081 1081
 		}
1082 1082
 
1083 1083
 		$httpTransport = $this->getHttpTransport();
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
 		$flushValue = $waitFlush ? 'true' : 'false';
1120 1120
 		$searcherValue = $waitSearcher ? 'true' : 'false';
1121 1121
 
1122
-		$rawPost = '<optimize waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';
1122
+		$rawPost = '<optimize waitFlush="'.$flushValue.'" waitSearcher="'.$searcherValue.'" />';
1123 1123
 
1124 1124
 		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
1125 1125
 	}
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1138 1138
 	 * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
1139 1139
 	 */
1140
-	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET)
1140
+	public function search($query, $offset = 0, $limit = 10, $params = array (), $method = self::METHOD_GET)
1141 1141
 	{
1142 1142
 		// ensure params is an array
1143 1143
 		if (!is_null($params))
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 		}
1151 1151
 		else
1152 1152
 		{
1153
-			$params = array();
1153
+			$params = array ();
1154 1154
 		}
1155 1155
 		
1156 1156
 		// construct our full parameters
@@ -1167,7 +1167,7 @@  discard block
 block discarded – undo
1167 1167
 
1168 1168
 		if ($method == self::METHOD_GET)
1169 1169
 		{
1170
-			return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
1170
+			return $this->_sendRawGet($this->_searchUrl.$this->_queryDelimiter.$queryString);
1171 1171
 		}
1172 1172
 		else if ($method == self::METHOD_POST)
1173 1173
 		{
Please login to merge, or discard this patch.
Braces   +99 added lines, -212 removed lines patch added patch discarded remove patch
@@ -83,8 +83,7 @@  discard block
 block discarded – undo
83 83
  * @todo Investigate using other HTTP clients other than file_get_contents built-in handler. Could provide performance
84 84
  * improvements when dealing with multiple requests by using HTTP's keep alive functionality
85 85
  */
86
-class Apache_Solr_Service
87
-{
86
+class Apache_Solr_Service {
88 87
 	/**
89 88
 	 * SVN Revision meta data for this class
90 89
 	 */
@@ -189,8 +188,7 @@  discard block
 block discarded – undo
189 188
 	 * @param string $value
190 189
 	 * @return string
191 190
 	 */
192
-	static public function escape($value)
193
-	{
191
+	static public function escape($value) {
194 192
 		//list taken from http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping%20Special%20Characters
195 193
 		$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\*|\?|:|\\\)/';
196 194
 		$replace = '\\\$1';
@@ -204,8 +202,7 @@  discard block
 block discarded – undo
204 202
 	 * @param string $value
205 203
 	 * @return string
206 204
 	 */
207
-	static public function escapePhrase($value)
208
-	{
205
+	static public function escapePhrase($value) {
209 206
 		$pattern = '/("|\\\)/';
210 207
 		$replace = '\\\$1';
211 208
 
@@ -218,8 +215,7 @@  discard block
 block discarded – undo
218 215
 	 * @param string $value
219 216
 	 * @return string
220 217
 	 */
221
-	static public function phrase($value)
222
-	{
218
+	static public function phrase($value) {
223 219
 		return '"' . self::escapePhrase($value) . '"';
224 220
 	}
225 221
 
@@ -232,16 +228,14 @@  discard block
 block discarded – undo
232 228
 	 * @param string $path
233 229
 	 * @param Apache_Solr_HttpTransport_Interface $httpTransport
234 230
 	 */
235
-	public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = false)
236
-	{
231
+	public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = false) {
237 232
 		$this->setHost($host);
238 233
 		$this->setPort($port);
239 234
 		$this->setPath($path);
240 235
 
241 236
 		$this->_initUrls();
242 237
 
243
-		if ($httpTransport)
244
-		{
238
+		if ($httpTransport) {
245 239
 			$this->setHttpTransport($httpTransport);
246 240
 		}
247 241
 
@@ -255,22 +249,17 @@  discard block
 block discarded – undo
255 249
 	 * @param string $servlet
256 250
 	 * @return string
257 251
 	 */
258
-	protected function _constructUrl($servlet, $params = array())
259
-	{
260
-		if (count($params))
261
-		{
252
+	protected function _constructUrl($servlet, $params = array()) {
253
+		if (count($params)) {
262 254
 			//escape all parameters appropriately for inclusion in the query string
263 255
 			$escapedParams = array();
264 256
 
265
-			foreach ($params as $key => $value)
266
-			{
257
+			foreach ($params as $key => $value) {
267 258
 				$escapedParams[] = urlencode($key) . '=' . urlencode($value);
268 259
 			}
269 260
 
270 261
 			$queryString = $this->_queryDelimiter . implode($this->_queryStringDelimiter, $escapedParams);
271
-		}
272
-		else
273
-		{
262
+		} else {
274 263
 			$queryString = '';
275 264
 		}
276 265
 
@@ -280,8 +269,7 @@  discard block
 block discarded – undo
280 269
 	/**
281 270
 	 * Construct the Full URLs for the three servlets we reference
282 271
 	 */
283
-	protected function _initUrls()
284
-	{
272
+	protected function _initUrls() {
285 273
 		//Initialize our full servlet URLs now that we have server information
286 274
 		$this->_extractUrl = $this->_constructUrl(self::EXTRACT_SERVLET);
287 275
 		$this->_pingUrl = $this->_constructUrl(self::PING_SERVLET);
@@ -292,8 +280,7 @@  discard block
 block discarded – undo
292 280
 		$this->_urlsInited = true;
293 281
 	}
294 282
 
295
-	protected function _generateQueryString($params)
296
-	{
283
+	protected function _generateQueryString($params) {
297 284
 		// use http_build_query to encode our arguments because its faster
298 285
 		// than urlencoding all the parts ourselves in a loop
299 286
 		//
@@ -305,13 +292,10 @@  discard block
 block discarded – undo
305 292
 		// NOTE: before php 5.1.3 brackets were not url encoded by http_build query - we've checked
306 293
 		// the php version in the constructor and put the results in the instance variable. Also, before
307 294
 		// 5.1.2 the arg_separator parameter was not available, so don't use it
308
-		if ($this->_queryBracketsEscaped)
309
-		{
295
+		if ($this->_queryBracketsEscaped) {
310 296
 			$queryString = http_build_query($params, null, $this->_queryStringDelimiter);
311 297
 			return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
312
-		}
313
-		else
314
-		{
298
+		} else {
315 299
 			$queryString = http_build_query($params);
316 300
 			return preg_replace('/\\[(?:[0-9]|[1-9][0-9]+)\\]=/', '=', $queryString);
317 301
 		}
@@ -326,15 +310,13 @@  discard block
 block discarded – undo
326 310
 	 *
327 311
 	 * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
328 312
 	 */
329
-	protected function _sendRawGet($url, $timeout = FALSE)
330
-	{
313
+	protected function _sendRawGet($url, $timeout = FALSE) {
331 314
 		$httpTransport = $this->getHttpTransport();
332 315
 
333 316
 		$httpResponse = $httpTransport->performGetRequest($url, $timeout);
334 317
 		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
335 318
 
336
-		if ($solrResponse->getHttpStatus() != 200)
337
-		{
319
+		if ($solrResponse->getHttpStatus() != 200) {
338 320
 			throw new Apache_Solr_HttpTransportException($solrResponse);
339 321
 		}
340 322
 
@@ -352,15 +334,13 @@  discard block
 block discarded – undo
352 334
 	 *
353 335
 	 * @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
354 336
 	 */
355
-	protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8')
356
-	{
337
+	protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') {
357 338
 		$httpTransport = $this->getHttpTransport();
358 339
 
359 340
 		$httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout);
360 341
 		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
361 342
 
362
-		if ($solrResponse->getHttpStatus() != 200)
363
-		{
343
+		if ($solrResponse->getHttpStatus() != 200) {
364 344
 			throw new Apache_Solr_HttpTransportException($solrResponse);
365 345
 		}
366 346
 
@@ -372,8 +352,7 @@  discard block
 block discarded – undo
372 352
 	 *
373 353
 	 * @return string
374 354
 	 */
375
-	public function getHost()
376
-	{
355
+	public function getHost() {
377 356
 		return $this->_host;
378 357
 	}
379 358
 
@@ -384,20 +363,15 @@  discard block
 block discarded – undo
384 363
 	 *
385 364
 	 * @throws Apache_Solr_InvalidArgumentException If the host parameter is empty
386 365
 	 */
387
-	public function setHost($host)
388
-	{
366
+	public function setHost($host) {
389 367
 		//Use the provided host or use the default
390
-		if (empty($host))
391
-		{
368
+		if (empty($host)) {
392 369
 			throw new Apache_Solr_InvalidArgumentException('Host parameter is empty');
393
-		}
394
-		else
395
-		{
370
+		} else {
396 371
 			$this->_host = $host;
397 372
 		}
398 373
 
399
-		if ($this->_urlsInited)
400
-		{
374
+		if ($this->_urlsInited) {
401 375
 			$this->_initUrls();
402 376
 		}
403 377
 	}
@@ -407,8 +381,7 @@  discard block
 block discarded – undo
407 381
 	 *
408 382
 	 * @return integer
409 383
 	 */
410
-	public function getPort()
411
-	{
384
+	public function getPort() {
412 385
 		return $this->_port;
413 386
 	}
414 387
 
@@ -419,22 +392,17 @@  discard block
 block discarded – undo
419 392
 	 *
420 393
 	 * @throws Apache_Solr_InvalidArgumentException If the port parameter is empty
421 394
 	 */
422
-	public function setPort($port)
423
-	{
395
+	public function setPort($port) {
424 396
 		//Use the provided port or use the default
425 397
 		$port = (int) $port;
426 398
 
427
-		if ($port <= 0)
428
-		{
399
+		if ($port <= 0) {
429 400
 			throw new Apache_Solr_InvalidArgumentException('Port is not a valid port number');
430
-		}
431
-		else
432
-		{
401
+		} else {
433 402
 			$this->_port = $port;
434 403
 		}
435 404
 
436
-		if ($this->_urlsInited)
437
-		{
405
+		if ($this->_urlsInited) {
438 406
 			$this->_initUrls();
439 407
 		}
440 408
 	}
@@ -444,8 +412,7 @@  discard block
 block discarded – undo
444 412
 	 *
445 413
 	 * @return string
446 414
 	 */
447
-	public function getPath()
448
-	{
415
+	public function getPath() {
449 416
 		return $this->_path;
450 417
 	}
451 418
 
@@ -454,14 +421,12 @@  discard block
 block discarded – undo
454 421
 	 *
455 422
 	 * @param string $path
456 423
 	 */
457
-	public function setPath($path)
458
-	{
424
+	public function setPath($path) {
459 425
 		$path = trim($path, '/');
460 426
 
461 427
 		$this->_path = '/' . $path . '/';
462 428
 
463
-		if ($this->_urlsInited)
464
-		{
429
+		if ($this->_urlsInited) {
465 430
 			$this->_initUrls();
466 431
 		}
467 432
 	}
@@ -471,11 +436,9 @@  discard block
 block discarded – undo
471 436
 	 *
472 437
 	 * @return HttpTransportInterface
473 438
 	 */
474
-	public function getHttpTransport()
475
-	{
439
+	public function getHttpTransport() {
476 440
 		// lazy load a default if one has not be set
477
-		if ($this->_httpTransport === false)
478
-		{
441
+		if ($this->_httpTransport === false) {
479 442
 			require_once(dirname(__FILE__) . '/HttpTransport/FileGetContents.php');
480 443
 
481 444
 			$this->_httpTransport = new Apache_Solr_HttpTransport_FileGetContents();
@@ -489,8 +452,7 @@  discard block
 block discarded – undo
489 452
 	 *
490 453
 	 * @param Apache_Solr_HttpTransport_Interface
491 454
 	 */
492
-	public function setHttpTransport(Apache_Solr_HttpTransport_Interface $httpTransport)
493
-	{
455
+	public function setHttpTransport(Apache_Solr_HttpTransport_Interface $httpTransport) {
494 456
 		$this->_httpTransport = $httpTransport;
495 457
 	}
496 458
 
@@ -500,8 +462,7 @@  discard block
 block discarded – undo
500 462
 	 *
501 463
 	 * @param boolean $createDocuments
502 464
 	 */
503
-	public function setCreateDocuments($createDocuments)
504
-	{
465
+	public function setCreateDocuments($createDocuments) {
505 466
 		$this->_createDocuments = (bool) $createDocuments;
506 467
 	}
507 468
 
@@ -510,8 +471,7 @@  discard block
 block discarded – undo
510 471
 	 *
511 472
 	 * @return boolean
512 473
 	 */
513
-	public function getCreateDocuments()
514
-	{
474
+	public function getCreateDocuments() {
515 475
 		return $this->_createDocuments;
516 476
 	}
517 477
 
@@ -520,8 +480,7 @@  discard block
 block discarded – undo
520 480
 	 *
521 481
 	 * @param boolean $collapseSingleValueArrays
522 482
 	 */
523
-	public function setCollapseSingleValueArrays($collapseSingleValueArrays)
524
-	{
483
+	public function setCollapseSingleValueArrays($collapseSingleValueArrays) {
525 484
 		$this->_collapseSingleValueArrays = (bool) $collapseSingleValueArrays;
526 485
 	}
527 486
 
@@ -530,8 +489,7 @@  discard block
 block discarded – undo
530 489
 	 *
531 490
 	 * @return boolean
532 491
 	 */
533
-	public function getCollapseSingleValueArrays()
534
-	{
492
+	public function getCollapseSingleValueArrays() {
535 493
 		return $this->_collapseSingleValueArrays;
536 494
 	}
537 495
 
@@ -543,8 +501,7 @@  discard block
 block discarded – undo
543 501
 	 *
544 502
 	 * @deprecated Use the getDefaultTimeout method on the HTTP transport implementation
545 503
 	 */
546
-	public function getDefaultTimeout()
547
-	{
504
+	public function getDefaultTimeout() {
548 505
 		return $this->getHttpTransport()->getDefaultTimeout();
549 506
 	}
550 507
 
@@ -555,8 +512,7 @@  discard block
 block discarded – undo
555 512
 	 *
556 513
 	 * @deprecated Use the setDefaultTimeout method on the HTTP transport implementation
557 514
 	 */
558
-	public function setDefaultTimeout($timeout)
559
-	{
515
+	public function setDefaultTimeout($timeout) {
560 516
 		$this->getHttpTransport()->setDefaultTimeout($timeout);
561 517
 	}
562 518
 
@@ -567,10 +523,8 @@  discard block
 block discarded – undo
567 523
 	 * @param string $namedListTreatment
568 524
 	 * @throws Apache_Solr_InvalidArgumentException If invalid option is set
569 525
 	 */
570
-	public function setNamedListTreatment($namedListTreatment)
571
-	{
572
-		switch ((string) $namedListTreatment)
573
-		{
526
+	public function setNamedListTreatment($namedListTreatment) {
527
+		switch ((string) $namedListTreatment) {
574 528
 			case Apache_Solr_Service::NAMED_LIST_FLAT:
575 529
 				$this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT;
576 530
 				break;
@@ -589,8 +543,7 @@  discard block
 block discarded – undo
589 543
 	 *
590 544
 	 * @return string
591 545
 	 */
592
-	public function getNamedListTreatment()
593
-	{
546
+	public function getNamedListTreatment() {
594 547
 		return $this->_namedListTreatment;
595 548
 	}
596 549
 
@@ -600,8 +553,7 @@  discard block
 block discarded – undo
600 553
 	 *
601 554
 	 * @param string $queryDelimiter
602 555
 	 */
603
-	public function setQueryDelimiter($queryDelimiter)
604
-	{
556
+	public function setQueryDelimiter($queryDelimiter) {
605 557
 		$this->_queryDelimiter = $queryDelimiter;
606 558
 	}
607 559
 
@@ -611,8 +563,7 @@  discard block
 block discarded – undo
611 563
 	 *
612 564
 	 * @param string $queryStringDelimiter
613 565
 	 */
614
-	public function setQueryStringDelimiter($queryStringDelimiter)
615
-	{
566
+	public function setQueryStringDelimiter($queryStringDelimiter) {
616 567
 		$this->_queryStringDelimiter = $queryStringDelimiter;
617 568
 	}
618 569
 
@@ -623,8 +574,7 @@  discard block
 block discarded – undo
623 574
 	 * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2)
624 575
 	 * @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
625 576
 	 */
626
-	public function ping($timeout = 2)
627
-	{
577
+	public function ping($timeout = 2) {
628 578
 		$start = microtime(true);
629 579
 		
630 580
 		$httpTransport = $this->getHttpTransport();
@@ -632,12 +582,9 @@  discard block
 block discarded – undo
632 582
 		$httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout);
633 583
 		$solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays);
634 584
 
635
-		if ($solrResponse->getHttpStatus() == 200)
636
-		{
585
+		if ($solrResponse->getHttpStatus() == 200) {
637 586
 			return microtime(true) - $start;
638
-		}
639
-		else
640
-		{
587
+		} else {
641 588
 			return false;
642 589
 		}
643 590
 	}
@@ -650,8 +597,7 @@  discard block
 block discarded – undo
650 597
 	 *
651 598
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
652 599
 	 */
653
-	public function threads()
654
-	{
600
+	public function threads() {
655 601
 		return $this->_sendRawGet($this->_threadsUrl);
656 602
 	}
657 603
 
@@ -664,8 +610,7 @@  discard block
 block discarded – undo
664 610
 	 *
665 611
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
666 612
 	 */
667
-	public function add($rawPost)
668
-	{
613
+	public function add($rawPost) {
669 614
 		return $this->_sendRawPost($this->_updateUrl, $rawPost);
670 615
 	}
671 616
 
@@ -681,8 +626,7 @@  discard block
 block discarded – undo
681 626
 	 *
682 627
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
683 628
 	 */
684
-	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
685
-	{
629
+	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0) {
686 630
 		$dupValue = $allowDups ? 'true' : 'false';
687 631
 		$pendingValue = $overwritePending ? 'true' : 'false';
688 632
 		$committedValue = $overwriteCommitted ? 'true' : 'false';
@@ -709,8 +653,7 @@  discard block
 block discarded – undo
709 653
 	 *
710 654
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
711 655
 	 */
712
-	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
713
-	{
656
+	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0) {
714 657
 		$dupValue = $allowDups ? 'true' : 'false';
715 658
 		$pendingValue = $overwritePending ? 'true' : 'false';
716 659
 		$committedValue = $overwriteCommitted ? 'true' : 'false';
@@ -720,10 +663,8 @@  discard block
 block discarded – undo
720 663
 
721 664
 		$rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
722 665
 
723
-		foreach ($documents as $document)
724
-		{
725
-			if ($document instanceof Apache_Solr_Document)
726
-			{
666
+		foreach ($documents as $document) {
667
+			if ($document instanceof Apache_Solr_Document) {
727 668
 				$rawPost .= $this->_documentToXmlFragment($document);
728 669
 			}
729 670
 		}
@@ -738,30 +679,24 @@  discard block
 block discarded – undo
738 679
 	 *
739 680
 	 * @return string
740 681
 	 */
741
-	protected function _documentToXmlFragment(Apache_Solr_Document $document)
742
-	{
682
+	protected function _documentToXmlFragment(Apache_Solr_Document $document) {
743 683
 		$xml = '<doc';
744 684
 
745
-		if ($document->getBoost() !== false)
746
-		{
685
+		if ($document->getBoost() !== false) {
747 686
 			$xml .= ' boost="' . $document->getBoost() . '"';
748 687
 		}
749 688
 
750 689
 		$xml .= '>';
751 690
 
752
-		foreach ($document as $key => $value)
753
-		{
691
+		foreach ($document as $key => $value) {
754 692
 			$key = htmlspecialchars($key, ENT_QUOTES, 'UTF-8');
755 693
 			$fieldBoost = $document->getFieldBoost($key);
756 694
 
757
-			if (is_array($value))
758
-			{
759
-				foreach ($value as $multivalue)
760
-				{
695
+			if (is_array($value)) {
696
+				foreach ($value as $multivalue) {
761 697
 					$xml .= '<field name="' . $key . '"';
762 698
 
763
-					if ($fieldBoost !== false)
764
-					{
699
+					if ($fieldBoost !== false) {
765 700
 						$xml .= ' boost="' . $fieldBoost . '"';
766 701
 
767 702
 						// only set the boost for the first field in the set
@@ -772,13 +707,10 @@  discard block
 block discarded – undo
772 707
 
773 708
 					$xml .= '>' . $multivalue . '</field>';
774 709
 				}
775
-			}
776
-			else
777
-			{
710
+			} else {
778 711
 				$xml .= '<field name="' . $key . '"';
779 712
 
780
-				if ($fieldBoost !== false)
781
-				{
713
+				if ($fieldBoost !== false) {
782 714
 					$xml .= ' boost="' . $fieldBoost . '"';
783 715
 				}
784 716
 
@@ -800,8 +732,7 @@  discard block
 block discarded – undo
800 732
 	 * @param string $string
801 733
 	 * @return string
802 734
 	 */
803
-	protected function _stripCtrlChars($string)
804
-	{
735
+	protected function _stripCtrlChars($string) {
805 736
 		// See:  http://w3.org/International/questions/qa-forms-utf-8.html
806 737
 		// Printable utf-8 does not include any of these chars below x7F
807 738
 		return preg_replace('@[\x00-\x08\x0B\x0C\x0E-\x1F]@', ' ', $string);
@@ -818,8 +749,7 @@  discard block
 block discarded – undo
818 749
 	 *
819 750
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
820 751
 	 */
821
-	public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
822
-	{
752
+	public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600) {
823 753
 		$expungeValue = $expungeDeletes ? 'true' : 'false';
824 754
 		$flushValue = $waitFlush ? 'true' : 'false';
825 755
 		$searcherValue = $waitSearcher ? 'true' : 'false';
@@ -839,8 +769,7 @@  discard block
 block discarded – undo
839 769
 	 *
840 770
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
841 771
 	 */
842
-	public function delete($rawPost, $timeout = 3600)
843
-	{
772
+	public function delete($rawPost, $timeout = 3600) {
844 773
 		return $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout);
845 774
 	}
846 775
 
@@ -855,8 +784,7 @@  discard block
 block discarded – undo
855 784
 	 *
856 785
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
857 786
 	 */
858
-	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
859
-	{
787
+	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600) {
860 788
 		$pendingValue = $fromPending ? 'true' : 'false';
861 789
 		$committedValue = $fromCommitted ? 'true' : 'false';
862 790
 
@@ -879,15 +807,13 @@  discard block
 block discarded – undo
879 807
 	 *
880 808
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
881 809
 	 */
882
-	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
883
-	{
810
+	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600) {
884 811
 		$pendingValue = $fromPending ? 'true' : 'false';
885 812
 		$committedValue = $fromCommitted ? 'true' : 'false';
886 813
 
887 814
 		$rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '">';
888 815
 
889
-		foreach ($ids as $id)
890
-		{
816
+		foreach ($ids as $id) {
891 817
 			//escape special xml characters
892 818
 			$id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8');
893 819
 
@@ -910,8 +836,7 @@  discard block
 block discarded – undo
910 836
 	 *
911 837
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
912 838
 	 */
913
-	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
914
-	{
839
+	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600) {
915 840
 		$pendingValue = $fromPending ? 'true' : 'false';
916 841
 		$committedValue = $fromCommitted ? 'true' : 'false';
917 842
 
@@ -941,43 +866,33 @@  discard block
 block discarded – undo
941 866
 	 *
942 867
 	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
943 868
 	 */
944
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
945
-	{
869
+	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream') {
946 870
 		// check if $params is an array (allow null for default empty array)
947
-		if (!is_null($params))
948
-		{
949
-			if (!is_array($params))
950
-			{
871
+		if (!is_null($params)) {
872
+			if (!is_array($params)) {
951 873
 				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
952 874
 			}
953
-		}
954
-		else
955
-		{
875
+		} else {
956 876
 			$params = array();
957 877
 		}
958 878
 		
959 879
 		// if $file is an http request, defer to extractFromUrl instead
960
-		if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://')
961
-		{
880
+		if (substr($file, 0, 7) == 'http://' || substr($file, 0, 8) == 'https://') {
962 881
 			return $this->extractFromUrl($file, $params, $document, $mimetype);
963 882
 		}
964 883
 		
965 884
 		// read the contents of the file
966 885
 		$contents = @file_get_contents($file);
967 886
 
968
-		if ($contents !== false)
969
-		{
887
+		if ($contents !== false) {
970 888
 			// add the resource.name parameter if not specified
971
-			if (!isset($params['resource.name']))
972
-			{
889
+			if (!isset($params['resource.name'])) {
973 890
 				$params['resource.name'] = basename($file);
974 891
 			}
975 892
 
976 893
 			// delegate the rest to extractFromString
977 894
 			return $this->extractFromString($contents, $params, $document, $mimetype);
978
-		}
979
-		else
980
-		{
895
+		} else {
981 896
 			throw new Apache_Solr_InvalidArgumentException("File '{$file}' is empty or could not be read");
982 897
 		}
983 898
 	}
@@ -1002,18 +917,13 @@  discard block
 block discarded – undo
1002 917
 	 *
1003 918
 	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
1004 919
 	 */
1005
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1006
-	{
920
+	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream') {
1007 921
 		// check if $params is an array (allow null for default empty array)
1008
-		if (!is_null($params))
1009
-		{
1010
-			if (!is_array($params))
1011
-			{
922
+		if (!is_null($params)) {
923
+			if (!is_array($params)) {
1012 924
 				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1013 925
 			}
1014
-		}
1015
-		else
1016
-		{
926
+		} else {
1017 927
 			$params = array();
1018 928
 		}
1019 929
 
@@ -1022,16 +932,13 @@  discard block
 block discarded – undo
1022 932
 		$params['json.nl'] = $this->_namedListTreatment;
1023 933
 
1024 934
 		// check if $document is an Apache_Solr_Document instance
1025
-		if (!is_null($document) && $document instanceof Apache_Solr_Document)
1026
-		{
935
+		if (!is_null($document) && $document instanceof Apache_Solr_Document) {
1027 936
 			// iterate document, adding literal.* and boost.* fields to $params as appropriate
1028
-			foreach ($document as $field => $fieldValue)
1029
-			{
937
+			foreach ($document as $field => $fieldValue) {
1030 938
 				// check if we need to add a boost.* parameters
1031 939
 				$fieldBoost = $document->getFieldBoost($field);
1032 940
 
1033
-				if ($fieldBoost !== false)
1034
-				{
941
+				if ($fieldBoost !== false) {
1035 942
 					$params["boost.{$field}"] = $fieldBoost;
1036 943
 				}
1037 944
 
@@ -1065,18 +972,13 @@  discard block
 block discarded – undo
1065 972
 	 *
1066 973
 	 * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
1067 974
 	 */
1068
-	public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1069
-	{
975
+	public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream') {
1070 976
 		// check if $params is an array (allow null for default empty array)
1071
-		if (!is_null($params))
1072
-		{
1073
-			if (!is_array($params))
1074
-			{
977
+		if (!is_null($params)) {
978
+			if (!is_array($params)) {
1075 979
 				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1076 980
 			}
1077
-		}
1078
-		else
1079
-		{
981
+		} else {
1080 982
 			$params = array();
1081 983
 		}
1082 984
 
@@ -1086,19 +988,15 @@  discard block
 block discarded – undo
1086 988
 		$httpResponse = $httpTransport->performGetRequest($url);
1087 989
 		
1088 990
 		// check that its a 200 response
1089
-		if ($httpResponse->getStatusCode() == 200)
1090
-		{
991
+		if ($httpResponse->getStatusCode() == 200) {
1091 992
 			// add the resource.name parameter if not specified
1092
-			if (!isset($params['resource.name']))
1093
-			{
993
+			if (!isset($params['resource.name'])) {
1094 994
 				$params['resource.name'] = $url;
1095 995
 			}
1096 996
 
1097 997
 			// delegate the rest to extractFromString
1098 998
 			return $this->extractFromString($httpResponse->getBody(), $params, $document, $mimetype);
1099
-		}
1100
-		else
1101
-		{
999
+		} else {
1102 1000
 			throw new Apache_Solr_InvalidArgumentException("URL '{$url}' returned non 200 response code");
1103 1001
 		}
1104 1002
 	}
@@ -1114,8 +1012,7 @@  discard block
 block discarded – undo
1114 1012
 	 *
1115 1013
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1116 1014
 	 */
1117
-	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
1118
-	{
1015
+	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600) {
1119 1016
 		$flushValue = $waitFlush ? 'true' : 'false';
1120 1017
 		$searcherValue = $waitSearcher ? 'true' : 'false';
1121 1018
 
@@ -1137,19 +1034,14 @@  discard block
 block discarded – undo
1137 1034
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1138 1035
 	 * @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used
1139 1036
 	 */
1140
-	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET)
1141
-	{
1037
+	public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET) {
1142 1038
 		// ensure params is an array
1143
-		if (!is_null($params))
1144
-		{
1145
-			if (!is_array($params))
1146
-			{
1039
+		if (!is_null($params)) {
1040
+			if (!is_array($params)) {
1147 1041
 				// params was specified but was not an array - invalid
1148 1042
 				throw new Apache_Solr_InvalidArgumentException("\$params must be a valid array or null");
1149 1043
 			}
1150
-		}
1151
-		else
1152
-		{
1044
+		} else {
1153 1045
 			$params = array();
1154 1046
 		}
1155 1047
 		
@@ -1165,16 +1057,11 @@  discard block
 block discarded – undo
1165 1057
 
1166 1058
 		$queryString = $this->_generateQueryString($params);
1167 1059
 
1168
-		if ($method == self::METHOD_GET)
1169
-		{
1060
+		if ($method == self::METHOD_GET) {
1170 1061
 			return $this->_sendRawGet($this->_searchUrl . $this->_queryDelimiter . $queryString);
1171
-		}
1172
-		else if ($method == self::METHOD_POST)
1173
-		{
1062
+		} else if ($method == self::METHOD_POST) {
1174 1063
 			return $this->_sendRawPost($this->_searchUrl, $queryString, FALSE, 'application/x-www-form-urlencoded; charset=UTF-8');
1175
-		}
1176
-		else
1177
-		{
1064
+		} else {
1178 1065
 			throw new Apache_Solr_InvalidArgumentException("Unsupported method '$method', please use the Apache_Solr_Service::METHOD_* constants");
1179 1066
 		}
1180 1067
 	}
Please login to merge, or discard this patch.
Upper-Lower-Casing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @var boolean
136 136
 	 */
137
-	protected $_createDocuments = true;
137
+	protected $_createDocuments = TRUE;
138 138
 
139 139
 	/**
140 140
 	 * Whether {@link Apache_Solr_Response} objects should have multivalue fields with only a single value
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 *
143 143
 	 * @var boolean
144 144
 	 */
145
-	protected $_collapseSingleValueArrays = true;
145
+	protected $_collapseSingleValueArrays = TRUE;
146 146
 
147 147
 	/**
148 148
 	 * How NamedLists should be formatted in the output.  This specifically effects facet counts. Valid values
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @var string
160 160
 	 */
161
-	protected $_queryDelimiter = '?', $_queryStringDelimiter = '&', $_queryBracketsEscaped = true;
161
+	protected $_queryDelimiter = '?', $_queryStringDelimiter = '&', $_queryBracketsEscaped = TRUE;
162 162
 
163 163
 	/**
164 164
 	 * Constructed servlet full path URLs
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	 *
173 173
 	 * @var boolean
174 174
 	 */
175
-	protected $_urlsInited = false;
175
+	protected $_urlsInited = FALSE;
176 176
 
177 177
 	/**
178 178
 	 * HTTP Transport implementation (pluggable)
179 179
 	 *
180 180
 	 * @var Apache_Solr_HttpTransport_Interface
181 181
 	 */
182
-	protected $_httpTransport = false;
182
+	protected $_httpTransport = FALSE;
183 183
 
184 184
 	/**
185 185
 	 * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 * @param string $path
233 233
 	 * @param Apache_Solr_HttpTransport_Interface $httpTransport
234 234
 	 */
235
-	public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = false)
235
+	public function __construct($host = 'localhost', $port = 8180, $path = '/solr/', $httpTransport = FALSE)
236 236
 	{
237 237
 		$this->setHost($host);
238 238
 		$this->setPort($port);
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 		$this->_threadsUrl = $this->_constructUrl(self::THREADS_SERVLET, array('wt' => self::SOLR_WRITER ));
290 290
 		$this->_updateUrl = $this->_constructUrl(self::UPDATE_SERVLET, array('wt' => self::SOLR_WRITER ));
291 291
 
292
-		$this->_urlsInited = true;
292
+		$this->_urlsInited = TRUE;
293 293
 	}
294 294
 
295 295
 	protected function _generateQueryString($params)
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 		// 5.1.2 the arg_separator parameter was not available, so don't use it
308 308
 		if ($this->_queryBracketsEscaped)
309 309
 		{
310
-			$queryString = http_build_query($params, null, $this->_queryStringDelimiter);
310
+			$queryString = http_build_query($params, NULL, $this->_queryStringDelimiter);
311 311
 			return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString);
312 312
 		}
313 313
 		else
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 	public function getHttpTransport()
475 475
 	{
476 476
 		// lazy load a default if one has not be set
477
-		if ($this->_httpTransport === false)
477
+		if ($this->_httpTransport === FALSE)
478 478
 		{
479 479
 			require_once(dirname(__FILE__) . '/HttpTransport/FileGetContents.php');
480 480
 
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 	 */
626 626
 	public function ping($timeout = 2)
627 627
 	{
628
-		$start = microtime(true);
628
+		$start = microtime(TRUE);
629 629
 		
630 630
 		$httpTransport = $this->getHttpTransport();
631 631
 
@@ -634,11 +634,11 @@  discard block
 block discarded – undo
634 634
 
635 635
 		if ($solrResponse->getHttpStatus() == 200)
636 636
 		{
637
-			return microtime(true) - $start;
637
+			return microtime(TRUE) - $start;
638 638
 		}
639 639
 		else
640 640
 		{
641
-			return false;
641
+			return FALSE;
642 642
 		}
643 643
 	}
644 644
 
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 	 *
682 682
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
683 683
 	 */
684
-	public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
684
+	public function addDocument(Apache_Solr_Document $document, $allowDups = FALSE, $overwritePending = TRUE, $overwriteCommitted = TRUE, $commitWithin = 0)
685 685
 	{
686 686
 		$dupValue = $allowDups ? 'true' : 'false';
687 687
 		$pendingValue = $overwritePending ? 'true' : 'false';
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	 *
710 710
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
711 711
 	 */
712
-	public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
712
+	public function addDocuments($documents, $allowDups = FALSE, $overwritePending = TRUE, $overwriteCommitted = TRUE, $commitWithin = 0)
713 713
 	{
714 714
 		$dupValue = $allowDups ? 'true' : 'false';
715 715
 		$pendingValue = $overwritePending ? 'true' : 'false';
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 	{
743 743
 		$xml = '<doc';
744 744
 
745
-		if ($document->getBoost() !== false)
745
+		if ($document->getBoost() !== FALSE)
746 746
 		{
747 747
 			$xml .= ' boost="' . $document->getBoost() . '"';
748 748
 		}
@@ -760,12 +760,12 @@  discard block
 block discarded – undo
760 760
 				{
761 761
 					$xml .= '<field name="' . $key . '"';
762 762
 
763
-					if ($fieldBoost !== false)
763
+					if ($fieldBoost !== FALSE)
764 764
 					{
765 765
 						$xml .= ' boost="' . $fieldBoost . '"';
766 766
 
767 767
 						// only set the boost for the first field in the set
768
-						$fieldBoost = false;
768
+						$fieldBoost = FALSE;
769 769
 					}
770 770
 
771 771
 					$multivalue = htmlspecialchars($multivalue, ENT_NOQUOTES, 'UTF-8');
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 			{
778 778
 				$xml .= '<field name="' . $key . '"';
779 779
 
780
-				if ($fieldBoost !== false)
780
+				if ($fieldBoost !== FALSE)
781 781
 				{
782 782
 					$xml .= ' boost="' . $fieldBoost . '"';
783 783
 				}
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 	 *
819 819
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
820 820
 	 */
821
-	public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600)
821
+	public function commit($expungeDeletes = FALSE, $waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600)
822 822
 	{
823 823
 		$expungeValue = $expungeDeletes ? 'true' : 'false';
824 824
 		$flushValue = $waitFlush ? 'true' : 'false';
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
 	 *
856 856
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
857 857
 	 */
858
-	public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600)
858
+	public function deleteById($id, $fromPending = TRUE, $fromCommitted = TRUE, $timeout = 3600)
859 859
 	{
860 860
 		$pendingValue = $fromPending ? 'true' : 'false';
861 861
 		$committedValue = $fromCommitted ? 'true' : 'false';
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 	 *
880 880
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
881 881
 	 */
882
-	public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600)
882
+	public function deleteByMultipleIds($ids, $fromPending = TRUE, $fromCommitted = TRUE, $timeout = 3600)
883 883
 	{
884 884
 		$pendingValue = $fromPending ? 'true' : 'false';
885 885
 		$committedValue = $fromCommitted ? 'true' : 'false';
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
 	 *
911 911
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
912 912
 	 */
913
-	public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600)
913
+	public function deleteByQuery($rawQuery, $fromPending = TRUE, $fromCommitted = TRUE, $timeout = 3600)
914 914
 	{
915 915
 		$pendingValue = $fromPending ? 'true' : 'false';
916 916
 		$committedValue = $fromCommitted ? 'true' : 'false';
@@ -941,7 +941,7 @@  discard block
 block discarded – undo
941 941
 	 *
942 942
 	 * @throws Apache_Solr_InvalidArgumentException if $file, $params, or $document are invalid.
943 943
 	 */
944
-	public function extract($file, $params = array(), $document = null, $mimetype = 'application/octet-stream')
944
+	public function extract($file, $params = array(), $document = NULL, $mimetype = 'application/octet-stream')
945 945
 	{
946 946
 		// check if $params is an array (allow null for default empty array)
947 947
 		if (!is_null($params))
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 		// read the contents of the file
966 966
 		$contents = @file_get_contents($file);
967 967
 
968
-		if ($contents !== false)
968
+		if ($contents !== FALSE)
969 969
 		{
970 970
 			// add the resource.name parameter if not specified
971 971
 			if (!isset($params['resource.name']))
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
 	 *
1003 1003
 	 * @todo Should be using multipart/form-data to post parameter values, but I could not get my implementation to work. Needs revisisted.
1004 1004
 	 */
1005
-	public function extractFromString($data, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1005
+	public function extractFromString($data, $params = array(), $document = NULL, $mimetype = 'application/octet-stream')
1006 1006
 	{
1007 1007
 		// check if $params is an array (allow null for default empty array)
1008 1008
 		if (!is_null($params))
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
 				// check if we need to add a boost.* parameters
1031 1031
 				$fieldBoost = $document->getFieldBoost($field);
1032 1032
 
1033
-				if ($fieldBoost !== false)
1033
+				if ($fieldBoost !== FALSE)
1034 1034
 				{
1035 1035
 					$params["boost.{$field}"] = $fieldBoost;
1036 1036
 				}
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
 		$queryString = $this->_generateQueryString($params);
1045 1045
 
1046 1046
 		// the file contents will be sent to SOLR as the POST BODY - we use application/octect-stream as default mimetype
1047
-		return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, false, $mimetype);
1047
+		return $this->_sendRawPost($this->_extractUrl . $this->_queryDelimiter . $queryString, $data, FALSE, $mimetype);
1048 1048
 	}
1049 1049
 	
1050 1050
 	/**
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
 	 *
1066 1066
 	 * @throws Apache_Solr_InvalidArgumentException if $url, $params, or $document are invalid.
1067 1067
 	 */
1068
-	public function extractFromUrl($url, $params = array(), $document = null, $mimetype = 'application/octet-stream')
1068
+	public function extractFromUrl($url, $params = array(), $document = NULL, $mimetype = 'application/octet-stream')
1069 1069
 	{
1070 1070
 		// check if $params is an array (allow null for default empty array)
1071 1071
 		if (!is_null($params))
@@ -1114,7 +1114,7 @@  discard block
 block discarded – undo
1114 1114
 	 *
1115 1115
 	 * @throws Apache_Solr_HttpTransportException If an error occurs during the service call
1116 1116
 	 */
1117
-	public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600)
1117
+	public function optimize($waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600)
1118 1118
 	{
1119 1119
 		$flushValue = $waitFlush ? 'true' : 'false';
1120 1120
 		$searcherValue = $waitSearcher ? 'true' : 'false';
Please login to merge, or discard this patch.